use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.
the class ImportHelper method findResolutionsForAllUnresolvedReferences.
/**
* Searches the entire AST for unresolved references and searches possible resolutions for each. Returns the
* resolutions of those unresolved references that are unambiguous, i.e. that have only a single possible
* resolution.
*
* @see ReferenceResolutionFinder#findResolutions(N4JSWorkspaceConfigSnapshot, ReferenceDescriptor, boolean,
* boolean, Predicate, Predicate, IResolutionAcceptor)
*/
public List<ReferenceResolution> findResolutionsForAllUnresolvedReferences(Script script, CancelIndicator cancelIndicator) {
triggerProxyResolution(script, cancelIndicator);
N4JSWorkspaceConfigSnapshot wc = workspaceAccess.getWorkspaceConfig(script);
List<ReferenceResolution> result = new ArrayList<>();
Set<String> donePrefixes = new HashSet<>();
Iterator<EObject> iter = script.eAllContents();
while (iter.hasNext()) {
operationCanceledManager.checkCanceled(cancelIndicator);
EObject curr = iter.next();
ReferenceDescriptor reference = getUnresolvedReferenceForASTNode(curr);
if (reference != null && donePrefixes.add(reference.text)) {
ResolutionAcceptor acceptor = new ResolutionAcceptor(2, cancelIndicator);
referenceResolutionFinder.findResolutions(wc, reference, true, true, Predicates.alwaysFalse(), Predicates.alwaysTrue(), acceptor);
// only add a found resolution if we have exactly one resolution (i.e. if reference is unambiguous)
List<ReferenceResolution> resolutions = acceptor.getResolutions();
if (resolutions.size() == 1) {
result.add(resolutions.get(0));
}
}
}
return result;
}
use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot 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.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.
the class N4JSCodeActionService method applyToProject.
/**
* Applies all fixes of the same kind to the project containing the given URI.
*/
public WorkspaceEdit applyToProject(URI uri, String issueCode, String fixId, CancelIndicator cancelIndicator) {
WorkspaceEdit result = new WorkspaceEdit();
QuickFixImplementation quickfix = findOriginatingQuickfix(issueCode, fixId);
if (quickfix == null) {
return result;
}
N4JSWorkspaceConfigSnapshot wc = (N4JSWorkspaceConfigSnapshot) concurrentIndex.getWorkspaceConfigSnapshot();
N4JSProjectConfigSnapshot project = wc.findProjectContaining(uri);
if (project == null) {
return result;
}
List<URI> urisInProject = Lists.newArrayList(IterableExtensions.flatMap(project.getSourceFolders(), N4JSSourceFolderSnapshot::getContents));
Map<String, List<TextEdit>> allEdits = new HashMap<>();
for (URI currURI : urisInProject) {
Map<String, List<TextEdit>> edits = doApplyToFile(currURI, issueCode, quickfix, cancelIndicator);
allEdits.putAll(edits);
}
result.setChanges(allEdits);
return result;
}
use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.
the class DtsSubGenerator method isActive.
@Override
public boolean isActive(Resource input) {
boolean superIsActive = super.isActive(input);
if (!superIsActive) {
return false;
}
N4JSWorkspaceConfigSnapshot ws = workspaceAccess.getWorkspaceConfig(input);
N4JSProjectConfigSnapshot project = ws.findProjectContaining(input.getURI());
if (project != null) {
ProjectDescription pd = project.getProjectDescription();
return N4JSLanguageUtils.isDtsGenerationActive(pd);
}
return false;
}
use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.
the class MockWorkspaceSupplier method createWorkspaceConfig.
/**
* Creates the configuration of the mocked test workspace.
* <p>
* The returned workspace configuration is expected to contain at least one project with at least one source folder
* that isn't a {@link N4JSSourceFolderSnapshotForPackageJson}. The corresponding folders and files are not expected
* to exist on disk.
* <p>
* Only invoked on demand and never more than once.
*/
protected N4JSWorkspaceConfigSnapshot createWorkspaceConfig() {
N4JSProjectConfigSnapshot projectConfig = createProjectConfig();
URI workspacePath = URIUtils.trimTrailingPathSeparator(projectConfig.getPath()).trimSegments(1);
ProjectSet projects = new ProjectSet(Collections.singleton(projectConfig));
BuildOrderInfo buildOrderInfo = new BuildOrderInfo(Collections.emptyList(), Collections.emptySet());
return new N4JSWorkspaceConfigSnapshot(workspacePath, projects, buildOrderInfo);
}
Aggregations