Search in sources :

Example 41 with JvmDeclaredType

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

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

the class XtendImportedNamespaceScopeProvider method doGetAllDescriptions.

private void doGetAllDescriptions(JvmDeclaredType type, List<IEObjectDescription> descriptions) {
    descriptions.add(EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(type.getIdentifier()), type));
    EList<JvmMember> members = null;
    if (type instanceof JvmDeclaredTypeImplCustom) {
        members = ((JvmDeclaredTypeImplCustom) type).basicGetMembers();
    } else {
        members = type.getMembers();
    }
    for (JvmMember member : members) {
        if (member instanceof JvmDeclaredType) {
            // add nested types also with the dot delimiter
            descriptions.add(EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(member.getQualifiedName('.')), member));
            doGetAllDescriptions((JvmDeclaredType) member, descriptions);
        }
    }
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmDeclaredTypeImplCustom(org.eclipse.xtext.common.types.impl.JvmDeclaredTypeImplCustom)

Example 43 with JvmDeclaredType

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

the class XtendReentrantTypeResolver method doPrepareLocalTypes.

protected void doPrepareLocalTypes(final ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmFeature container, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    List<JvmGenericType> localClasses = container.getLocalClasses();
    for (final JvmGenericType localClass : localClasses) {
        JvmTypeReference superType = localClass.getSuperTypes().get(0);
        final IFeatureScopeSession nestedSession = featureScopeSession;
        if (InferredTypeIndicator.isInferred(superType)) {
            final XComputedTypeReference casted = (XComputedTypeReference) superType;
            InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
            final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression();
            XConstructorCall constructorCall = anonymousClass.getConstructorCall();
            IScope typeScope = featureScopeSession.getScope(constructorCall, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
            final JvmDeclaredType type = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
            if (type == null) {
                JvmUnknownTypeReference superTypeReference = TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        inferAnonymousClassConstructor(anonymousClass, localClass);
                    }
                });
            } else {
                final JvmParameterizedTypeReference superTypeReference = createSuperTypeReference(type, constructorCall);
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    @SuppressWarnings("deprecation")
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        IFeatureScopeSession mySession = addThisAndSuper(nestedSession, resolvedTypes.getReferenceOwner(), localClass, superTypeReference, false);
                        if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) type).isInterface()) {
                            localClass.getSuperTypes().add(0, typesBuilder.newTypeRef(localClass, Object.class));
                            inferAnonymousClassConstructor(anonymousClass, localClass);
                        } else {
                            for (JvmMember superMember : type.getMembers()) {
                                if (superMember instanceof JvmConstructor) {
                                    JvmConstructor superTypeConstructor = (JvmConstructor) superMember;
                                    boolean visible = mySession.isVisible(superTypeConstructor);
                                    inferAnonymousClassConstructor(anonymousClass, localClass, superTypeConstructor, visible);
                                }
                            }
                        }
                    }
                });
            }
        }
    }
}
Also used : IFeatureScopeSession(org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmUnknownTypeReference(org.eclipse.xtext.common.types.JvmUnknownTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) InferredTypeIndicator(org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) IScope(org.eclipse.xtext.scoping.IScope) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 44 with JvmDeclaredType

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

the class XtendValidator method contributesToConflict.

/**
 * Determine whether the given type contributes to the conflict caused by the given default interface implementation.
 */
private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) {
    Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet();
    involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType());
    for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) {
        involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType());
    }
    RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>();
    if (rootType.isInterface()) {
        int contributingCount = 0;
        for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) {
            JvmType rawType = typeRef.getType();
            if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) {
                contributingCount++;
            }
        }
        return contributingCount >= 2;
    } else {
        return contributesToConflict(rootType, involvedInterfaces, recursionGuard);
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) RecursionGuard(org.eclipse.xtext.xbase.typesystem.util.RecursionGuard) JvmType(org.eclipse.xtext.common.types.JvmType) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)

Example 45 with JvmDeclaredType

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

the class XtendValidator method hasCycleInHierarchy.

protected boolean hasCycleInHierarchy(JvmGenericType type, Set<JvmGenericType> processedSuperTypes) {
    JvmDeclaredType container = type;
    do {
        if (processedSuperTypes.contains(container))
            return true;
        container = container.getDeclaringType();
    } while (container != null);
    processedSuperTypes.add(type);
    for (JvmTypeReference superTypeRef : type.getSuperTypes()) {
        if (superTypeRef.getType() instanceof JvmGenericType) {
            if (hasCycleInHierarchy((JvmGenericType) superTypeRef.getType(), processedSuperTypes))
                return true;
        }
    }
    processedSuperTypes.remove(type);
    return false;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)74 EObject (org.eclipse.emf.ecore.EObject)21 JvmType (org.eclipse.xtext.common.types.JvmType)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 Test (org.junit.Test)8 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)7 Resource (org.eclipse.emf.ecore.resource.Resource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 XExpression (org.eclipse.xtext.xbase.XExpression)5 List (java.util.List)4 EList (org.eclipse.emf.common.util.EList)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4