Search in sources :

Example 1 with JvmCustomAnnotationValue

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

the class CompilationUnitImpl method translateAnnotationValue.

public Object translateAnnotationValue(final JvmAnnotationValue value, final boolean isArray) {
    Pair<List<?>, Class<?>> _switchResult = null;
    boolean _matched = false;
    if (value instanceof JvmCustomAnnotationValue) {
        if ((((JvmCustomAnnotationValue) value).getValues().isEmpty() && isArray)) {
            _matched = true;
            List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
            Class<?> _arrayComponentType = this.toArrayComponentType(this.findExpectedType(value));
            _switchResult = Pair.<List<?>, Class<?>>of(_emptyList, _arrayComponentType);
        }
    }
    if (!_matched) {
        if (value instanceof JvmCustomAnnotationValue) {
            _matched = true;
            final JvmTypeReference expectedType = this.findExpectedType(value);
            final Function1<XExpression, Object> _function = (XExpression it) -> {
                return this.evaluate(it, expectedType);
            };
            final Object result = IterableExtensions.<Object>head(IterableExtensions.<XExpression, Object>map(Iterables.<XExpression>filter(((JvmCustomAnnotationValue) value).getValues(), XExpression.class), _function));
            return this.translateAnnotationValue(result, expectedType, isArray);
        }
    }
    if (!_matched) {
        if (value instanceof JvmTypeAnnotationValue) {
            _matched = true;
            final Function1<JvmTypeReference, TypeReference> _function = (JvmTypeReference it) -> {
                return this.toTypeReference(it);
            };
            List<TypeReference> _map = ListExtensions.<JvmTypeReference, TypeReference>map(((JvmTypeAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, TypeReference.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmAnnotationAnnotationValue) {
            _matched = true;
            final Function1<JvmAnnotationReference, AnnotationReference> _function = (JvmAnnotationReference it) -> {
                return this.toAnnotationReference(it);
            };
            List<AnnotationReference> _map = ListExtensions.<JvmAnnotationReference, AnnotationReference>map(((JvmAnnotationAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, AnnotationReference.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmStringAnnotationValue) {
            _matched = true;
            EList<String> _values = ((JvmStringAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, String.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmBooleanAnnotationValue) {
            _matched = true;
            EList<Boolean> _values = ((JvmBooleanAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, boolean.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmIntAnnotationValue) {
            _matched = true;
            EList<Integer> _values = ((JvmIntAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, int.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmByteAnnotationValue) {
            _matched = true;
            EList<Byte> _values = ((JvmByteAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, byte.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmCharAnnotationValue) {
            _matched = true;
            EList<Character> _values = ((JvmCharAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, char.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmDoubleAnnotationValue) {
            _matched = true;
            EList<Double> _values = ((JvmDoubleAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, double.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmEnumAnnotationValue) {
            _matched = true;
            final Function1<JvmEnumerationLiteral, NamedElement> _function = (JvmEnumerationLiteral it) -> {
                return this.toNamedElement(it);
            };
            List<NamedElement> _map = ListExtensions.<JvmEnumerationLiteral, NamedElement>map(((JvmEnumAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, EnumerationValueDeclaration.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmFloatAnnotationValue) {
            _matched = true;
            EList<Float> _values = ((JvmFloatAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, float.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmLongAnnotationValue) {
            _matched = true;
            EList<Long> _values = ((JvmLongAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, long.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmShortAnnotationValue) {
            _matched = true;
            EList<Short> _values = ((JvmShortAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, short.class);
        }
    }
    if (!_matched) {
        List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
        _switchResult = Pair.<List<?>, Class<?>>of(_emptyList, Object.class);
    }
    final Pair<List<?>, Class<?>> result = _switchResult;
    if (isArray) {
        return this.toArrayOfType(result.getKey(), result.getValue());
    } else {
        return IterableExtensions.head(result.getKey());
    }
}
Also used : JvmEnumAnnotationValue(org.eclipse.xtext.common.types.JvmEnumAnnotationValue) JvmByteAnnotationValue(org.eclipse.xtext.common.types.JvmByteAnnotationValue) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) JvmLongAnnotationValue(org.eclipse.xtext.common.types.JvmLongAnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) JvmStringAnnotationValue(org.eclipse.xtext.common.types.JvmStringAnnotationValue) JvmFloatAnnotationValue(org.eclipse.xtext.common.types.JvmFloatAnnotationValue) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) NamedElement(org.eclipse.xtend.lib.macro.declaration.NamedElement) EnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration) JvmTypeAnnotationValue(org.eclipse.xtext.common.types.JvmTypeAnnotationValue) JvmBooleanAnnotationValue(org.eclipse.xtext.common.types.JvmBooleanAnnotationValue) JvmIntAnnotationValue(org.eclipse.xtext.common.types.JvmIntAnnotationValue) JvmCharAnnotationValue(org.eclipse.xtext.common.types.JvmCharAnnotationValue) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmShortAnnotationValue(org.eclipse.xtext.common.types.JvmShortAnnotationValue) JvmDoubleAnnotationValue(org.eclipse.xtext.common.types.JvmDoubleAnnotationValue) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XExpression(org.eclipse.xtext.xbase.XExpression) JvmAnnotationAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue)

Example 2 with JvmCustomAnnotationValue

use of org.eclipse.xtext.common.types.JvmCustomAnnotationValue 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 3 with JvmCustomAnnotationValue

use of org.eclipse.xtext.common.types.JvmCustomAnnotationValue 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 4 with JvmCustomAnnotationValue

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

the class JvmAnnotationReferenceImpl method getExpression.

@Override
public Expression getExpression(final String property) {
    final JvmOperation op = this.findOperation(property);
    final Function1<JvmAnnotationValue, Boolean> _function = (JvmAnnotationValue it) -> {
        return Boolean.valueOf((Objects.equal(it.getOperation(), op) || ((it.getOperation() == null) && Objects.equal(op.getSimpleName(), "value"))));
    };
    final JvmAnnotationValue annotationValue = IterableExtensions.<JvmAnnotationValue>findFirst(this.getDelegate().getValues(), _function);
    boolean _matched = false;
    if (annotationValue instanceof JvmCustomAnnotationValue) {
        _matched = true;
        EObject _head = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) annotationValue).getValues());
        final XExpression expression = ((XExpression) _head);
        if (((expression != null) && this.getCompilationUnit().isBelongedToCompilationUnit(expression))) {
            return this.getCompilationUnit().toExpression(expression);
        }
    }
    return null;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)4 JvmCustomAnnotationValue (org.eclipse.xtext.common.types.JvmCustomAnnotationValue)4 JvmAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationValue)3 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)3 XExpression (org.eclipse.xtext.xbase.XExpression)3 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)2 JvmTypeAnnotationValue (org.eclipse.xtext.common.types.JvmTypeAnnotationValue)2 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 Active (org.eclipse.xtend.lib.macro.Active)1 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)1 EnumerationValueDeclaration (org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration)1 NamedElement (org.eclipse.xtend.lib.macro.declaration.NamedElement)1 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 JvmAnnotationAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue)1