Search in sources :

Example 16 with JvmAnnotationReference

use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-xtend by eclipse.

the class XAnnotationExtensions method isActiveAnnotation.

protected boolean isActiveAnnotation(final JvmAnnotationType annotationType) {
    EList<JvmAnnotationReference> _annotations = annotationType.getAnnotations();
    for (final JvmAnnotationReference anno : _annotations) {
        String _identifier = anno.getAnnotation().getIdentifier();
        String _name = Active.class.getName();
        boolean _equals = Objects.equal(_identifier, _name);
        if (_equals) {
            return true;
        }
    }
    return false;
}
Also used : JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 17 with JvmAnnotationReference

use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-xtend by eclipse.

the class AnnotationReferenceProviderImpl method newAnnotationReference.

@Override
public AnnotationReference newAnnotationReference(final String annotationTypeName, final Procedure1<AnnotationReferenceBuildContext> initializer) {
    AnnotationReference _xblockexpression = null;
    {
        this.compilationUnit.checkCanceled();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotationTypeName cannot be null");
        Preconditions.checkArgument((annotationTypeName != null), _builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("initializer cannot be null");
        Preconditions.checkArgument((initializer != null), _builder_1);
        final JvmAnnotationReference jvmAnnotationReference = this.createJvmAnnotationReference(this.compilationUnit.getTypeReferences().findDeclaredType(annotationTypeName, this.compilationUnit.getXtendFile()));
        if ((jvmAnnotationReference == null)) {
            return null;
        }
        AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
        final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
            it.setDelegate(jvmAnnotationReference);
            it.setCompilationUnit(this.compilationUnit);
        };
        final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
        initializer.apply(buildContext);
        _xblockexpression = this.compilationUnit.toAnnotationReference(jvmAnnotationReference);
    }
    return _xblockexpression;
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 18 with JvmAnnotationReference

use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-xtend by eclipse.

the class AnnotationReferenceProviderImpl method newAnnotationReference.

@Override
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
    Object _xblockexpression = null;
    {
        this.compilationUnit.checkCanceled();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotationTypeDelcaration cannot be null");
        Preconditions.checkArgument((annotationTypeDelcaration != null), _builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("initializer cannot be null");
        Preconditions.checkArgument((initializer != null), _builder_1);
        JvmDeclaredType _switchResult = null;
        boolean _matched = false;
        if (annotationTypeDelcaration instanceof JvmAnnotationTypeDeclarationImpl) {
            _matched = true;
            _switchResult = ((JvmAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate();
        }
        if (!_matched) {
            if (annotationTypeDelcaration instanceof XtendAnnotationTypeDeclarationImpl) {
                _matched = true;
                _switchResult = this.compilationUnit.getJvmModelAssociations().getInferredType(((XtendAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate());
            }
        }
        if (!_matched) {
            throw new IllegalArgumentException(("couldn\'t construct type reference for type " + annotationTypeDelcaration));
        }
        final JvmDeclaredType type = _switchResult;
        if ((type instanceof JvmAnnotationType)) {
            final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(type);
            AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
            final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
                it.setDelegate(newJvmAnnotationReference);
                it.setCompilationUnit(this.compilationUnit);
            };
            final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
            initializer.apply(buildContext);
            return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
        }
        _xblockexpression = null;
    }
    return ((AnnotationReference) _xblockexpression);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 19 with JvmAnnotationReference

use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-xtend by eclipse.

the class AnnotationReferenceProviderImpl method newAnnotationReference.

@Override
public AnnotationReference newAnnotationReference(final AnnotationReference annotationReference, final Procedure1<AnnotationReferenceBuildContext> initializer) {
    Object _xblockexpression = null;
    {
        this.compilationUnit.checkCanceled();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotationReference cannot be null");
        Preconditions.checkArgument((annotationReference != null), _builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("initializer cannot be null");
        Preconditions.checkArgument((initializer != null), _builder_1);
        if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
            final JvmAnnotationReference baseJvmAnnotationReference = ((JvmAnnotationReferenceImpl) annotationReference).getDelegate();
            ConditionUtils.notRemoved(baseJvmAnnotationReference, "annotationReference");
            final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(baseJvmAnnotationReference.getAnnotation());
            AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
            final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
                it.setDelegate(newJvmAnnotationReference);
                it.setCompilationUnit(this.compilationUnit);
            };
            final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
            final Function1<JvmAnnotationValue, String> _function_1 = (JvmAnnotationValue it) -> {
                String _elvis = null;
                String _valueName = it.getValueName();
                if (_valueName != null) {
                    _elvis = _valueName;
                } else {
                    _elvis = "value";
                }
                return _elvis;
            };
            List<String> _map = ListExtensions.<JvmAnnotationValue, String>map(baseJvmAnnotationReference.getExplicitValues(), _function_1);
            for (final String valueName : _map) {
                {
                    final Object value = ((JvmAnnotationReferenceImpl) annotationReference).getValue(valueName);
                    buildContext.set(valueName, value);
                }
            }
            initializer.apply(buildContext);
            return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
        }
        _xblockexpression = null;
    }
    return ((AnnotationReference) _xblockexpression);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 20 with JvmAnnotationReference

use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-xtend by eclipse.

the class JvmAnnotationTargetImpl method addAnnotation.

public AnnotationReference addAnnotation(final AnnotationReference annotationReference) {
    AnnotationReference _xblockexpression = null;
    {
        this.checkMutable();
        Preconditions.checkArgument((annotationReference != null), "annotationReference cannot be null");
        AnnotationReference _xifexpression = null;
        if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
            AnnotationReference _xblockexpression_1 = null;
            {
                final JvmAnnotationReference jvmAnnotationReference = EcoreUtil2.<JvmAnnotationReference>cloneWithProxies(((JvmAnnotationReferenceImpl) annotationReference).getDelegate());
                EList<JvmAnnotationReference> _annotations = this.getDelegate().getAnnotations();
                _annotations.add(jvmAnnotationReference);
                _xblockexpression_1 = this.getCompilationUnit().toAnnotationReference(jvmAnnotationReference);
            }
            _xifexpression = _xblockexpression_1;
        } else {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append(annotationReference);
            _builder.append(" is not annotation reference");
            throw new IllegalArgumentException(_builder.toString());
        }
        _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

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