Search in sources :

Example 41 with JvmAnnotationReference

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

the class CompilationUnitImpl method translateAnnotation.

protected AnnotationReference translateAnnotation(final XAnnotation annotation) {
    AnnotationReference _xblockexpression = null;
    {
        AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
        final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
            it.setCompilationUnit(this);
            JvmAnnotationReference _createJvmAnnotationReference = this.typesFactory.createJvmAnnotationReference();
            final Procedure1<JvmAnnotationReference> _function_1 = (JvmAnnotationReference reference) -> {
                JvmType _annotationType = annotation.getAnnotationType();
                reference.setAnnotation(((JvmAnnotationType) _annotationType));
            };
            JvmAnnotationReference _doubleArrow = ObjectExtensions.<JvmAnnotationReference>operator_doubleArrow(_createJvmAnnotationReference, _function_1);
            it.setDelegate(_doubleArrow);
        };
        final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
        EList<XAnnotationElementValuePair> _elementValuePairs = annotation.getElementValuePairs();
        for (final XAnnotationElementValuePair valuePair : _elementValuePairs) {
            {
                final XExpression value = valuePair.getValue();
                if ((value != null)) {
                    final JvmOperation operation = valuePair.getElement();
                    final Object annotationValue = this.translateAnnotationValue(value, operation.getReturnType());
                    buildContext.set(operation.getSimpleName(), annotationValue);
                }
            }
        }
        XExpression _value = annotation.getValue();
        boolean _tripleNotEquals = (_value != null);
        if (_tripleNotEquals) {
            final Object annotationValue = this.translateAnnotationValue(annotation.getValue(), null);
            buildContext.set("value", annotationValue);
        }
        _xblockexpression = this.toAnnotationReference(buildContext.getDelegate());
    }
    return _xblockexpression;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XAnnotationElementValuePair(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) XExpression(org.eclipse.xtext.xbase.XExpression) EObject(org.eclipse.emf.ecore.EObject) JvmType(org.eclipse.xtext.common.types.JvmType) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 42 with JvmAnnotationReference

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

the class CompilationUnitImpl method findExpectedType.

protected JvmTypeReference findExpectedType(final JvmAnnotationValue value) {
    JvmOperation _operation = value.getOperation();
    boolean _tripleNotEquals = (_operation != null);
    if (_tripleNotEquals) {
        return value.getOperation().getReturnType();
    }
    JvmTypeReference _switchResult = null;
    EObject _eContainer = value.eContainer();
    final EObject container = _eContainer;
    boolean _matched = false;
    if (container instanceof JvmOperation) {
        _matched = true;
        _switchResult = ((JvmOperation) container).getReturnType();
    }
    if (!_matched) {
        if (container instanceof JvmAnnotationReference) {
            _matched = true;
            JvmTypeReference _xblockexpression = null;
            {
                final JvmOperation defaultOp = IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(((JvmAnnotationReference) container).getAnnotation().findAllFeaturesByName("value"), JvmOperation.class));
                JvmTypeReference _xifexpression = null;
                if ((defaultOp != null)) {
                    _xifexpression = defaultOp.getReturnType();
                }
                _xblockexpression = _xifexpression;
            }
            _switchResult = _xblockexpression;
        }
    }
    return _switchResult;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 43 with JvmAnnotationReference

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

the class XAnnotationExtensions method getProcessorType.

public JvmType getProcessorType(final JvmAnnotationType it) {
    final Function1<JvmAnnotationReference, Boolean> _function = (JvmAnnotationReference it_1) -> {
        JvmAnnotationType _annotation = it_1.getAnnotation();
        String _identifier = null;
        if (_annotation != null) {
            _identifier = _annotation.getIdentifier();
        }
        String _name = Active.class.getName();
        return Boolean.valueOf(Objects.equal(_identifier, _name));
    };
    final JvmAnnotationReference activeAnnotation = IterableExtensions.<JvmAnnotationReference>findFirst(it.getAnnotations(), _function);
    final Function1<JvmAnnotationValue, Boolean> _function_1 = (JvmAnnotationValue it_1) -> {
        return Boolean.valueOf(((it_1.getOperation() == null) || Objects.equal(it_1.getOperation().getSimpleName(), "value")));
    };
    final JvmAnnotationValue annoVal = IterableExtensions.<JvmAnnotationValue>findFirst(activeAnnotation.getValues(), _function_1);
    boolean _matched = false;
    if (annoVal instanceof JvmTypeAnnotationValue) {
        _matched = true;
        JvmTypeReference _head = IterableExtensions.<JvmTypeReference>head(((JvmTypeAnnotationValue) annoVal).getValues());
        JvmType _type = null;
        if (_head != null) {
            _type = _head.getType();
        }
        return _type;
    }
    if (!_matched) {
        if (annoVal instanceof JvmCustomAnnotationValue) {
            _matched = true;
            EObject _head = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) annoVal).getValues());
            JvmOperation _operation = ((JvmCustomAnnotationValue) annoVal).getOperation();
            JvmTypeReference _returnType = null;
            if (_operation != null) {
                _returnType = _operation.getReturnType();
            }
            final Object type = this.constantExpressionsInterpreter.evaluate(((XExpression) _head), _returnType);
            if ((type instanceof JvmTypeReference)) {
                return ((JvmTypeReference) type).getType();
            }
        }
    }
    return null;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmTypeAnnotationValue(org.eclipse.xtext.common.types.JvmTypeAnnotationValue) JvmType(org.eclipse.xtext.common.types.JvmType) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) Active(org.eclipse.xtend.lib.macro.Active) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 44 with JvmAnnotationReference

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

the class AnnotationReferenceProviderImpl method createJvmAnnotationReference.

protected JvmAnnotationReference createJvmAnnotationReference(final JvmType type) {
    JvmAnnotationReference _switchResult = null;
    boolean _matched = false;
    if (type instanceof JvmAnnotationType) {
        _matched = true;
        JvmAnnotationReference _createJvmAnnotationReference = TypesFactory.eINSTANCE.createJvmAnnotationReference();
        final Procedure1<JvmAnnotationReference> _function = (JvmAnnotationReference it) -> {
            it.setAnnotation(((JvmAnnotationType) type));
        };
        _switchResult = ObjectExtensions.<JvmAnnotationReference>operator_doubleArrow(_createJvmAnnotationReference, _function);
    }
    if (!_matched) {
        _switchResult = null;
    }
    return _switchResult;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 45 with JvmAnnotationReference

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

the class XtendJvmModelInferrer method transform.

protected void transform(XtendEnumLiteral literal, JvmEnumerationType container) {
    if (literal.getName() == null)
        return;
    JvmEnumerationLiteral jvmLiteral = typesFactory.createJvmEnumerationLiteral();
    associator.associatePrimary(literal, jvmLiteral);
    jvmLiteral.setSimpleName(literal.getName());
    jvmLiteral.setVisibility(JvmVisibility.PUBLIC);
    jvmLiteral.setStatic(true);
    jvmLiteral.setFinal(true);
    jvmTypesBuilder.copyDocumentationTo(literal, jvmLiteral);
    for (XAnnotation anno : literal.getAnnotations()) {
        if (!annotationTranslationFilter.apply(anno))
            continue;
        JvmAnnotationReference annotationReference = jvmTypesBuilder.getJvmAnnotationReference(anno);
        if (annotationReference != null)
            jvmLiteral.getAnnotations().add(annotationReference);
    }
    container.getMembers().add(jvmLiteral);
}
Also used : JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) 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