Search in sources :

Example 1 with N4JSProjectConfigSnapshot

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

the class ReferenceResolutionFinder method collectAllElements.

/**
 * @param addHere
 *            elements will be added here.
 * @param addHereNames
 *            iff non-<code>null</code>, names of all elements will be added here.
 * @param addHereCollisioningModules
 *            iff non-<code>null</code>, module uris that clash (need project import) will be added here.
 * @param acceptor
 *            no resolutions will be passed to the acceptor by this method, only used for cancellation handling.
 */
private void collectAllElements(IScope scope, N4JSWorkspaceConfigSnapshot wc, List<IEObjectDescription> addHere, Map<IEObjectDescription, N4JSProjectConfigSnapshot> addHereProjects, Set<QualifiedName> addHereNames, Set<QualifiedName> addHereCollisioningModules, IResolutionAcceptor acceptor) {
    try (Measurement m = contentAssistDataCollectors.dcGetAllElements().getMeasurement()) {
        if (!acceptor.canAcceptMoreProposals()) {
            return;
        }
        Map<QualifiedName, N4JSProjectConfigSnapshot> moduleQN2Prj = new HashMap<>();
        Iterator<IEObjectDescription> iter = scope.getAllElements().iterator();
        // note: checking #canAcceptMoreProposals() in next line is required to quickly react to cancellation
        while (acceptor.canAcceptMoreProposals() && iter.hasNext()) {
            IEObjectDescription curr = iter.next();
            if (!isRelevantDescription(curr)) {
                continue;
            }
            addHere.add(curr);
            N4JSProjectConfigSnapshot prj = wc.findProjectContaining(curr.getEObjectURI());
            addHereProjects.put(curr, prj);
            if (addHereNames != null) {
                addHereNames.add(curr.getName());
            }
            if (curr.getEObjectURI() != null) {
                QualifiedName candidateModuleQN = getQualifiedNameOfModule(curr);
                if (candidateModuleQN != null) {
                    if (moduleQN2Prj.containsKey(candidateModuleQN)) {
                        if (moduleQN2Prj.get(candidateModuleQN) != prj) {
                            addHereCollisioningModules.add(candidateModuleQN);
                        }
                    } else {
                        moduleQN2Prj.put(candidateModuleQN, prj);
                    }
                }
            }
        }
    }
}
Also used : Measurement(org.eclipse.n4js.smith.Measurement) HashMap(java.util.HashMap) QualifiedName(org.eclipse.xtext.naming.QualifiedName) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with N4JSProjectConfigSnapshot

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

the class ReferenceResolutionFinder method findResolutions.

/**
 * Searches all valid resolutions of the given reference. Note: two higher-level convenience methods are available
 * in {@link ImportHelper}.
 *
 * @param reference
 *            the reference to resolve.
 * @param requireFullMatch
 *            if <code>true</code>, a candidate's name must be <em>equal</em> to the given <code>reference</code>'s
 *            {@link ReferenceDescriptor#text text}; otherwise it is sufficient if the name <em>starts with</em> the
 *            text.
 * @param isUnresolvedReference
 *            if true, the given <code>reference</code> is assumed to be an unresolved reference (which means
 *            certain collision checks can be omitted); otherwise nothing will be assumed, i.e. the reference may be
 *            resolved or unresolved.
 * @param conflictChecker
 *            allows for additional checks to be performed on a potential resolution's
 *            {@link ReferenceResolutionCandidate#shortName shortName}, before it is deemed valid and sent to the
 *            acceptor.
 * @param filter
 *            a filter to decide with candidate {@link IEObjectDescription}s to include in the search. Should return
 *            <code>true</code> to include the given candidate in the search.
 * @param acceptor
 *            an {@link IResolutionAcceptor} that will be invoked with all valid resolutions.
 */
public void findResolutions(N4JSWorkspaceConfigSnapshot wc, ReferenceDescriptor reference, boolean requireFullMatch, boolean isUnresolvedReference, Predicate<String> conflictChecker, Predicate<IEObjectDescription> filter, IResolutionAcceptor acceptor) {
    IScope scope = getScopeForContentAssist(reference);
    // iterate over candidates, filter them, and create ICompletionProposals for them
    boolean isPropertyAccess = reference.eReference == N4JSPackage.Literals.PARAMETERIZED_PROPERTY_ACCESS_EXPRESSION__PROPERTY;
    boolean needCollisionCheck = !isUnresolvedReference && !isPropertyAccess;
    List<IEObjectDescription> candidates = new ArrayList<>(512);
    Map<IEObjectDescription, N4JSProjectConfigSnapshot> projects = new HashMap<>();
    Set<QualifiedName> candidateNames = needCollisionCheck ? new HashSet<>() : null;
    Set<QualifiedName> collisioningModules = new HashSet<>();
    collectAllElements(scope, wc, candidates, projects, candidateNames, collisioningModules, acceptor);
    try (Measurement m = contentAssistDataCollectors.dcIterateAllElements().getMeasurement()) {
        // note: shadowing for #getAllElements does not work
        Set<URI> candidateURIs = new HashSet<>();
        for (IEObjectDescription candidate : candidates) {
            if (!acceptor.canAcceptMoreProposals()) {
                return;
            }
            if (!filter.apply(candidate)) {
                continue;
            }
            final N4JSProjectConfigSnapshot candidateProject = projects.get(candidate);
            final Optional<IScope> scopeForCollisionCheck = needCollisionCheck ? Optional.of(scope) : Optional.absent();
            final Optional<Set<QualifiedName>> allElementsForCollisionCheck = needCollisionCheck ? Optional.of(candidateNames) : Optional.absent();
            final ReferenceResolution resolution = getResolution(reference.text, reference.parseTreeNode, requireFullMatch, candidate, candidateProject, isPropertyAccess, scopeForCollisionCheck, allElementsForCollisionCheck, collisioningModules, conflictChecker);
            if (resolution != null && candidateURIs.add(candidate.getEObjectURI())) {
                acceptor.accept(resolution);
            }
        }
    }
}
Also used : Measurement(org.eclipse.n4js.smith.Measurement) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) IScope(org.eclipse.xtext.scoping.IScope) HashSet(java.util.HashSet)

Example 3 with N4JSProjectConfigSnapshot

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

the class N4JSProjectDescriptionFactory method getProjectDescription.

@Override
public ProjectDescription getProjectDescription(ProjectConfigSnapshot config) {
    ProjectDescription projectDescription = super.getProjectDescription(config);
    projectDescription.getDependencies().clear();
    N4JSProjectConfigSnapshot casted = (N4JSProjectConfigSnapshot) config;
    if (casted.getType() == ProjectType.PLAINJS) {
        // see N4JSProjectBuildOrderInfo for why we ignore dependencies of PLAINJS projects:
        return projectDescription;
    }
    projectDescription.getDependencies().addAll(casted.getDependencies());
    return projectDescription;
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Example 4 with N4JSProjectConfigSnapshot

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

the class N4JSProjectBuilder method writeTestCatalog.

/**
 * Generates the test catalog for the project.
 */
private void writeTestCatalog() {
    N4JSWorkspaceConfigSnapshot workspaceConfig = (N4JSWorkspaceConfigSnapshot) workspaceManager.getWorkspaceConfig();
    N4JSProjectConfigSnapshot projectConfig = getProjectConfig();
    File testCatalog = getTestCatalogFile(projectConfig);
    String catalog = testCatalogSupplier.get(workspaceConfig, getResourceSet(), projectConfig, // do not include "endpoint" property here
    true);
    if (catalog != null) {
        try (FileWriter fileWriter = new FileWriter(testCatalog)) {
            fileWriter.write(catalog);
        } catch (IOException e) {
            LOG.error("Error while writing test catalog file: " + testCatalog);
        }
    }
}
Also used : N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 5 with N4JSProjectConfigSnapshot

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

the class N4JSOutputConfigurationProvider method getOutputConfigurations.

@Override
public Set<OutputConfiguration> getOutputConfigurations(ResourceSet context) {
    EList<Resource> resources = context.getResources();
    if (resources.isEmpty()) {
        ProjectDescription description = ProjectDescription.findInEmfObject(context);
        N4JSProjectConfigSnapshot project = workspaceAccess.findProjectByName(context, description.getName());
        // returns a default configuration if 'project' is still 'null'
        return getOutputConfigurationSet(project);
    }
    return getOutputConfigurations(resources.get(0));
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) Resource(org.eclipse.emf.ecore.resource.Resource) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Aggregations

N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)50 URI (org.eclipse.emf.common.util.URI)15 N4JSPackageName (org.eclipse.n4js.workspace.utils.N4JSPackageName)9 N4JSSourceFolderSnapshot (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)8 Path (java.nio.file.Path)7 Resource (org.eclipse.emf.ecore.resource.Resource)7 N4JSWorkspaceConfigSnapshot (org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot)7 FileURI (org.eclipse.n4js.workspace.locations.FileURI)7 ArrayList (java.util.ArrayList)6 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)6 File (java.io.File)5 HashMap (java.util.HashMap)5 N4JSResource (org.eclipse.n4js.resource.N4JSResource)5 LinkedHashMap (java.util.LinkedHashMap)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)4 TModule (org.eclipse.n4js.ts.types.TModule)4 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)4