Search in sources :

Example 16 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.

the class StaticPolyfillHelper method findStaticPolyfiller.

/**
 * Find the corresponding static-polyfill to this {@code @@PolyfillAware} resource in the same project. returns null
 * if not found or this resource has no {@code @@PolyfillAware} annotation.
 */
public URI findStaticPolyfiller(Resource resource) {
    // ensure right resource
    if (resource instanceof N4JSResource) {
        final N4JSResource res = (N4JSResource) resource;
        if (!isContainedInStaticPolyfillAware(res.getScript()))
            return null;
        final QualifiedName qnFilled = qualifiedNameConverter.toQualifiedName(res.getModule().getQualifiedName());
        final IN4JSProject project = projectResolver.resolveProject(res.getURI());
        final QualifiedName fqn = qnFilled;
        // see Req.155#4: "Both
        final Optional<String> fileExtension = Optional.of(res.getURI().fileExtension());
        // extensions are
        // equal."
        final IN4JSSourceContainer filledSrcContainer = n4jsCore.findN4JSSourceContainer(res.getURI()).get();
        for (IN4JSSourceContainer srcConti : project.getSourceContainers()) {
            if (!Objects.equals(filledSrcContainer, srcConti)) {
                final URI uri = srcConti.findArtifact(fqn, fileExtension);
                if (uri != null) {
                    return uri;
                }
            }
        }
    }
    return null;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) N4JSResource(org.eclipse.n4js.resource.N4JSResource) URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 17 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer 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 18 with IN4JSSourceContainer

use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.

the class N4JSDReader method getTestTypes.

private List<Type> getTestTypes(IN4JSProject project, ResourceSet resSet, SubMonitorMsg monitor) throws InterruptedException {
    List<Type> testTypes = new ArrayList<>();
    ImmutableList<? extends IN4JSSourceContainer> srcCont = project.getSourceContainers();
    // count container
    int count = 0;
    for (IN4JSSourceContainer container : srcCont) {
        if (container.isTest()) {
            count += Iterables.size(container);
        }
    }
    SubMonitorMsg sub = monitor.convert(count);
    // scan for types
    for (IN4JSSourceContainer container : srcCont) {
        if (container.isTest()) {
            for (URI uri : container) {
                String ext = uri.fileExtension();
                if ("n4js".equals(ext)) {
                    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);
                        }
                        N4JSResource.postProcess(resource);
                        for (Type type : getRealTopLevelTypes(script)) {
                            testTypes.add(type);
                        }
                    }
                }
                sub.worked(1);
                sub.checkCanceled();
            }
        }
    }
    return testTypes;
}
Also used : Script(org.eclipse.n4js.n4JS.Script) ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) ArrayList(java.util.ArrayList) 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)

Aggregations

IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)18 URI (org.eclipse.emf.common.util.URI)15 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)9 N4JSResource (org.eclipse.n4js.resource.N4JSResource)5 LinkedList (java.util.LinkedList)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 ImmutableList (com.google.common.collect.ImmutableList)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 Optional (com.google.common.base.Optional)2 HashMultimap (com.google.common.collect.HashMultimap)2 Inject (com.google.inject.Inject)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Script (org.eclipse.n4js.n4JS.Script)2 ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)2