Search in sources :

Example 21 with JvmAnnotationType

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

the class ConstantExpressionsInterpreter method getJavaType.

protected Class<?> getJavaType(final JvmType type, final ClassFinder classFinder) throws ClassNotFoundException {
    if ((type instanceof JvmArrayType)) {
        JvmType t = type;
        String dimensions = "";
        while ((t instanceof JvmArrayType)) {
            {
                dimensions = (dimensions + "[]");
                t = ((JvmArrayType) t).getComponentType();
            }
        }
        final Class<?> componentClass = this.getJavaType(t, classFinder);
        String _name = componentClass.getName();
        String _plus = (_name + dimensions);
        return classFinder.forName(_plus);
    }
    String _identifier = type.getIdentifier();
    boolean _equals = Objects.equal(_identifier, "java.lang.Class");
    if (_equals) {
        return JvmTypeReference.class;
    }
    if ((type instanceof JvmEnumerationType)) {
        return JvmEnumerationLiteral.class;
    }
    if ((type instanceof JvmAnnotationType)) {
        return XAnnotation.class;
    }
    return classFinder.forName(type.getIdentifier());
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmType(org.eclipse.xtext.common.types.JvmType) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType)

Example 22 with JvmAnnotationType

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

the class XAnnotationExtensions method tryFindAnnotationType.

public JvmAnnotationType tryFindAnnotationType(final XAnnotation it) {
    Object _eGet = it.eGet(XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false);
    final Object proxy = _eGet;
    boolean _matched = false;
    if (proxy instanceof EObject) {
        boolean _eIsProxy = ((EObject) proxy).eIsProxy();
        if (_eIsProxy) {
            _matched = true;
            final URI uri = ((InternalEObject) proxy).eProxyURI();
            EObject _eObject = it.eResource().getResourceSet().getEObject(uri, true);
            return ((JvmAnnotationType) _eObject);
        }
    }
    if (!_matched) {
        if (proxy instanceof JvmAnnotationType) {
            _matched = true;
            return ((JvmAnnotationType) proxy);
        }
    }
    return null;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) URI(org.eclipse.emf.common.util.URI) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 23 with JvmAnnotationType

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

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

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

the class JvmAnnotationReferenceImpl method findOperation.

private JvmOperation findOperation(final String name) {
    ConditionUtils.checkJavaIdentifier(name, "name");
    AnnotationTypeDeclaration _annotationTypeDeclaration = this.getAnnotationTypeDeclaration();
    final JvmAnnotationType jvmAnnoType = ((JvmAnnotationTypeDeclarationImpl) _annotationTypeDeclaration).getDelegate();
    final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
        String _simpleName = it.getSimpleName();
        return Boolean.valueOf(Objects.equal(_simpleName, name));
    };
    final JvmOperation jvmOperation = IterableExtensions.<JvmOperation>findFirst(jvmAnnoType.getDeclaredOperations(), _function);
    if ((jvmOperation == null)) {
        String _identifier = jvmAnnoType.getIdentifier();
        String _plus = ((("The annotation property \'" + name) + "\' is not declared on the annotation type \'") + _identifier);
        String _plus_1 = (_plus + "\'.");
        throw new IllegalArgumentException(_plus_1);
    }
    return jvmOperation;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration)

Aggregations

JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)26 JvmType (org.eclipse.xtext.common.types.JvmType)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)6 EObject (org.eclipse.emf.ecore.EObject)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)4 JvmMember (org.eclipse.xtext.common.types.JvmMember)4 Test (org.junit.Test)4 InternalEObject (org.eclipse.emf.ecore.InternalEObject)3 JvmAnnotationTypeDeclarationImpl (org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl)3 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)3 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)3 URI (org.eclipse.emf.common.util.URI)2 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)2 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)2