Search in sources :

Example 16 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ActiveAnnotationContextProvider method registerMacroAnnotations.

private void registerMacroAnnotations(final XtendAnnotationTarget candidate, final IAcceptor<Pair<JvmAnnotationType, XAnnotation>> acceptor) {
    final Function1<XAnnotation, Boolean> _function = (XAnnotation it) -> {
        return Boolean.valueOf(this._xAnnotationExtensions.isProcessed(it));
    };
    Iterable<XAnnotation> _filter = IterableExtensions.<XAnnotation>filter(candidate.getAnnotations(), _function);
    for (final XAnnotation annotation : _filter) {
        {
            final JvmAnnotationType activeAnnotationDeclaration = this._xAnnotationExtensions.tryFindAnnotationType(annotation);
            if ((activeAnnotationDeclaration != null)) {
                boolean _isValid = this.isValid(annotation, activeAnnotationDeclaration);
                if (_isValid) {
                    Pair<JvmAnnotationType, XAnnotation> _mappedTo = Pair.<JvmAnnotationType, XAnnotation>of(activeAnnotationDeclaration, annotation);
                    acceptor.accept(_mappedTo);
                }
            }
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 17 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreterTest method testAnnotationValues.

@Test
public void testAnnotationValues() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("@test.Annotation(annotation2Value=@test.Annotation2(\'foo\'))");
        _builder.newLine();
        _builder.append("class C { ");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final XAnnotationElementValuePair pair = IterableExtensions.<XAnnotationElementValuePair>head(IterableExtensions.<XAnnotation>head(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getAnnotations()).getElementValuePairs());
        Object _evaluate = this.interpreter.evaluate(pair.getValue(), pair.getElement().getReturnType());
        final XAnnotation anno = ((XAnnotation) _evaluate);
        Assert.assertEquals("test.Annotation2", anno.getAnnotationType().getIdentifier());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XAnnotationElementValuePair(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 18 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_008.

@Test
public void testErrorModel_008() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotation Bar { @");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration typeDeclaration = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
    final EList<XAnnotation> annotations = IterableExtensions.<XtendMember>last(typeDeclaration.getMembers()).getAnnotations();
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
    Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Example 19 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_003.

@Test
public void testErrorModel_003() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class TestXtend {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val static int a = 4");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Click(#[ a, a ])");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("d");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    final XtendClass clazz = ((XtendClass) _head);
    final XtendMember lastMember = IterableExtensions.<XtendMember>last(clazz.getMembers());
    final EList<XAnnotation> annotations = lastMember.getAnnotations();
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
    Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Example 20 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_009.

@Test
public void testErrorModel_009() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class X {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Property val S");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration typeDeclaration = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
    final EList<XAnnotation> annotations = IterableExtensions.<XtendMember>last(typeDeclaration.getMembers()).getAnnotations();
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
    Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Aggregations

XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)24 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)13 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 Test (org.junit.Test)12 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)11 EObject (org.eclipse.emf.ecore.EObject)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)4 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)4 XtendAnnotationTarget (org.eclipse.xtend.core.xtend.XtendAnnotationTarget)3 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)3 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)2 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)2 EObjectDiagnosticImpl (org.eclipse.xtext.validation.EObjectDiagnosticImpl)2 Pair (org.eclipse.xtext.xbase.lib.Pair)2 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1