Search in sources :

Example 1 with JvmAnnotationValue

use of org.eclipse.xtext.common.types.JvmAnnotationValue 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 : AnnotationReferenceBuildContextImpl(org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl) 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) JvmAnnotationReferenceImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 2 with JvmAnnotationValue

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

the class XtendJvmModelInferrer method initialize.

protected void initialize(XtendAnnotationType source, JvmAnnotationType inferredJvmType) {
    inferredJvmType.setVisibility(source.getVisibility());
    inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
    inferredJvmType.setAbstract(true);
    translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
    jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
    for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendField) {
            XtendField field = (XtendField) member;
            if (!Strings.isEmpty(field.getName())) {
                JvmOperation operation = typesFactory.createJvmOperation();
                associator.associatePrimary(member, operation);
                operation.setSimpleName(field.getName());
                JvmTypeReference returnType = null;
                XExpression initialValue = field.getInitialValue();
                if (field.getType() != null) {
                    returnType = jvmTypesBuilder.cloneWithProxies(field.getType());
                } else if (initialValue != null) {
                    returnType = jvmTypesBuilder.inferredType(initialValue);
                }
                operation.setReturnType(returnType);
                if (initialValue != null) {
                    JvmAnnotationValue jvmAnnotationValue = jvmTypesBuilder.toJvmAnnotationValue(initialValue);
                    if (jvmAnnotationValue != null) {
                        operation.setDefaultValue(jvmAnnotationValue);
                        jvmAnnotationValue.setOperation(operation);
                    }
                    jvmTypesBuilder.setBody(operation, initialValue);
                }
                operation.setVisibility(JvmVisibility.PUBLIC);
                translateAnnotationsTo(member.getAnnotations(), operation);
                jvmTypesBuilder.copyDocumentationTo(member, operation);
                inferredJvmType.getMembers().add(operation);
            }
        }
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 3 with JvmAnnotationValue

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

the class JvmModelTests method testEmptyListAsAnnotationValueDefault.

@Test
public void testEmptyListAsAnnotationValueDefault() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotation Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("String[] bar = #[]");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
        final JvmOperation inferred = ((JvmOperation) _head);
        Assert.assertEquals("java.lang.String[]", inferred.getReturnType().getIdentifier());
        JvmAnnotationValue _defaultValue = inferred.getDefaultValue();
        Assert.assertTrue((_defaultValue instanceof JvmCustomAnnotationValue));
        JvmAnnotationValue _defaultValue_1 = inferred.getDefaultValue();
        EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _defaultValue_1).getValues());
        Assert.assertTrue((_head_1 instanceof XListLiteral));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) XListLiteral(org.eclipse.xtext.xbase.XListLiteral) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue) Test(org.junit.Test)

Example 4 with JvmAnnotationValue

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

the class JvmModelTests method testAnnotationDefaultAssociatedWithJvmOperation.

@Test
public void testAnnotationDefaultAssociatedWithJvmOperation() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotation Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val bar = \'\'");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
        final JvmOperation inferred = ((JvmOperation) _head);
        final JvmAnnotationValue defaultValue = inferred.getDefaultValue();
        Assert.assertSame(inferred, defaultValue.getOperation());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue) Test(org.junit.Test)

Example 5 with JvmAnnotationValue

use of org.eclipse.xtext.common.types.JvmAnnotationValue 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)

Aggregations

JvmAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationValue)8 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 EObject (org.eclipse.emf.ecore.EObject)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 JvmCustomAnnotationValue (org.eclipse.xtext.common.types.JvmCustomAnnotationValue)3 XExpression (org.eclipse.xtext.xbase.XExpression)3 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)2 JvmMember (org.eclipse.xtext.common.types.JvmMember)2 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)2 Test (org.junit.Test)2 List (java.util.List)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 AnnotationReferenceBuildContextImpl (org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl)1 JvmAnnotationReferenceImpl (org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl)1 XtendField (org.eclipse.xtend.core.xtend.XtendField)1 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)1 Active (org.eclipse.xtend.lib.macro.Active)1 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)1 JvmType (org.eclipse.xtext.common.types.JvmType)1 JvmTypeAnnotationValue (org.eclipse.xtext.common.types.JvmTypeAnnotationValue)1