Java Code Examples for org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue#getValues()

The following examples show how to use org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue#getValues() . 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: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createAnnotationAnnotationValue(Object value) {
	JvmAnnotationAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmAnnotationAnnotationValue();
	if (value != null) {
		InternalEList<JvmAnnotationReference> values = (InternalEList<JvmAnnotationReference>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof IAnnotationBinding) {
					values.addUnique(createAnnotationReference((IAnnotationBinding)element));
				}
			}
		} else if (value instanceof IAnnotationBinding) {
			values.addUnique(createAnnotationReference((IAnnotationBinding)value));
		}
	}
	return annotationValue;
}
 
Example 2
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 3
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 4
Source File: JvmAnnotationReferenceBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(final String name, final String desc) {
	JvmAnnotationAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmAnnotationAnnotationValue();
	InternalEList<JvmAnnotationReference> nestedValues = (InternalEList<JvmAnnotationReference>) annotationValue
			.getValues();
	annotationValue.setOperation(proxies.createMethodProxy(annotationType, name));
	JvmAnnotationReferenceBuilder annotation = new JvmAnnotationReferenceBuilder(nestedValues, desc, proxies);
	values.addUnique(annotationValue);
	return annotation;
}