Search in sources :

Example 36 with JvmAnnotationReference

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));
}
Also used : JvmAnnotationAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue) JvmStringAnnotationValue(org.eclipse.xtext.common.types.JvmStringAnnotationValue) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) Test(org.junit.Test)

Example 37 with JvmAnnotationReference

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));
}
Also used : JvmAnnotationAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue) JvmStringAnnotationValue(org.eclipse.xtext.common.types.JvmStringAnnotationValue) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue) Test(org.junit.Test)

Example 38 with JvmAnnotationReference

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;
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 39 with JvmAnnotationReference

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();
    }
}
Also used : IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) AbortCompilation(org.eclipse.jdt.internal.compiler.problem.AbortCompilation) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 40 with JvmAnnotationReference

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.");
            }
        }
    }
}
Also used : JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference)

Aggregations

JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)47 Test (org.junit.Test)23 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)15 JvmAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationValue)11 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)9 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 JvmAnnotationAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue)6 JvmAnnotationTarget (org.eclipse.xtext.common.types.JvmAnnotationTarget)6 JvmTypeAnnotationValue (org.eclipse.xtext.common.types.JvmTypeAnnotationValue)6 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)6 EObject (org.eclipse.emf.ecore.EObject)5 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmStringAnnotationValue (org.eclipse.xtext.common.types.JvmStringAnnotationValue)5 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 TestAnnotation (org.eclipse.xtext.common.types.testSetups.TestAnnotation)4 TestAnnotationWithStringDefault (org.eclipse.xtext.common.types.testSetups.TestAnnotationWithStringDefault)4 Extension (org.eclipse.xtext.xbase.lib.Extension)4 IFile (org.eclipse.core.resources.IFile)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3