org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue. 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: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void _setValue(final JvmAnnotationAnnotationValue it, final AnnotationReference[] value, final String componentType, final boolean mustBeArray) {
  this.checkType(it, componentType, mustBeArray);
  for (final AnnotationReference annotationValue : value) {
    boolean _matched = false;
    if (annotationValue instanceof JvmAnnotationReferenceImpl) {
      _matched=true;
      it.getValues().add(EcoreUtil2.<JvmAnnotationReference>cloneWithProxies(((JvmAnnotationReferenceImpl)annotationValue).getDelegate()));
    }
    if (!_matched) {
      if (annotationValue instanceof XtendAnnotationReferenceImpl) {
        _matched=true;
        throw new IllegalArgumentException("Multiple source annotations cannot be set as values. Please the the expression not the value.");
      }
    }
  }
}
 
Example #2
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 #3
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValue_02() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue(
			"annotationArrayValue");
	assertEquals(2, value.getValues().size());
	JvmAnnotationReference reference1 = value.getValues().get(0);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference1.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue1 = reference1.getValues().get(0);
	assertTrue(nestedAnnotationValue1 instanceof JvmStringAnnotationValue);
	assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue1).getValues().get(0));
	JvmAnnotationReference reference2 = value.getValues().get(1);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference2.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue2 = reference2.getValues().get(0);
	assertTrue(nestedAnnotationValue2 instanceof JvmStringAnnotationValue);
	assertEquals("MyString", ((JvmStringAnnotationValue) nestedAnnotationValue2).getValues().get(0));
}
 
Example #4
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValue_02() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue(
			"annotationArrayValue");
	assertEquals(2, value.getValues().size());
	JvmAnnotationReference reference1 = value.getValues().get(0);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference1.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue1 = reference1.getValues().get(0);
	assertTrue(nestedAnnotationValue1 instanceof JvmStringAnnotationValue);
	assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue1).getValues().get(0));
	JvmAnnotationReference reference2 = value.getValues().get(1);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference2.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue2 = reference2.getValues().get(0);
	assertTrue(nestedAnnotationValue2 instanceof JvmStringAnnotationValue);
	assertEquals("MyString", ((JvmStringAnnotationValue) nestedAnnotationValue2).getValues().get(0));
}
 
Example #5
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void recordAnnotationExpressions(List<JvmAnnotationReference> annotations) {
	for(JvmAnnotationReference annotation: annotations) {
		EObject sourceElement = getSourceElement(annotation);
		if (sourceElement != annotation) {
			rootedInstances.add(sourceElement);
		} else {
			for(JvmAnnotationValue value: annotation.getExplicitValues()) {
				if (value instanceof JvmCustomAnnotationValue) {
					JvmCustomAnnotationValue custom = (JvmCustomAnnotationValue) value;
					for(Object object: custom.getValues()) {
						if (object instanceof XExpression) {
							rootedInstances.add(sourceElement);
						}
					}
				} else if (value instanceof JvmAnnotationAnnotationValue) {
					recordAnnotationExpressions(((JvmAnnotationAnnotationValue) value).getValues());
				}
			}
		}
	}
}
 
Example #6
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void computeAnnotationTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, List<JvmAnnotationReference> annotations) {
	for(JvmAnnotationReference annotation: annotations) {
		EObject sourceElement = getSourceElement(annotation);
		if (sourceElement != annotation) {
			computeTypes(resolvedTypes, featureScopeSession, sourceElement);
		} else {
			for(JvmAnnotationValue value: annotation.getExplicitValues()) {
				if (value instanceof JvmCustomAnnotationValue) {
					JvmCustomAnnotationValue custom = (JvmCustomAnnotationValue) value;
					for(Object object: custom.getValues()) {
						if (object instanceof XExpression) {
							AnnotationValueTypeComputationState state = new AnnotationValueTypeComputationState(resolvedTypes, featureScopeSession, value, (XExpression) object);
							state.computeTypes();
						}
					}
				} else if (value instanceof JvmAnnotationAnnotationValue) {
					computeAnnotationTypes(resolvedTypes, featureScopeSession, ((JvmAnnotationAnnotationValue) value).getValues());
				}
			}
		}
	}
}
 
Example #7
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValue_02() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue(
			"annotationArrayValue");
	assertEquals(2, value.getValues().size());
	JvmAnnotationReference reference1 = value.getValues().get(0);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference1.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue1 = reference1.getValues().get(0);
	assertTrue(nestedAnnotationValue1 instanceof JvmStringAnnotationValue);
	assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue1).getValues().get(0));
	JvmAnnotationReference reference2 = value.getValues().get(1);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference2.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue2 = reference2.getValues().get(0);
	assertTrue(nestedAnnotationValue2 instanceof JvmStringAnnotationValue);
	assertEquals("MyString", ((JvmStringAnnotationValue) nestedAnnotationValue2).getValues().get(0));
}
 
Example #8
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_02() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getConstructorParameterAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #9
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValue_01() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference reference = value.getValues().get(0);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue = reference.getValues().get(0);
	assertTrue(nestedAnnotationValue instanceof JvmStringAnnotationValue);
	assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue).getValues().get(0));
}
 
Example #10
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_03() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getMethodParameterAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #11
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_02() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getConstructorParameterAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #12
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_01() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getAnnotationValue("annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #13
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;
}
 
Example #14
Source File: JvmAnnotationValueBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
	if (name != null) {
		throw new IllegalStateException();
	}
	if (result == null) {
		result = TypesFactory.eINSTANCE.createJvmAnnotationAnnotationValue();
	}
	InternalEList<JvmAnnotationReference> nestedValues = (InternalEList<JvmAnnotationReference>) ((JvmAnnotationAnnotationValue) result).getValues();
	JvmAnnotationReferenceBuilder annotation = new JvmAnnotationReferenceBuilder(nestedValues, desc, proxies);
	return annotation;
}
 
Example #15
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 #16
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 #17
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValue_01() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference reference = value.getValues().get(0);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue = reference.getValues().get(0);
	assertTrue(nestedAnnotationValue instanceof JvmStringAnnotationValue);
	assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue).getValues().get(0));
}
 
Example #18
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_03() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getMethodParameterAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #19
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_02() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getConstructorParameterAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #20
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_01() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getAnnotationValue("annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #21
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValue_01() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference reference = value.getValues().get(0);
	assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(),
			reference.getAnnotation().getIdentifier());
	JvmAnnotationValue nestedAnnotationValue = reference.getValues().get(0);
	assertTrue(nestedAnnotationValue instanceof JvmStringAnnotationValue);
	assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue).getValues().get(0));
}
 
Example #22
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_03() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getMethodParameterAnnotationValue(
			"annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #23
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotationAnnotationValue_01() throws Exception {
	JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getAnnotationValue("annotationValue");
	assertEquals(1, value.getValues().size());
	JvmAnnotationReference annotationReference = value.getValues().get(0);
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			annotationReference.getAnnotation().getIdentifier());
	assertEquals(1, annotationReference.getValues().size());
	JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0);
	assertEquals(1, nestedValue.getValues().size());
	assertEquals("MyString", nestedValue.getValues().get(0));
}
 
Example #24
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void toJavaLiteral(final JvmAnnotationValue value, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (value instanceof JvmAnnotationAnnotationValue) {
    _toJavaLiteral((JvmAnnotationAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmBooleanAnnotationValue) {
    _toJavaLiteral((JvmBooleanAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmByteAnnotationValue) {
    _toJavaLiteral((JvmByteAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmCharAnnotationValue) {
    _toJavaLiteral((JvmCharAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmCustomAnnotationValue) {
    _toJavaLiteral((JvmCustomAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmDoubleAnnotationValue) {
    _toJavaLiteral((JvmDoubleAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmEnumAnnotationValue) {
    _toJavaLiteral((JvmEnumAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmFloatAnnotationValue) {
    _toJavaLiteral((JvmFloatAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmIntAnnotationValue) {
    _toJavaLiteral((JvmIntAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmLongAnnotationValue) {
    _toJavaLiteral((JvmLongAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmShortAnnotationValue) {
    _toJavaLiteral((JvmShortAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmStringAnnotationValue) {
    _toJavaLiteral((JvmStringAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmTypeAnnotationValue) {
    _toJavaLiteral((JvmTypeAnnotationValue)value, appendable, config);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(value, appendable, config).toString());
  }
}
 
Example #25
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void _toJavaLiteral(final JvmAnnotationAnnotationValue value, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<JvmAnnotationReference> _function = (JvmAnnotationReference it) -> {
    this.generateAnnotation(it, appendable, config);
  };
  this._loopExtensions.<JvmAnnotationReference>forEachWithShortcut(appendable, value.getValues(), _function);
}
 
Example #26
Source File: SarlCompiler.java    From sarl with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"})
private static String getAnnotationStringValue(JvmAnnotationValue value) {
	if (value instanceof JvmAnnotationAnnotationValue) {
		return ((JvmAnnotationAnnotationValue) value).getValues().get(0).getAnnotation().getIdentifier();
	}
	if (value instanceof JvmBooleanAnnotationValue) {
		return ((JvmBooleanAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmByteAnnotationValue) {
		return ((JvmByteAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmCharAnnotationValue) {
		return ((JvmCharAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmCustomAnnotationValue) {
		final EObject evalue = ((JvmCustomAnnotationValue) value).getValues().get(0);
		if (evalue instanceof XStringLiteral) {
			return ((XStringLiteral) evalue).getValue();
		}
		if (evalue instanceof XNumberLiteral) {
			return ((XNumberLiteral) evalue).getValue();
		}
		if (evalue instanceof XBooleanLiteral) {
			return ((XNumberLiteral) evalue).getValue();
		}
		if (evalue instanceof XTypeLiteral) {
			return ((XTypeLiteral) evalue).getType().getIdentifier();
		}
	}
	if (value instanceof JvmDoubleAnnotationValue) {
		return ((JvmDoubleAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmEnumAnnotationValue) {
		return ((JvmEnumAnnotationValue) value).getValues().get(0).getSimpleName();
	}
	if (value instanceof JvmFloatAnnotationValue) {
		return ((JvmFloatAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmIntAnnotationValue) {
		return ((JvmIntAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmLongAnnotationValue) {
		return ((JvmLongAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmShortAnnotationValue) {
		return ((JvmShortAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmStringAnnotationValue) {
		return ((JvmStringAnnotationValue) value).getValues().get(0);
	}
	if (value instanceof JvmTypeAnnotationValue) {
		return ((JvmTypeAnnotationValue) value).getValues().get(0).getIdentifier();
	}
	return null;
}