use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testAnnotationAnnotationValue_02.
@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));
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testDefaultAnnotationAnnotationValue_02.
@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));
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createFormalParameter.
protected JvmFormalParameter createFormalParameter(ITypeBinding parameterType, String paramName, IAnnotationBinding[] annotations) {
JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter();
if (paramName != null)
result.setName(paramName);
result.setParameterType(createTypeReference(parameterType));
if (annotations != null && annotations.length > 0) {
InternalEList<JvmAnnotationReference> parameterAnnotations = (InternalEList<JvmAnnotationReference>) result.getAnnotations();
for (IAnnotationBinding annotation : annotations) {
parameterAnnotations.addUnique(createAnnotationReference(annotation));
}
}
return result;
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createAnnotationValues.
protected void createAnnotationValues(IBinding annotated, JvmAnnotationTarget result) {
try {
resolveAnnotations.start();
IAnnotationBinding[] annotationBindings = annotated.getAnnotations();
if (annotationBindings.length != 0) {
InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>) result.getAnnotations();
for (IAnnotationBinding annotation : annotationBindings) {
annotations.addUnique(createAnnotationReference(annotation));
}
}
} catch (AbortCompilation aborted) {
if (aborted.problem.getID() == IProblem.IsClassPathCorrect) {
// ignore
} else {
log.info("Couldn't resolve annotations of " + annotated, aborted);
}
} finally {
resolveAnnotations.stop();
}
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-xtend by eclipse.
the class AnnotationReferenceBuildContextImpl method _setValue.
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.");
}
}
}
}
Aggregations