Search in sources :

Example 96 with JvmTypeReference

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

the class RegisterGlobalsContextImpl method registerClass.

@Override
public void registerClass(final String qualifiedName) throws IllegalArgumentException {
    final JvmGenericType newType = TypesFactory.eINSTANCE.createJvmGenericType();
    newType.setVisibility(JvmVisibility.PUBLIC);
    EList<JvmTypeReference> _superTypes = newType.getSuperTypes();
    JvmTypeReference _typeForName = this.compilationUnit.getTypeReferences().getTypeForName(Object.class, this.compilationUnit.getXtendFile());
    _superTypes.add(_typeForName);
    this.setNameAndAccept(newType, qualifiedName);
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType)

Example 97 with JvmTypeReference

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

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

the class AnnotationReferenceBuildContextImpl method throwNotApplicable.

protected void throwNotApplicable(final JvmAnnotationValue it, final String valueType) {
    JvmTypeReference _returnType = it.getOperation().getReturnType();
    JvmType _type = null;
    if (_returnType != null) {
        _type = _returnType.getType();
    }
    String _isNotApplicableMessage = ConditionUtils.isNotApplicableMessage(valueType, this.getAnnotationValueTypeName(_type));
    throw new IllegalArgumentException(_isNotApplicableMessage);
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 99 with JvmTypeReference

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

the class AnnotationReferenceBuildContextImpl method _setValue.

protected void _setValue(final JvmAnnotationValue it, final Object value, final String componentType, final boolean mustBeArray) {
    if ((componentType == null)) {
        this.throwNotApplicable(it, value.getClass().getName());
    }
    boolean _or = false;
    if (mustBeArray) {
        _or = true;
    } else {
        JvmTypeReference _returnType = it.getOperation().getReturnType();
        JvmType _type = null;
        if (_returnType != null) {
            _type = _returnType.getType();
        }
        EClass _eClass = null;
        if (_type != null) {
            _eClass = _type.eClass();
        }
        boolean _equals = Objects.equal(_eClass, TypesPackage.Literals.JVM_ARRAY_TYPE);
        _or = _equals;
    }
    if (_or) {
        this.throwNotApplicable(it, (componentType + "[]"));
    }
    this.throwNotApplicable(it, componentType);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 100 with JvmTypeReference

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

the class AnnotationReferenceBuildContextImpl method checkType.

protected void checkType(final JvmAnnotationValue it, final String componentType, final boolean mustBeArray) {
    if ((componentType == null)) {
        return;
    }
    JvmTypeReference _returnType = it.getOperation().getReturnType();
    JvmType _type = null;
    if (_returnType != null) {
        _type = _returnType.getType();
    }
    final JvmType returnType = _type;
    boolean _or = false;
    if (mustBeArray) {
        _or = true;
    } else {
        EClass _eClass = null;
        if (returnType != null) {
            _eClass = returnType.eClass();
        }
        boolean _equals = Objects.equal(_eClass, TypesPackage.Literals.JVM_ARRAY_TYPE);
        _or = _equals;
    }
    if (_or) {
        ConditionUtils.checkTypeName(this.getAnnotationValueTypeName(returnType), (componentType + "[]"));
    } else {
        ConditionUtils.checkTypeName(this.getAnnotationValueTypeName(returnType), componentType);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)130 Test (org.junit.Test)58 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)38 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmType (org.eclipse.xtext.common.types.JvmType)28 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)23 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 XExpression (org.eclipse.xtext.xbase.XExpression)18 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 EObject (org.eclipse.emf.ecore.EObject)15 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)12 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)12 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)8