Search in sources :

Example 6 with N4JSSourceFolderSnapshot

use of org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot in project n4js by eclipse.

the class MockWorkspaceSupplier method createProjectConfig.

/**
 * See {@link #createWorkspaceConfig()}.
 */
protected N4JSProjectConfigSnapshot createProjectConfig() {
    // try to load a test package.json from disk, otherwise create a project configuration from default values
    Pair<FileURI, ProjectDescription> loadedOrCreated = loadProjectDescription().or(this::createProjectDescription);
    FileURI projectPath = loadedOrCreated.getKey();
    ProjectDescription pd = loadedOrCreated.getValue();
    List<N4JSSourceFolderSnapshot> sourceFolders = createSourceFolders(projectPath, pd);
    return new N4JSProjectConfigSnapshot(pd, projectPath.withTrailingPathDelimiter().toURI(), false, true, Collections.emptyList(), sourceFolders, Map.of());
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 7 with N4JSSourceFolderSnapshot

use of org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot in project n4js by eclipse.

the class ProjectSetTest method createProjectConfig.

private N4JSProjectConfigSnapshot createProjectConfig(URI path) {
    String name = ProjectDescriptionUtils.deriveN4JSPackageNameFromURI(path);
    ProjectDescription pd = ProjectDescription.builder().setPackageName(name).setType(ProjectType.LIBRARY).setVersion(SemverUtils.createVersionNumber(0, 0, 1)).build();
    N4JSSourceFolderSnapshot srcFolder = new N4JSSourceFolderSnapshot("src", path.appendSegment("src"), SourceContainerType.SOURCE, "src");
    return new N4JSProjectConfigSnapshot(pd, path, false, true, Collections.emptyList(), Collections.singleton(srcFolder), Map.of());
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 8 with N4JSSourceFolderSnapshot

use of org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot in project n4js by eclipse.

the class N4JSDReader method getTestTypes.

private List<Type> getTestTypes(N4JSProjectConfigSnapshot project, ResourceSet resSet, SubMonitorMsg monitor) throws InterruptedException {
    List<Type> testTypes = new ArrayList<>();
    ImmutableSet<? extends N4JSSourceFolderSnapshot> srcCont = project.getSourceFolders();
    // count container
    int count = 0;
    for (N4JSSourceFolderSnapshot container : srcCont) {
        if (container.isTest()) {
            count += Iterables.size(container.getContents());
        }
    }
    SubMonitorMsg sub = monitor.convert(count);
    // scan for types
    for (N4JSSourceFolderSnapshot container : srcCont) {
        if (container.isTest()) {
            for (URI uri : container.getContents()) {
                String ext = URIUtils.fileExtension(uri);
                if (N4JSGlobals.N4JS_FILE_EXTENSION.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) Type(org.eclipse.n4js.ts.types.Type) ArrayList(java.util.ArrayList) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 9 with N4JSSourceFolderSnapshot

use of org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot 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 specInfosByName
 *            map of fqn of types or reqid keys to their corresponding spec info.
 * @throws InterruptedException
 *             thrown when user cancels the operation
 */
private void readScripts(SpecInfosByName specInfosByName, N4JSProjectConfigSnapshot project, ResourceSet resSet, SubMonitorMsg monitor) throws InterruptedException {
    ImmutableSet<? extends N4JSSourceFolderSnapshot> srcCont = project.getSourceFolders();
    List<N4JSSourceFolderSnapshot> srcContFilter = new LinkedList<>();
    int count = 0;
    for (N4JSSourceFolderSnapshot container : srcCont) {
        if (container.isSource() || container.isTest()) {
            count += Iterables.size(container.getContents());
            srcContFilter.add(container);
        }
    }
    SubMonitorMsg sub = monitor.convert(count);
    for (N4JSSourceFolderSnapshot container : srcContFilter) {
        for (URI uri : container.getContents()) {
            String ext = URIUtils.fileExtension(uri);
            if (N4JSGlobals.N4JS_FILE_EXTENSION.equals(ext) || N4JSGlobals.N4JSD_FILE_EXTENSION.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)) {
                            specInfosByName.createTypeSpecInfo(type, rrph);
                        }
                        for (TVariable tvar : script.getModule().getVariables()) {
                            specInfosByName.createTVarSpecInfo(tvar, rrph);
                        }
                    }
                } 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) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) FileURI(org.eclipse.n4js.workspace.locations.FileURI) LinkedList(java.util.LinkedList) Type(org.eclipse.n4js.ts.types.Type)

Example 10 with N4JSSourceFolderSnapshot

use of org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot in project n4js by eclipse.

the class ProjectCompareHelper method createEntries.

// may be made public later
private ProjectComparisonEntry createEntries(ProjectComparison root, N4JSProjectConfigSnapshot api, N4JSProjectConfigSnapshot[] impls, ResourceSet resourceSet, IResourceDescriptions index) {
    final ProjectComparisonEntry entry = new ProjectComparisonEntry(root, api, impls);
    for (N4JSSourceFolderSnapshot currSrcFolder : api.getSourceFolders()) {
        for (URI uri : currSrcFolder.getContents()) {
            final String uriStr = uri.toString();
            if (uriStr.endsWith("." + N4JSGlobals.N4JS_FILE_EXTENSION) || uriStr.endsWith("." + N4JSGlobals.N4JSD_FILE_EXTENSION)) {
                final IResourceDescription resDesc = index.getResourceDescription(uri);
                final TModule moduleApi = getModuleFrom(resourceSet, resDesc);
                if (moduleApi != null) {
                    final TModule[] moduleImpls = new TModule[impls.length];
                    for (int idx = 0; idx < impls.length; idx++) {
                        final N4JSProjectConfigSnapshot projectImpl = impls[idx];
                        if (projectImpl != null)
                            moduleImpls[idx] = findImplementation(moduleApi, projectImpl, resourceSet, index);
                        else
                            moduleImpls[idx] = null;
                    }
                    createEntries(entry, -1, moduleApi, moduleImpls, false);
                }
            }
        }
    }
    return entry;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI)

Aggregations

N4JSSourceFolderSnapshot (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)13 N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)8 URI (org.eclipse.emf.common.util.URI)6 Resource (org.eclipse.emf.ecore.resource.Resource)4 N4JSResource (org.eclipse.n4js.resource.N4JSResource)4 FileURI (org.eclipse.n4js.workspace.locations.FileURI)4 Script (org.eclipse.n4js.n4JS.Script)3 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)3 ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)2 Type (org.eclipse.n4js.ts.types.Type)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 TModule (org.eclipse.n4js.ts.types.TModule)1 TVariable (org.eclipse.n4js.ts.types.TVariable)1 N4JSSourceFolderSnapshotForPackageJson (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshotForPackageJson)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1