Search in sources :

Example 61 with JvmType

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

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

Example 63 with JvmType

use of org.eclipse.xtext.common.types.JvmType 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 : AnnotationReferenceBuildContextImpl(org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl) 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) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) 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 64 with JvmType

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

the class CompilationUnitImpl method toType.

public Type toType(final JvmType delegate) {
    final Function1<JvmType, Type> _function = (JvmType it) -> {
        Type _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof JvmDeclaredType) {
            _matched = true;
            _switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
        }
        if (!_matched) {
            if (delegate instanceof JvmTypeParameter) {
                _matched = true;
                _switchResult = this.toTypeParameterDeclaration(((JvmTypeParameter) delegate));
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmVoid) {
                _matched = true;
                VoidTypeImpl _voidTypeImpl = new VoidTypeImpl();
                final Procedure1<VoidTypeImpl> _function_1 = (VoidTypeImpl it_1) -> {
                    it_1.setDelegate(((JvmVoid) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<VoidTypeImpl>operator_doubleArrow(_voidTypeImpl, _function_1);
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmPrimitiveType) {
                _matched = true;
                PrimitiveTypeImpl _primitiveTypeImpl = new PrimitiveTypeImpl();
                final Procedure1<PrimitiveTypeImpl> _function_1 = (PrimitiveTypeImpl it_1) -> {
                    it_1.setDelegate(((JvmPrimitiveType) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<PrimitiveTypeImpl>operator_doubleArrow(_primitiveTypeImpl, _function_1);
            }
        }
        return _switchResult;
    };
    return this.<JvmType, Type>getOrCreate(delegate, _function);
}
Also used : PrimitiveTypeImpl(org.eclipse.xtend.core.macro.declaration.PrimitiveTypeImpl) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) JvmType(org.eclipse.xtext.common.types.JvmType) JvmComponentType(org.eclipse.xtext.common.types.JvmComponentType) JvmPrimitiveType(org.eclipse.xtext.common.types.JvmPrimitiveType) AccessorType(org.eclipse.xtend.lib.annotations.AccessorType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmVoid(org.eclipse.xtext.common.types.JvmVoid) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmPrimitiveType(org.eclipse.xtext.common.types.JvmPrimitiveType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) VoidTypeImpl(org.eclipse.xtend.core.macro.declaration.VoidTypeImpl) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 65 with JvmType

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

the class TypeLookupImpl method findTypeOnScope.

private Type findTypeOnScope(final String typeName, final Function1<? super IEObjectDescription, ? extends Boolean> filter) {
    final QualifiedName qualifiedName = this.compilationUnit.getQualifiedNameConverter().toQualifiedName(typeName);
    final IEObjectDescription result = this.compilationUnit.getScopeProvider().getScope(this.compilationUnit.getXtendFile(), XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE).getSingleElement(qualifiedName);
    if ((((result != null) && TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(result.getEClass())) && (filter.apply(result)).booleanValue())) {
        EObject _eObjectOrProxy = result.getEObjectOrProxy();
        return this.compilationUnit.toType(((JvmType) _eObjectOrProxy));
    }
    return null;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) JvmType(org.eclipse.xtext.common.types.JvmType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

JvmType (org.eclipse.xtext.common.types.JvmType)73 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)29 EObject (org.eclipse.emf.ecore.EObject)18 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)17 Test (org.junit.Test)17 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)14 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 XExpression (org.eclipse.xtext.xbase.XExpression)12 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)10 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)9 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)9 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)8 Resource (org.eclipse.emf.ecore.resource.Resource)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)6 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)6