org.eclipse.xtext.xbase.jvmmodel
Class JvmTypesBuilder

java.lang.Object
  extended by org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder

public class JvmTypesBuilder
extends java.lang.Object

A set of factory and builder functions, used to create an instance of the Jvm model (TypesPackage).

Author:
Sven Efftinge - Initial contribution and API

Constructor Summary
JvmTypesBuilder()
           
 
Method Summary
 JvmTypeReference addArrayTypeDimension(JvmTypeReference componentType)
           
protected  void addCompilationStrategy(JvmMember member, Functions.Function1<ImportManager,? extends java.lang.CharSequence> strategy)
           
<T extends JvmIdentifiableElement>
T
associate(org.eclipse.emf.ecore.EObject sourceElement, T target)
          Associates a source element with a target element.
 JvmTypeReference cloneWithProxies(JvmTypeReference typeRef)
          Creates a clone of the given JvmTypeReference without resolving any proxies.
protected  JvmGenericType createJvmGenericType(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name)
           
 java.lang.String getDocumentation(org.eclipse.emf.ecore.EObject source)
           
protected  JvmAnnotationReference getJvmAnnotationReference(XAnnotation anno)
           
protected  JvmAnnotationValue getJvmAnnotationValue(XExpression value)
           
 void initialization(JvmField field, Functions.Function1<ImportManager,? extends java.lang.CharSequence> strategy)
          Attaches the given compile strategy to the given JvmField such that the compiler knows how to initialize the JvmField when it is translated to Java source code.
 JvmTypeReference newTypeRef(org.eclipse.emf.ecore.EObject ctx, java.lang.Class<?> clazz, JvmTypeReference... typeArgs)
          Creates a new JvmTypeReference pointing to the given class and containing the given type arguments.
 JvmTypeReference newTypeRef(org.eclipse.emf.ecore.EObject ctx, java.lang.String typeName, JvmTypeReference... typeArgs)
          Creates a new JvmTypeReference pointing to the given class and containing the given type arguments.
protected  java.lang.String nullSaveName(java.lang.String name)
           
 void setBody(JvmExecutable executable, Functions.Function1<ImportManager,? extends java.lang.CharSequence> strategy)
          Attaches the given compile strategy to the given JvmExecutable such that the compiler knows how to implement the JvmExecutable when it is translated to Java source code.
 void setBody(JvmExecutable logicalContainer, XExpression expr)
          Sets the given JvmExecutable as the logical container for the given XExpression.
 void setDocumentation(JvmIdentifiableElement jvmElement, java.lang.String documentation)
          Attaches the given documentation to the given jvmElement.
protected  Pair<java.lang.String,java.lang.String> splitQualifiedName(java.lang.String name)
           
 JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement, java.lang.Class<?> annotationType)
          Creates and returns an annotation of the given annotation type.
 JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement, java.lang.Class<?> annotationType, java.lang.Object value)
          Creates and returns an annotation of the given annotation type's name and the given value.
 JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String annotationTypeName)
          Creates and returns an annotation of the given annotation type's name.
 JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String annotationTypeName, java.lang.Object value)
          Creates and returns an annotation of the given annotation type's name and the given value.
 JvmAnnotationType toAnnotationType(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, Procedures.Procedure1<JvmAnnotationType> initializer)
          Creates a public annotation declaration, associated to the given sourceElement.
 JvmGenericType toClass(org.eclipse.emf.ecore.EObject sourceElement, QualifiedName name, Procedures.Procedure1<JvmGenericType> initializer)
          Creates a public class declaration, associated to the given sourceElement.
 JvmGenericType toClass(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, Procedures.Procedure1<JvmGenericType> initializer)
          Creates a public class declaration, associated to the given sourceElement.
 JvmConstructor toConstructor(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String simpleName, Procedures.Procedure1<JvmConstructor> init)
          Creates and returns a constructor with the given simple name associated to the given source element.
 JvmEnumerationType toEnumerationType(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, Procedures.Procedure1<JvmEnumerationType> initializer)
          Creates a public enum declaration, associated to the given sourceElement.
 JvmField toField(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, JvmTypeReference typeRef)
          Creates a private field with the given name and the given type associated to the given sourceElement.
 JvmField toField(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, JvmTypeReference typeRef, Procedures.Procedure1<JvmField> initializer)
           
 JvmOperation toGetter(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, JvmTypeReference typeRef)
          Creates a getter method for the given properties name with a simple implementation returning the value of a similarly named field.
 JvmGenericType toInterface(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, Procedures.Procedure1<JvmGenericType> initializer)
          Creates a public interface declaration, associated to the given sourceElement.
 JvmOperation toMethod(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, JvmTypeReference returnType, Procedures.Procedure1<JvmOperation> init)
          Creates a public method with the given name and the given return type and associates it with the given sourceElement.
 JvmFormalParameter toParameter(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, JvmTypeReference typeRef)
          Creates and returns a formal parameter for the given name and type, which is associated to the given source element.
 JvmOperation toSetter(org.eclipse.emf.ecore.EObject sourceElement, java.lang.String name, JvmTypeReference typeRef)
          Creates a setter method for the given properties name with the standard implementation assigning the passed parameter to a similarly named field.
 void translateAnnotationsTo(java.lang.Iterable<? extends XAnnotation> annotations, JvmAnnotationTarget target)
          translates XAnnotations to JvmAnnotationReferences and adds them to the given JvmAnnotationTarget
protected  org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.AnnotationValueTranslator translator(XExpression obj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JvmTypesBuilder

public JvmTypesBuilder()
Method Detail

setBody

public void setBody(JvmExecutable logicalContainer,
                    XExpression expr)
Sets the given JvmExecutable as the logical container for the given XExpression. This defines the context and sīthe scope for the given expression.

Parameters:
logicalContainer - - the JvmExecutable the expression is associated with. Must not be null.
expr - - the expression. Can be null in which case this function does nothing.

setBody

public void setBody(JvmExecutable executable,
                    Functions.Function1<ImportManager,? extends java.lang.CharSequence> strategy)
Attaches the given compile strategy to the given JvmExecutable such that the compiler knows how to implement the JvmExecutable when it is translated to Java source code.

Parameters:
executable - - the operation or constructor to add the method body to.
strategy - - the compilation strategy. Must return zero or more Java statements.

getDocumentation

public java.lang.String getDocumentation(org.eclipse.emf.ecore.EObject source)

setDocumentation

public void setDocumentation(JvmIdentifiableElement jvmElement,
                             java.lang.String documentation)
Attaches the given documentation to the given jvmElement.


toClass

public JvmGenericType toClass(org.eclipse.emf.ecore.EObject sourceElement,
                              QualifiedName name,
                              Procedures.Procedure1<JvmGenericType> initializer)
Creates a public class declaration, associated to the given sourceElement. It sets the given name, which might be fully qualified using the standard Java notation.

Parameters:
sourceElement - - the sourceElement the resulting element is associated with.
qualifiedName - - the qualifiedName of the resulting class.
initializer - - the initializer to apply on the created class element
Returns:
a JvmGenericType representing a Java class of the given name.

toClass

public JvmGenericType toClass(org.eclipse.emf.ecore.EObject sourceElement,
                              java.lang.String name,
                              Procedures.Procedure1<JvmGenericType> initializer)
Creates a public class declaration, associated to the given sourceElement. It sets the given name, which might be fully qualified using the standard Java notation.

Parameters:
sourceElement - - the sourceElement the resulting element is associated with.
qualifiedName - - the qualifiedName of the resulting class.
initializer - - the initializer to apply on the created class element
Returns:
a JvmGenericType representing a Java class of the given name.

toInterface

public JvmGenericType toInterface(org.eclipse.emf.ecore.EObject sourceElement,
                                  java.lang.String name,
                                  Procedures.Procedure1<JvmGenericType> initializer)
Creates a public interface declaration, associated to the given sourceElement. It sets the given name, which might be fully qualified using the standard Java notation.

Parameters:
sourceElement - - the sourceElement the resulting element is associated with.
qualifiedName - - the qualifiedName of the resulting class.
initializer - - the initializer to apply on the created interface declaration.
Returns:
a JvmGenericType representing a Java interface of the given name.

toAnnotationType

public JvmAnnotationType toAnnotationType(org.eclipse.emf.ecore.EObject sourceElement,
                                          java.lang.String name,
                                          Procedures.Procedure1<JvmAnnotationType> initializer)
Creates a public annotation declaration, associated to the given sourceElement. It sets the given name, which might be fully qualified using the standard Java notation.

Parameters:
sourceElement - - the sourceElement the resulting element is associated with.
qualifiedName - - the qualifiedName of the resulting class.
initializer - - the initializer to apply on the created annotation
Returns:
a JvmAnnotationType representing a Java annatation of the given name.

toEnumerationType

public JvmEnumerationType toEnumerationType(org.eclipse.emf.ecore.EObject sourceElement,
                                            java.lang.String name,
                                            Procedures.Procedure1<JvmEnumerationType> initializer)
Creates a public enum declaration, associated to the given sourceElement. It sets the given name, which might be fully qualified using the standard Java notation.

Parameters:
sourceElement - - the sourceElement the resulting element is associated with.
qualifiedName - - the qualifiedName of the resulting class.
initializer - - the initializer to apply on the created enumeration type
Returns:
a result representing a Java class of the given name.

createJvmGenericType

protected JvmGenericType createJvmGenericType(org.eclipse.emf.ecore.EObject sourceElement,
                                              java.lang.String name)

splitQualifiedName

protected Pair<java.lang.String,java.lang.String> splitQualifiedName(java.lang.String name)

toField

public JvmField toField(org.eclipse.emf.ecore.EObject sourceElement,
                        java.lang.String name,
                        JvmTypeReference typeRef)
Creates a private field with the given name and the given type associated to the given sourceElement.

Parameters:
sourceElement - - the sourceElement the resulting element is associated with.
name - - the simple name of the resulting class.
typeRef - - the type of the field
Returns:
a JvmField representing a Java field with the given simple name and type.

toField

public JvmField toField(org.eclipse.emf.ecore.EObject sourceElement,
                        java.lang.String name,
                        JvmTypeReference typeRef,
                        Procedures.Procedure1<JvmField> initializer)

nullSaveName

protected java.lang.String nullSaveName(java.lang.String name)

associate

public <T extends JvmIdentifiableElement> T associate(org.eclipse.emf.ecore.EObject sourceElement,
                                                      T target)
Associates a source element with a target element. This association is used for tracing. Navigation, for instance, uses this information to find the real declaration of a Jvm element.

See Also:
IJvmModelAssociator, IJvmModelAssociations

toMethod

public JvmOperation toMethod(org.eclipse.emf.ecore.EObject sourceElement,
                             java.lang.String name,
                             JvmTypeReference returnType,
                             Procedures.Procedure1<JvmOperation> init)
Creates a public method with the given name and the given return type and associates it with the given sourceElement.


toGetter

public JvmOperation toGetter(org.eclipse.emf.ecore.EObject sourceElement,
                             java.lang.String name,
                             JvmTypeReference typeRef)
Creates a getter method for the given properties name with a simple implementation returning the value of a similarly named field. Example: public String getFoo() { return this.foo; }


toSetter

public JvmOperation toSetter(org.eclipse.emf.ecore.EObject sourceElement,
                             java.lang.String name,
                             JvmTypeReference typeRef)
Creates a setter method for the given properties name with the standard implementation assigning the passed parameter to a similarly named field. Example: public void setFoo(String foo) { this.foo = foo; }


toParameter

public JvmFormalParameter toParameter(org.eclipse.emf.ecore.EObject sourceElement,
                                      java.lang.String name,
                                      JvmTypeReference typeRef)
Creates and returns a formal parameter for the given name and type, which is associated to the given source element.


toConstructor

public JvmConstructor toConstructor(org.eclipse.emf.ecore.EObject sourceElement,
                                    java.lang.String simpleName,
                                    Procedures.Procedure1<JvmConstructor> init)
Creates and returns a constructor with the given simple name associated to the given source element. By default the constructor will have an empty body and no arguments, hence the Java default constructor.


toAnnotation

public JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement,
                                           java.lang.Class<?> annotationType)
Creates and returns an annotation of the given annotation type.


toAnnotation

public JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement,
                                           java.lang.String annotationTypeName)
Creates and returns an annotation of the given annotation type's name.


toAnnotation

public JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement,
                                           java.lang.Class<?> annotationType,
                                           java.lang.Object value)
Creates and returns an annotation of the given annotation type's name and the given value.

Parameters:
sourceElement - - the source element to associate the created element with.
annotationType - - the type of the created annotation.
value - - the value of the single

toAnnotation

public JvmAnnotationReference toAnnotation(org.eclipse.emf.ecore.EObject sourceElement,
                                           java.lang.String annotationTypeName,
                                           java.lang.Object value)
Creates and returns an annotation of the given annotation type's name and the given value.

Parameters:
sourceElement - - the source element to associate the created element with.
annotationTypeNAme - - the type name of the created annotation.
value - - the value of the single

cloneWithProxies

public JvmTypeReference cloneWithProxies(JvmTypeReference typeRef)
Creates a clone of the given JvmTypeReference without resolving any proxies.


initialization

public void initialization(JvmField field,
                           Functions.Function1<ImportManager,? extends java.lang.CharSequence> strategy)
Attaches the given compile strategy to the given JvmField such that the compiler knows how to initialize the JvmField when it is translated to Java source code.

Parameters:
field - - the field to add the initializer to.
strategy - - the compilation strategy. Must return just one valid Java expression.

addCompilationStrategy

protected void addCompilationStrategy(JvmMember member,
                                      Functions.Function1<ImportManager,? extends java.lang.CharSequence> strategy)

newTypeRef

public JvmTypeReference newTypeRef(org.eclipse.emf.ecore.EObject ctx,
                                   java.lang.Class<?> clazz,
                                   JvmTypeReference... typeArgs)
Creates a new JvmTypeReference pointing to the given class and containing the given type arguments.

Parameters:
ctx - - an EMF context, which is used to look up the JvmType for the given clazz.
clazz - - the class the type reference shall point to.
typeArgs - - type arguments
Returns:
the newly created JvmTypeReference

newTypeRef

public JvmTypeReference newTypeRef(org.eclipse.emf.ecore.EObject ctx,
                                   java.lang.String typeName,
                                   JvmTypeReference... typeArgs)
Creates a new JvmTypeReference pointing to the given class and containing the given type arguments.

Parameters:
ctx - - an EMF context, which is used to look up the JvmType for the given clazz.
typeName - - the name of the type the reference shall point to.
typeArgs - - type arguments
Returns:
the newly created JvmTypeReference

addArrayTypeDimension

public JvmTypeReference addArrayTypeDimension(JvmTypeReference componentType)
Returns:
an array type of the given type reference. Add one dimension if the given JvmTypeReference is already an array.

translateAnnotationsTo

public void translateAnnotationsTo(java.lang.Iterable<? extends XAnnotation> annotations,
                                   JvmAnnotationTarget target)
translates XAnnotations to JvmAnnotationReferences and adds them to the given JvmAnnotationTarget


getJvmAnnotationReference

protected JvmAnnotationReference getJvmAnnotationReference(XAnnotation anno)

getJvmAnnotationValue

protected JvmAnnotationValue getJvmAnnotationValue(XExpression value)

translator

protected org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.AnnotationValueTranslator translator(XExpression obj)