Java Code Examples for org.eclipse.xtext.common.types.JvmOperation#getAnnotations()

The following examples show how to use org.eclipse.xtext.common.types.JvmOperation#getAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValueByReference() throws Exception {
	String typeName = Bug334943Client.class.getName();
	JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0);
	List<JvmAnnotationReference> annotations = operation.getAnnotations();
	assertEquals(1, annotations.size());
	JvmAnnotationReference annotation = annotations.get(0);
	for (JvmAnnotationValue value : annotation.getValues()) {
		if ("enumValue".equals(value.getValueName())) {
			JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value;
			assertEquals(1, enumValue.getValues().size());
			assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName());
		}
	}
}
 
Example 2
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValueByReference() throws Exception {
	String typeName = Bug334943Client.class.getName();
	JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0);
	List<JvmAnnotationReference> annotations = operation.getAnnotations();
	assertEquals(1, annotations.size());
	JvmAnnotationReference annotation = annotations.get(0);
	for (JvmAnnotationValue value : annotation.getValues()) {
		if ("enumValue".equals(value.getValueName())) {
			JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value;
			assertEquals(1, enumValue.getValues().size());
			assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName());
		}
	}
}
 
Example 3
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValueByReference() throws Exception {
	String typeName = Bug334943Client.class.getName();
	JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0);
	List<JvmAnnotationReference> annotations = operation.getAnnotations();
	assertEquals(1, annotations.size());
	JvmAnnotationReference annotation = annotations.get(0);
	for (JvmAnnotationValue value : annotation.getValues()) {
		if ("enumValue".equals(value.getValueName())) {
			JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value;
			assertEquals(1, enumValue.getValues().size());
			assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName());
		}
	}
}
 
Example 4
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug380754() {
  try {
    final XExpression expression = this.expression("null");
    final JvmAnnotationReferenceBuilder jvmAnnotationReferenceBuilder = this.jvmAnnotationReferenceBuilderFactory.create(expression.eResource().getResourceSet());
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmMember> _members = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
        this.builder.setBody(it_1, expression);
        final JvmAnnotationReference annotation = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotations.class);
        final JvmAnnotationAnnotationValue annotationAnnotationValue = this.typesFactory.createJvmAnnotationAnnotationValue();
        EList<JvmAnnotationReference> _values = annotationAnnotationValue.getValues();
        JvmAnnotationReference _annotationRef = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class);
        this.builder.<JvmAnnotationReference>operator_add(_values, _annotationRef);
        EList<JvmAnnotationReference> _values_1 = annotationAnnotationValue.getValues();
        JvmAnnotationReference _annotationRef_1 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class);
        this.builder.<JvmAnnotationReference>operator_add(_values_1, _annotationRef_1);
        EList<JvmAnnotationReference> _values_2 = annotationAnnotationValue.getValues();
        JvmAnnotationReference _annotationRef_2 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class);
        this.builder.<JvmAnnotationReference>operator_add(_values_2, _annotationRef_2);
        EList<JvmAnnotationValue> _explicitValues = annotation.getExplicitValues();
        this.builder.<JvmAnnotationAnnotationValue>operator_add(_explicitValues, annotationAnnotationValue);
        EList<JvmAnnotationReference> _annotations = it_1.getAnnotations();
        this.builder.<JvmAnnotationReference>operator_add(_annotations, annotation);
      };
      JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members, _method);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    this.compile(expression.eResource(), clazz);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug419430() {
  try {
    final XExpression expression = this.expression("null");
    final JvmAnnotationReferenceBuilder jvmAnnotationReferenceBuilder = this.jvmAnnotationReferenceBuilderFactory.create(expression.eResource().getResourceSet());
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmMember> _members = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
        this.builder.setBody(it_1, expression);
        final JvmAnnotationReference annotation = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotations.class);
        final JvmAnnotationAnnotationValue annotationAnnotationValue = this.typesFactory.createJvmAnnotationAnnotationValue();
        EList<JvmAnnotationReference> _values = annotationAnnotationValue.getValues();
        JvmAnnotationReference _annotationRef = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class);
        this.builder.<JvmAnnotationReference>operator_add(_values, _annotationRef);
        EList<JvmAnnotationReference> _values_1 = annotationAnnotationValue.getValues();
        JvmAnnotationReference _annotationRef_1 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class);
        this.builder.<JvmAnnotationReference>operator_add(_values_1, _annotationRef_1);
        EList<JvmAnnotationReference> _values_2 = annotationAnnotationValue.getValues();
        JvmAnnotationReference _annotationRef_2 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class);
        this.builder.<JvmAnnotationReference>operator_add(_values_2, _annotationRef_2);
        EList<JvmAnnotationValue> _explicitValues = annotation.getExplicitValues();
        this.builder.<JvmAnnotationAnnotationValue>operator_add(_explicitValues, annotationAnnotationValue);
        EList<JvmAnnotationReference> _annotations = it_1.getAnnotations();
        this.builder.<JvmAnnotationReference>operator_add(_annotations, annotation);
      };
      JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members, _method);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    final String code = this.generate(expression.eResource(), clazz);
    Assert.assertTrue(code, code.contains("@TestAnnotations({ @TestAnnotation, @TestAnnotation, @TestAnnotation })"));
    final Class<?> compiledClazz = this.compileToClass(expression.eResource(), clazz, code);
    final Method method = compiledClazz.getMethod("doStuff");
    final TestAnnotations methodAnnotation = method.<TestAnnotations>getAnnotation(TestAnnotations.class);
    Assert.assertEquals(3, ((List<TestAnnotation>)Conversions.doWrapArray(methodAnnotation.value())).size());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: MissedMethodAddModification.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies if the given method is marked has automatically generated by the SARL compiler.
 *
 * @param method the method to check.
 * @return <code>true</code> if the method is annoted with SyntheticMember; <code>false</code>
 *     otherwise.
 */
public static boolean isGeneratedOperation(JvmOperation method) {
	for (final JvmAnnotationReference annotation : method.getAnnotations()) {
		if (Objects.equals(SyntheticMember.class.getName(), annotation.getAnnotation().getIdentifier())
				|| Objects.equals(Generated.class.getName(), annotation.getAnnotation().getIdentifier())) {
			return true;
		}
	}
	return false;
}