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);
}
}
}
}
}
}
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);
}
}
}
}
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;
}
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);
}
}
}
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));
}
Aggregations