Java源码示例:org.eclipse.xtext.common.types.JvmAnnotationType
示例1
protected void highlightDeprecatedXtendAnnotationTarget(IHighlightedPositionAcceptor acceptor, XtendAnnotationTarget target, XAnnotation annotation){
JvmType annotationType = annotation.getAnnotationType();
if(annotationType instanceof JvmAnnotationType && DeprecationUtil.isDeprecatedAnnotation((JvmAnnotationType) annotationType)){
if (target instanceof XtendConstructor) {
ICompositeNode compositeNode = NodeModelUtils.getNode(target);
for(ILeafNode leaf: compositeNode.getLeafNodes()) {
if (leaf.getGrammarElement() == xtendGrammarAccess.getMemberAccess().getNewKeyword_2_2_2()) {
highlightNode(acceptor, leaf, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
highlightNode(acceptor, leaf, HighlightingStyles.KEYWORD_ID);
return;
}
}
} else {
EStructuralFeature nameFeature = target.eClass().getEStructuralFeature("name");
if (nameFeature!=null) {
highlightFeature(acceptor, target, nameFeature, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
}
}
}
}
示例2
@Test
public void testStubGeneration_04() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public @interface MyTest {");
_builder.newLine();
_builder.append("\t");
_builder.append("String value();");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy();
Assert.assertTrue((_eObjectOrProxy instanceof JvmAnnotationType));
Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
};
this.resultsIn(_builder, _function);
}
示例3
@Override
public boolean validate(IAcceptor<? super AbstractDiagnostic> result) {
JvmType type = (JvmType) description.getElementOrProxy();
String typeKind = "";
if (type instanceof JvmPrimitiveType || type instanceof JvmVoid) {
typeKind = "primitive type";
} else if (type instanceof JvmAnnotationType) {
typeKind = "annotation type";
} else if (type instanceof JvmEnumerationType) {
typeKind = "enum type";
} else if (type instanceof JvmGenericType && ((JvmGenericType) type).isInterface()) {
typeKind = "interface type";
} else if (type instanceof JvmTypeParameter) {
typeKind = "type parameter";
}
String message = String.format("Cannot instantiate the %s %s", typeKind, type.getSimpleName());
AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR,
IssueCodes.ILLEGAL_CLASS_INSTANTIATION, message, getExpression(),
XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, -1, null);
result.accept(diagnostic);
return false;
}
示例4
/**
* Creates and returns an annotation reference of the given annotation type's name and the given value.
*
* @param sourceElement
* the source element to associate the created element with.
* @param annotationTypeName
* the type name of the created annotation.
* @param value
* the value of the annotation reference. Can be <code>null</code> if the reference doesn't have any value.
*
* @return a result representing an annotation reference to the given annotation type, <code>null<code> if
* sourceElement or annotationType are <code>null</code>.
*
* @deprecated use {@link JvmAnnotationReferenceBuilder#annotationRef(String, String...)} instead
*/
//TODO Move up the code used in Xtend's CompilationUnitImpl so we can reuse it here.
/* @Nullable */
@Deprecated
public JvmAnnotationReference toAnnotation(/* @Nullable */ EObject sourceElement, /* @Nullable */ String annotationTypeName, /* @Nullable */ Object value) {
JvmAnnotationReference result = typesFactory.createJvmAnnotationReference();
JvmType jvmType = references.findDeclaredType(annotationTypeName, sourceElement);
if (jvmType == null) {
throw new IllegalArgumentException("The type "+annotationTypeName +" is not on the classpath.");
}
if (!(jvmType instanceof JvmAnnotationType)) {
throw new IllegalArgumentException("The given class " + annotationTypeName + " is not an annotation type.");
}
result.setAnnotation((JvmAnnotationType) jvmType);
if (value != null) {
if (value instanceof String) {
JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue();
annotationValue.getValues().add((String) value);
result.getExplicitValues().add(annotationValue);
}
}
return result;
}
示例5
/**
* Creates and returns an annotation reference of the given annotation type's name and the given value.
*
* @param annotationTypeName
* the type name of the created annotation.
* @param values
* the string value of the annotation's 'values' property.
*
* @return a result representing an annotation reference to the given annotation type, <code>null<code> if
* annotationType are <code>null</code>.
*/
//TODO Move up the code used in Xtend's CompilationUnitImpl so we can reuse it here.
//TODO Support other types and setting non default properties
/* @Nullable */
public JvmAnnotationReference annotationRef(/* @Nullable */ String annotationTypeName, /* @Nullable */ String... values) {
if (context == null || annotationTypeName == null)
return null;
JvmAnnotationReference result = typesFactory.createJvmAnnotationReference();
JvmType jvmType = references.findDeclaredType(annotationTypeName, context);
if (jvmType == null) {
throw new IllegalArgumentException("The type "+annotationTypeName +" is not on the classpath.");
}
if (!(jvmType instanceof JvmAnnotationType)) {
throw new IllegalArgumentException("The given class " + annotationTypeName + " is not an annotation type.");
}
result.setAnnotation((JvmAnnotationType) jvmType);
if (values != null && values.length>0) {
JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue();
for (String value : values) {
annotationValue.getValues().add(value);
}
result.getExplicitValues().add(annotationValue);
}
return result;
}
示例6
@Check
public void checkAllAttributesConfigured(XAnnotation annotation) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType))
return;
Iterable<JvmOperation> attributes = ((JvmAnnotationType) annotationType).getDeclaredOperations();
for (JvmOperation jvmOperation : attributes) {
XExpression value = annotationUtil.findValue(annotation, jvmOperation);
if(value == null) {
if (jvmOperation.getDefaultValue() == null) {
error("The annotation must define the attribute '"+jvmOperation.getSimpleName()+"'.", annotation, null,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION);
}
} else
annotationValueValidator.validateAnnotationValue(value, this);
}
}
示例7
protected void registerMacroAnnotations(final XtendAnnotationTarget candidate, final IAcceptor<Pair<JvmAnnotationType, XAnnotation>> acceptor) {
final Function1<XAnnotation, Boolean> _function = (XAnnotation it) -> {
return Boolean.valueOf(this._xAnnotationExtensions.isProcessed(it));
};
Iterable<XAnnotation> _filter = IterableExtensions.<XAnnotation>filter(candidate.getAnnotations(), _function);
for (final XAnnotation annotation : _filter) {
{
final JvmAnnotationType activeAnnotationDeclaration = this._xAnnotationExtensions.tryFindAnnotationType(annotation);
if ((activeAnnotationDeclaration != null)) {
boolean _isValid = this.isValid(annotation, activeAnnotationDeclaration);
if (_isValid) {
Pair<JvmAnnotationType, XAnnotation> _mappedTo = Pair.<JvmAnnotationType, XAnnotation>of(activeAnnotationDeclaration, annotation);
acceptor.accept(_mappedTo);
}
}
}
}
}
示例8
public JvmAnnotationType tryFindAnnotationType(final XAnnotation it) {
Object _eGet = it.eGet(XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false);
final Object proxy = _eGet;
boolean _matched = false;
if (proxy instanceof EObject) {
boolean _eIsProxy = ((EObject)proxy).eIsProxy();
if (_eIsProxy) {
_matched=true;
final URI uri = ((InternalEObject) proxy).eProxyURI();
EObject _eObject = it.eResource().getResourceSet().getEObject(uri, true);
return ((JvmAnnotationType) _eObject);
}
}
if (!_matched) {
if (proxy instanceof JvmAnnotationType) {
_matched=true;
return ((JvmAnnotationType)proxy);
}
}
return null;
}
示例9
protected JvmOperation findOperation(final String name) {
ConditionUtils.checkJavaIdentifier(name, "name");
final JvmAnnotationType annotationType = this.delegate.getAnnotation();
final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
String _simpleName = it.getSimpleName();
return Boolean.valueOf(Objects.equal(_simpleName, name));
};
final JvmOperation jvmOperation = IterableExtensions.<JvmOperation>findFirst(annotationType.getDeclaredOperations(), _function);
if ((jvmOperation == null)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("The annotation property \'");
_builder.append(name);
_builder.append("\' is not declared on the annotation type \'");
String _identifier = annotationType.getIdentifier();
_builder.append(_identifier);
_builder.append("\'.");
throw new IllegalArgumentException(_builder.toString());
}
return jvmOperation;
}
示例10
@Test
public void testStringAnnotation() {
try {
final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
final XExpression e = this.expression("\'Foo\'");
final XAnnotation anno = f.createXAnnotation();
JvmType _findDeclaredType = this.references.findDeclaredType(Inject.class, e);
anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType));
anno.setValue(e);
final JvmGenericType type = this.typesFactory.createJvmGenericType();
this._jvmTypesBuilder.addAnnotation(type, anno);
Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues());
EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues());
Assert.assertTrue((_head_1 instanceof XStringLiteral));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例11
@Test
public void testAnnotationDefaultValue() {
try {
final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
final XExpression e = this.expression("\'Foo\'");
final XAnnotation anno = f.createXAnnotation();
JvmType _findDeclaredType = this.references.findDeclaredType(Named.class, e);
anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType));
anno.setValue(e);
final JvmGenericType type = this.typesFactory.createJvmGenericType();
this._jvmTypesBuilder.addAnnotation(type, anno);
Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues());
EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues());
Assert.assertTrue((_head_1 instanceof XStringLiteral));
Assert.assertNull(IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()).getOperation());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例12
@Test
public void testNestedAnnotationType() {
try {
final XExpression expression = this.expression("42");
final JvmGenericType outerClass = this.builder.toClass(expression, "my.outer.Clazz");
EList<JvmMember> _members = outerClass.getMembers();
final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> {
EList<JvmMember> _members_1 = it.getMembers();
final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
this.builder.setBody(it_1, expression);
};
JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1);
this.builder.<JvmOperation>operator_add(_members_1, _method);
};
JvmAnnotationType _annotationType = this.builder.toAnnotationType(expression, "MyAnnotation", _function);
this.builder.<JvmAnnotationType>operator_add(_members, _annotationType);
final Class<?> compiled = IterableExtensions.<Class<?>>head(((Iterable<Class<?>>)Conversions.doWrapArray(this.compile(expression.eResource(), outerClass).getDeclaredClasses())));
Assert.assertEquals("my.outer.Clazz.MyAnnotation", compiled.getCanonicalName());
Assert.assertEquals(Integer.valueOf(42), IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiled.getDeclaredMethods()))).getDefaultValue());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例13
@Override
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
AnnotationTypeDeclaration _switchResult = null;
JvmType _annotationType = this.getAnnotationType();
final JvmType type = _annotationType;
boolean _matched = false;
if (type instanceof JvmAnnotationType) {
_matched=true;
TypeDeclaration _typeDeclaration = this.getCompilationUnit().toTypeDeclaration(((JvmDeclaredType)type));
_switchResult = ((AnnotationTypeDeclaration) _typeDeclaration);
}
if (!_matched) {
_switchResult = null;
}
return _switchResult;
}
示例14
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
switch (featureID)
{
case TypesPackage.JVM_ANNOTATION_REFERENCE__ANNOTATION:
setAnnotation((JvmAnnotationType)newValue);
return;
case TypesPackage.JVM_ANNOTATION_REFERENCE__EXPLICIT_VALUES:
getExplicitValues().clear();
getExplicitValues().addAll((Collection<? extends JvmAnnotationValue>)newValue);
return;
}
super.eSet(featureID, newValue);
}
示例15
@Test
public void testMemberCount_14() {
String typeName = TestAnnotation.class.getName();
JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
int methodCount = TestAnnotation.class.getDeclaredMethods().length;
assertEquals(15, methodCount);
int innerTypesCount = TestAnnotation.class.getDeclaredClasses().length;
assertEquals(2, innerTypesCount);
int fieldCount = TestAnnotation.class.getDeclaredFields().length;
assertEquals(1, fieldCount);
assertEquals(fieldCount + methodCount + innerTypesCount, type.getMembers().size());
}
示例16
@Test
public void testMemberCount_17() {
String typeName = TestAnnotationWithDefaults.class.getName();
JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
int methodCount = TestAnnotationWithDefaults.class.getDeclaredMethods().length;
assertEquals(15, methodCount);
int innerTypesCount = TestAnnotationWithDefaults.class.getDeclaredClasses().length;
assertEquals(1, innerTypesCount);
assertEquals(methodCount + innerTypesCount, type.getMembers().size());
}
示例17
@Test
public void testAnnotationType_02() throws Exception {
String typeName = TestAnnotation.class.getName();
JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
assertEquals(1, type.getSuperTypes().size());
assertEquals(Annotation.class.getName(), type.getSuperTypes().get(0).getIdentifier());
}
示例18
@Test
public void testNestedAnnotationType_02() throws Exception {
String typeName = TestAnnotation.NestedAnnotation.class.getName();
JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
assertEquals(1, type.getSuperTypes().size());
assertEquals(Annotation.class.getName(), type.getSuperTypes().get(0).getIdentifier());
}
示例19
@Test
public void testAnnotationType_03() throws Exception {
String typeName = TestAnnotationWithDefaults.class.getName();
JvmType type = getTypeProvider().findTypeByName(typeName);
assertNotNull(type);
assertTrue(type instanceof JvmAnnotationType);
diagnose(type);
Resource resource = type.eResource();
getAndResolveAllFragments(resource);
recomputeAndCheckIdentifiers(resource);
}
示例20
@Test
public void testAnnotationType_04() throws Exception {
String typeName = TestAnnotationWithDefaults.class.getName();
JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
assertEquals(1, type.getSuperTypes().size());
assertEquals(Annotation.class.getName(), type.getSuperTypes().get(0).getIdentifier());
}
示例21
private void doTestAnnotation_01(JvmAnnotationTarget target) {
JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider()
.findTypeByName(TestAnnotation.class.getName());
assertEquals(1, target.getAnnotations().size());
JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
assertSame(annotationType, annotationReference.getAnnotation());
if (isDefaultValueSupported())
assertEquals(14, annotationReference.getExplicitValues().size());
assertEquals(15, annotationReference.getValues().size());
}
示例22
@Test
public void testAnnotatedParameter_03() throws Exception {
String typeName = TestAnnotation.Annotated.class.getName();
JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider()
.findTypeByName(TestAnnotation.NestedAnnotation.class.getName());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class,
"Annotated(java.lang.String,java.lang.String,java.lang.String)");
JvmAnnotationTarget target = constructor.getParameters().get(2);
assertEquals(1, target.getAnnotations().size());
JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
assertSame(annotationType, annotationReference.getAnnotation());
}
示例23
@Test
public void testAnnotatedParameter_06() throws Exception {
String typeName = TestAnnotation.Annotated.class.getName();
JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider()
.findTypeByName(TestAnnotation.NestedAnnotation.class.getName());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
JvmOperation method = getMethodFromType(type, TestAnnotation.Annotated.class,
"method(java.lang.String,java.lang.String,java.lang.String)");
JvmAnnotationTarget target = method.getParameters().get(2);
assertEquals(1, target.getAnnotations().size());
JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
assertSame(annotationType, annotationReference.getAnnotation());
}
示例24
public JvmAnnotationValue getDefaultAnnotationValue(String name) {
String typeName = TestAnnotationWithDefaults.class.getName();
JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
JvmOperation operation = getMethodFromType(type, TestAnnotationWithDefaults.class, name + "()");
JvmAnnotationValue result = operation.getDefaultValue();
assertNotNull(result);
assertSame(operation, result.getOperation());
return result;
}
示例25
@Test
public void testAnnotationAbstract() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotation Foo {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmAnnotationType inferred = this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString()));
Assert.assertTrue(inferred.isAbstract());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例26
/**
* 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.
*
* @param sourceElement
* the sourceElement the resulting element is associated with.
* @param name
* the qualified name of the resulting class.
* @param initializer
* the initializer to apply on the created annotation. If <code>null</code>, the annotation won't be initialized.
*
* @return a {@link JvmAnnotationType} representing a Java annotation of the given name, <code>null</code>
* if sourceElement or name are <code>null</code>.
*/
/* @Nullable */
public JvmAnnotationType toAnnotationType(/* @Nullable */ EObject sourceElement, /* @Nullable */ String name,
/* @Nullable */ Procedure1<? super JvmAnnotationType> initializer) {
if (sourceElement == null || name == null)
return null;
Pair<String, String> fullName = splitQualifiedName(name);
JvmAnnotationType annotationType = typesFactory.createJvmAnnotationType();
annotationType.setSimpleName(fullName.getSecond());
annotationType.setAbstract(true);
if (fullName.getFirst() != null)
annotationType.setPackageName(fullName.getFirst());
associate(sourceElement, annotationType);
return initializeSafely(annotationType, initializer);
}
示例27
/**
* Translates a single {@link XAnnotation} to {@link JvmAnnotationReference} that can be added to a {@link JvmAnnotationTarget}.
*
* @param anno the source annotation
*
* @return a {@link JvmAnnotationReference} that can be attached to some {@link JvmAnnotationTarget}
*/
/* @Nullable */
public JvmAnnotationReference getJvmAnnotationReference(/* @Nullable */ XAnnotation anno) {
if(anno == null)
return null;
JvmAnnotationReference reference = typesFactory.createJvmAnnotationReference();
final JvmType annotation = (JvmType) anno.eGet(
XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false);
if (annotation.eIsProxy()) {
JvmAnnotationType copiedProxy = TypesFactory.eINSTANCE.createJvmAnnotationType();
((InternalEObject)copiedProxy).eSetProxyURI(EcoreUtil.getURI(annotation));
reference.setAnnotation(copiedProxy);
} else if (annotation instanceof JvmAnnotationType){
reference.setAnnotation((JvmAnnotationType) annotation);
}
for (XAnnotationElementValuePair val : anno.getElementValuePairs()) {
XExpression valueExpression = val.getValue();
JvmAnnotationValue annotationValue = toJvmAnnotationValue(valueExpression);
if (annotationValue != null) {
JvmOperation op = (JvmOperation) val.eGet(
XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT, false);
annotationValue.setOperation(op);
reference.getExplicitValues().add(annotationValue);
}
}
if (anno.getValue() != null) {
JvmAnnotationValue value = toJvmAnnotationValue(anno.getValue());
if (value != null) {
reference.getExplicitValues().add(value);
}
}
associate(anno, reference);
return reference;
}
示例28
/** Find an annotation.
*
* @param annotationTarget the annotation target.
* @param lookupType the name of the type to look for.
* @return the annotation or {@code null}.
* @see AnnotationLookup#findAnnotation(JvmAnnotationTarget, Class)
*/
@SuppressWarnings("static-method")
public JvmAnnotationReference findAnnotation(JvmAnnotationTarget annotationTarget, String lookupType) {
// avoid creating an empty list for all given targets but check for #eIsSet first
if (annotationTarget.eIsSet(TypesPackage.Literals.JVM_ANNOTATION_TARGET__ANNOTATIONS)) {
for (final JvmAnnotationReference annotation: annotationTarget.getAnnotations()) {
final JvmAnnotationType annotationType = annotation.getAnnotation();
if (annotationType != null && Objects.equals(lookupType, annotationType.getQualifiedName())) {
return annotation;
}
}
}
return null;
}
示例29
protected void initialize(XtendAnnotationType source, JvmAnnotationType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (!Strings.isEmpty(field.getName())) {
JvmOperation operation = typesFactory.createJvmOperation();
associator.associatePrimary(member, operation);
operation.setSimpleName(field.getName());
JvmTypeReference returnType = null;
XExpression initialValue = field.getInitialValue();
if (field.getType() != null) {
returnType = jvmTypesBuilder.cloneWithProxies(field.getType());
} else if (initialValue != null) {
returnType = jvmTypesBuilder.inferredType(initialValue);
}
operation.setReturnType(returnType);
if (initialValue != null) {
JvmAnnotationValue jvmAnnotationValue = jvmTypesBuilder.toJvmAnnotationValue(initialValue);
if (jvmAnnotationValue != null) {
operation.setDefaultValue(jvmAnnotationValue);
jvmAnnotationValue.setOperation(operation);
}
jvmTypesBuilder.setBody(operation, initialValue);
}
operation.setVisibility(JvmVisibility.PUBLIC);
translateAnnotationsTo(member.getAnnotations(), operation);
jvmTypesBuilder.copyDocumentationTo(member, operation);
inferredJvmType.getMembers().add(operation);
}
}
}
}
示例30
private JvmOperation getOperation(JvmAnnotationType annotationType, String operationName) {
for (JvmOperation operation : annotationType.getDeclaredOperations()) {
if (operationName.equals(operation.getSimpleName()))
return operation;
}
return null;
}