Search in sources :

Example 6 with TVariable

use of org.eclipse.n4js.ts.types.TVariable 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 7 with TVariable

use of org.eclipse.n4js.ts.types.TVariable 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 8 with TVariable

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

the class VisibilityAwareIdentifiableScope method isAccepted.

@Override
protected boolean isAccepted(IEObjectDescription description) {
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance instanceof TVariable && !proxyOrInstance.eIsProxy()) {
        TVariable type = (TVariable) proxyOrInstance;
        TypeVisibility visibility = checker.isVisible(this.contextResource, type);
        if (!visibility.visibility) {
            this.accessModifierSuggestionStore.put(description.getEObjectURI().toString(), visibility.accessModifierSuggestion);
        }
        return visibility.visibility;
    }
    return super.isAccepted(description);
}
Also used : TVariable(org.eclipse.n4js.ts.types.TVariable) TypeVisibility(org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility) EObject(org.eclipse.emf.ecore.EObject)

Example 9 with TVariable

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

the class N4JSDReader method readScripts.

/**
 * Reads all N4JSD files in project and scans for types. No further information is added yet. Reads all types into a
 * map with fully qualified type name (inclusive module spec) as key, the type info only contains the types, no
 * other information yet.
 *
 * @param specInfoByName
 *            map of fqn of types or reqid keys to their corresponding spec info.
 * @throws InterruptedException
 *             thrown when user cancels the operation
 */
private void readScripts(Multimap<String, SpecInfo> specInfoByName, IN4JSProject project, ResourceSet resSet, SubMonitorMsg monitor) throws InterruptedException {
    ImmutableList<? extends IN4JSSourceContainer> srcCont = project.getSourceContainers();
    List<IN4JSSourceContainer> srcContFilter = new LinkedList<>();
    int count = 0;
    for (IN4JSSourceContainer container : srcCont) {
        if (container.isSource() || container.isTest()) {
            count += Iterables.size(container);
            srcContFilter.add(container);
        }
    }
    SubMonitorMsg sub = monitor.convert(count);
    for (IN4JSSourceContainer container : srcContFilter) {
        for (URI uri : container) {
            String ext = uri.fileExtension();
            if ("n4js".equals(ext) || "n4jsd".equals(ext)) {
                try {
                    Resource resource = resSet.getResource(uri, true);
                    if (resource != null) {
                        Script script = (Script) (resource.getContents().isEmpty() ? null : resource.getContents().get(0));
                        if (script == null) {
                            // throw new IllegalStateException("Error parsing " + uri);
                            continue;
                        }
                        N4JSResource.postProcess(resource);
                        for (Type type : getRealTopLevelTypes(script)) {
                            createTypeSpecInfo(type, specInfoByName);
                        }
                        for (TVariable tvar : script.getModule().getVariables()) {
                            createTVarSpecInfo(tvar, specInfoByName);
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    String msg = "Error processing " + uri + ": " + ex.getMessage();
                    throw new IllegalArgumentException(msg, ex);
                }
            }
            sub.worked(1);
            sub.checkCanceled();
        }
    }
}
Also used : Script(org.eclipse.n4js.n4JS.Script) TVariable(org.eclipse.n4js.ts.types.TVariable) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer) LinkedList(java.util.LinkedList) ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type)

Example 10 with TVariable

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

the class SpecModuleFile method add.

/**
 * Adds another region change entry to this file.
 */
@Override
public void add(SpecSection specElem) {
    if (!(specElem instanceof SpecIdentifiableElementSection))
        return;
    SpecIdentifiableElementSection specIE = (SpecIdentifiableElementSection) specElem;
    EObject container = specIE.idElement.eContainer();
    if (container instanceof Type) {
        addTypeElement((Type) container, specIE);
        return;
    }
    if (specIE.idElement instanceof TFunction) {
        functions.add(specIE);
        allSections.add(specIE);
        return;
    }
    if (specIE.idElement instanceof TVariable) {
        variables.add(specIE);
        allSections.add(specIE);
        return;
    }
    if (specIE.idElement instanceof Type) {
        addTypeElement((Type) specIE.idElement, specIE);
        return;
    }
    throw new RuntimeException("Missing Implementation");
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TFunction(org.eclipse.n4js.ts.types.TFunction) TVariable(org.eclipse.n4js.ts.types.TVariable) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

TVariable (org.eclipse.n4js.ts.types.TVariable)10 Type (org.eclipse.n4js.ts.types.Type)5 EObject (org.eclipse.emf.ecore.EObject)4 ContainerType (org.eclipse.n4js.ts.types.ContainerType)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 VariableDeclaration (org.eclipse.n4js.n4JS.VariableDeclaration)2 IdentifiableElement (org.eclipse.n4js.ts.types.IdentifiableElement)2 TEnumLiteral (org.eclipse.n4js.ts.types.TEnumLiteral)2 TFunction (org.eclipse.n4js.ts.types.TFunction)2 TModule (org.eclipse.n4js.ts.types.TModule)2 LinkedList (java.util.LinkedList)1 URI (org.eclipse.emf.common.util.URI)1 IdentifierRef (org.eclipse.n4js.n4JS.IdentifierRef)1 Script (org.eclipse.n4js.n4JS.Script)1 IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 TypeVisibility (org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility)1 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)1 TField (org.eclipse.n4js.ts.types.TField)1