Search in sources :

Example 61 with Type

use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.

the class N4JSResourceDescription method getImportedNames.

@Override
public Iterable<QualifiedName> getImportedNames() {
    if (null == lazyImportedNames) {
        synchronized (this) {
            if (null == lazyImportedNames) {
                // get imported names collected during global scoping
                // the scope provider registers every request in scoping so that by this
                // also all names are collected that cannot be resolved
                Iterable<QualifiedName> superImportedNames = super.getImportedNames();
                // use sorted set to ensure order of items
                final SortedSet<QualifiedName> importedNames;
                if (superImportedNames != null) {
                    importedNames = Sets.newTreeSet(superImportedNames);
                } else {
                    importedNames = Sets.<QualifiedName>newTreeSet();
                }
                // import our own module name to get a proper change notification
                Resource resource = getResource();
                List<EObject> contents = resource.getContents();
                if (contents.size() > 1) {
                    TModule module = (TModule) contents.get(1);
                    importedNames.add(qualifiedNameProvider.getFullyQualifiedName(module));
                }
                final Set<EObject> crossRefTypes = Sets.newHashSet();
                IAcceptor<EObject> acceptor = getCrossRefTypeAcceptor(crossRefTypes);
                crossReferenceComputer.computeCrossRefs(resource, acceptor);
                for (EObject type : crossRefTypes) {
                    if (type instanceof Type) {
                        handleType(importedNames, type);
                    } else if (type instanceof TVariable) {
                        handleTVariable(importedNames, (TVariable) type);
                    } else if (type instanceof TEnumLiteral) {
                        handleTEnumLiteral(importedNames, (TEnumLiteral) type);
                    }
                }
                this.lazyImportedNames = importedNames;
            }
        }
    }
    return lazyImportedNames;
}
Also used : ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) TVariable(org.eclipse.n4js.ts.types.TVariable) TEnumLiteral(org.eclipse.n4js.ts.types.TEnumLiteral) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) TModule(org.eclipse.n4js.ts.types.TModule)

Example 62 with Type

use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.

the class N4JSResourceDescription method getCrossRefTypeAcceptor.

private IAcceptor<EObject> getCrossRefTypeAcceptor(final Set<EObject> crossRefTypesAddHere) {
    IAcceptor<EObject> acceptor = new IAcceptor<EObject>() {

        @Override
        public void accept(EObject to) {
            if (to instanceof Type || to instanceof TVariable || to instanceof TEnumLiteral) {
                crossRefTypesAddHere.add(to);
            }
            // Add declared type of a field to cross ref types
            if (to instanceof TFunction) {
                TypeRef returnTypeRef = ((TFunction) to).getReturnTypeRef();
                crossRefTypesAddHere.add(returnTypeRef.getDeclaredType());
            }
            if (to instanceof TField) {
                TypeRef typeRef = ((TField) to).getTypeRef();
                crossRefTypesAddHere.add(typeRef.getDeclaredType());
            }
            // In case of TMember, add the containing type as well
            if (to instanceof TMember) {
                TMember casted = (TMember) to;
                ContainerType<?> declaringType = casted.getContainingType();
                crossRefTypesAddHere.add(declaringType);
            }
        }
    };
    return acceptor;
}
Also used : ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) TFunction(org.eclipse.n4js.ts.types.TFunction) TVariable(org.eclipse.n4js.ts.types.TVariable) TField(org.eclipse.n4js.ts.types.TField) TEnumLiteral(org.eclipse.n4js.ts.types.TEnumLiteral) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) IAcceptor(org.eclipse.xtext.util.IAcceptor) TMember(org.eclipse.n4js.ts.types.TMember)

Example 63 with Type

use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.

the class N4JSResourceDescriptionStrategy method createEObjectDescriptions.

@Override
public boolean createEObjectDescriptions(final EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
    if (getQualifiedNameProvider() == null)
        return false;
    if (eObject instanceof TModule) {
        TModule module = (TModule) eObject;
        internalCreateEObjectDescriptionForRoot(module, acceptor);
        for (Type type : module.getTopLevelTypes()) {
            internalCreateEObjectDescription(type, acceptor);
        }
        for (TVariable variable : module.getVariables()) {
            internalCreateEObjectDescription(variable, acceptor);
        }
    }
    // export is only possible for top-level elements
    return false;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TVariable(org.eclipse.n4js.ts.types.TVariable) TModule(org.eclipse.n4js.ts.types.TModule)

Example 64 with Type

use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.

the class TypeVisibilityChecker method isProjectVisible.

private boolean isProjectVisible(Resource contextResource, URI elementLocation) {
    URI moduleURI = getURI(contextResource);
    if (moduleURI.isPlatformResource() && elementLocation.isPlatformResource()) {
        // Not valid for PUBLIC_INTERNAL
        final boolean visible = moduleURI.segment(1).equals(elementLocation.segment(1));
        // TODO IDEBUG-640 this needs to be reviewed again, since the refactoring made here are invalid.
        if (visible) {
            return true;
        } else {
            if (getTestedProjects(getURI(contextResource)).isEmpty()) {
                return false;
            }
        // $FALL-THROUGH$ if the project for the context resource has a host project.
        }
    } else {
        ResourceSet resourceSet = contextResource.getResourceSet();
        EObject loadedType = resourceSet.getEObject(elementLocation, false);
        if (loadedType == null) {
            loadedType = resourceSet.getEObject(elementLocation, true);
        }
        if (loadedType instanceof Type) {
            // delegate to the *real* impl
            return isVisible(contextResource, TypeAccessModifier.PROJECT, (Type) loadedType).visibility;
        }
    }
    return false;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 65 with Type

use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method checkSpecConstructorOverrideCompatibility.

private boolean checkSpecConstructorOverrideCompatibility(TClassifier tClassifier, TMethod inheritedConstructor) {
    final Type rightThisContext = MemberRedefinitionUtils.findThisContextForConstructor(tClassifier, inheritedConstructor);
    final Result<Boolean> subtypeResult = isSubTypeResult(inheritedConstructor, rightThisContext, inheritedConstructor);
    if (subtypeResult.failed()) {
        final String msg = getMessageForCLF_PSEUDO_REDEFINED_SPEC_CTOR_INCOMPATIBLE(validatorMessageHelper.description(inheritedConstructor), validatorMessageHelper.description(tClassifier), validatorMessageHelper.description(rightThisContext));
        // ok, because tClassifier is coming from AST
        final EObject astNode = tClassifier.getAstElement();
        addIssue(msg, astNode, N4JSPackage.eINSTANCE.getN4TypeDeclaration_Name(), CLF_PSEUDO_REDEFINED_SPEC_CTOR_INCOMPATIBLE);
        return false;
    }
    return true;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) MemberType(org.eclipse.n4js.ts.types.MemberType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

Type (org.eclipse.n4js.ts.types.Type)84 ContainerType (org.eclipse.n4js.ts.types.ContainerType)32 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)28 TStructuralType (org.eclipse.n4js.ts.types.TStructuralType)26 EObject (org.eclipse.emf.ecore.EObject)21 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)21 PrimitiveType (org.eclipse.n4js.ts.types.PrimitiveType)19 AnyType (org.eclipse.n4js.ts.types.AnyType)18 UndefinedType (org.eclipse.n4js.ts.types.UndefinedType)18 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)17 NullType (org.eclipse.n4js.ts.types.NullType)17 VoidType (org.eclipse.n4js.ts.types.VoidType)17 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)16 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)16 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)16 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)16 ModuleNamespaceVirtualType (org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType)16 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)16 Result (org.eclipse.xsemantics.runtime.Result)16 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)15