Search in sources :

Example 36 with JvmType

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

the class KnownTypesScope method doGetSingleElement.

@Override
protected IEObjectDescription doGetSingleElement(QualifiedName name, String firstSegment, int dollarIndex) {
    int index = -1;
    JvmType result = null;
    for (int i = 0; i < types.size(); i++) {
        JvmType type = types.get(i);
        JvmType exactMatch = getExactMatch(type, index, name);
        if (exactMatch != null)
            return EObjectDescription.create(name, exactMatch);
        if (isMatch(i, type, firstSegment, name)) {
            JvmType resolved = getUnambiguousResult(result, index, type, i, name);
            if (resolved == null) {
                return null;
            }
            if (resolved != result) {
                result = resolved;
                index = i;
            }
        }
    }
    return toDescription(name, result, dollarIndex, index);
}
Also used : JvmType(org.eclipse.xtext.common.types.JvmType)

Example 37 with JvmType

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

the class NestedTypesScope method findNestedTypeInLocalTypeNonResolving.

/**
 * We have to be careful to keep the unresolved super type of a local type which may depend on type resolution.
 * Therefore these types are treated differently from other types.
 */
protected IEObjectDescription findNestedTypeInLocalTypeNonResolving(JvmDeclaredType localType, QualifiedName name, String firstSegment, int dollarIndex) {
    List<JvmMember> members = localType.getMembers();
    for (int i = 0; i < members.size(); i++) {
        JvmMember member = members.get(i);
        if (member instanceof JvmDeclaredType) {
            JvmDeclaredType nestedType = (JvmDeclaredType) member;
            if (firstSegment.equals(nestedType.getSimpleName())) {
                JvmType candidate = findNestedType(nestedType, 0, name);
                if (candidate != null) {
                    return toDescription(name, candidate, dollarIndex, 0);
                }
            }
        }
    }
    JvmDeclaredType superType = typeScopeProvider.getSuperTypeOfLocalTypeNonResolving(localType);
    if (superType == null) {
        return null;
    }
    return doGetSingleElement(superType, name, firstSegment, dollarIndex);
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 38 with JvmType

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

the class XtendImportedNamespaceScopeProvider method getResourceTypeScope.

private AbstractScope getResourceTypeScope(Resource resource, String packageName, AbstractScope parent) {
    List<EObject> contents = resource.getContents();
    List<JvmType> knownTypes = Lists.newArrayListWithExpectedSize(contents.size() - 1);
    for (EObject content : contents) {
        if (content instanceof JvmType) {
            if (content instanceof JvmDeclaredType) {
                if (Strings.equal(packageName, ((JvmDeclaredType) content).getPackageName())) {
                    knownTypes.add((JvmType) content);
                }
            } else {
                knownTypes.add((JvmType) content);
            }
        }
    }
    if (knownTypes.isEmpty())
        return parent;
    return new KnownTypesScope(knownTypes, parent);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 39 with JvmType

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

the class XtendSerializerScopeProvider method doCreateConstructorCallSerializationScope.

@Override
protected IScope doCreateConstructorCallSerializationScope(XConstructorCall context) {
    if (context.eContainer() instanceof AnonymousClass) {
        final AnonymousClass anonymousClass = (AnonymousClass) context.eContainer();
        final JvmType superType = anonymousClassUtil.getSuperType(anonymousClass);
        if (superType != null) {
            return createAnonymousClassConstructorScope(context, superType);
        }
    }
    return super.doCreateConstructorCallSerializationScope(context);
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 40 with JvmType

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

the class XtendValidator method getParamTypes.

protected List<JvmType> getParamTypes(JvmOperation jvmOperation, boolean wrapPrimitives) {
    List<JvmType> types = newArrayList();
    for (JvmFormalParameter p : jvmOperation.getParameters()) {
        LightweightTypeReference typeReference = toLightweightTypeReference(p.getParameterType());
        if (wrapPrimitives) {
            typeReference = typeReference.getWrapperTypeIfPrimitive();
        }
        types.add(typeReference.getType());
    }
    return types;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmType(org.eclipse.xtext.common.types.JvmType)

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