use of org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot in project n4js by eclipse.
the class N4JSClusteringStorageAwareResourceLoader method initDependencyMaps.
private void initDependencyMaps(List<LoadResult> results, ProjectConfigSnapshot pcs, Set<LoadResult> noDeps, Multimap<LoadResult, LoadResult> dependsOn, Multimap<LoadResult, LoadResult> dependsOnInverse) {
Multimap<String, LoadResult> moduleName2Result = HashMultimap.create();
for (LoadResult result : results) {
URI uri = result.resource.getURI();
SourceFolderSnapshot srcFolder = pcs.findSourceFolderContaining(uri);
URI srcFolderUri = srcFolder.getPath();
URI relUri = uri.deresolve(srcFolderUri);
String moduleName = URIUtils.trimFileExtension(relUri).toFileString();
moduleName2Result.put(moduleName, result);
noDeps.add(result);
}
String prjName = pcs.getName();
for (LoadResult result : results) {
for (EObject eobj : result.resource.getContents()) {
if (eobj instanceof Script) {
Script script = (Script) eobj;
for (EObject topLevelStmt : script.getScriptElements()) {
if (topLevelStmt instanceof ImportDeclaration) {
ImportDeclaration impDecl = (ImportDeclaration) topLevelStmt;
String moduleSpecifier = impDecl.getModuleSpecifierAsText();
boolean hasInnerProjectDependency = false;
if (moduleName2Result.containsKey(moduleSpecifier)) {
hasInnerProjectDependency = true;
} else if (moduleSpecifier.startsWith(prjName)) {
moduleSpecifier = moduleSpecifier.substring(prjName.length() + 1);
if (moduleName2Result.containsKey(moduleSpecifier)) {
hasInnerProjectDependency = true;
}
}
if (hasInnerProjectDependency) {
for (LoadResult dependsOnResult : moduleName2Result.get(moduleSpecifier)) {
dependsOn.put(result, dependsOnResult);
dependsOnInverse.put(dependsOnResult, result);
}
noDeps.remove(result);
}
} else {
// we know that all import statements are at the beginning of a file
break;
}
}
}
}
}
}
use of org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot in project n4js by eclipse.
the class XWorkspaceBuilder method scanAddedSourceFoldersForNewSourceFiles.
/**
* @return list of URIs from newly added source folders (including source folders of added projects).
*/
private List<URI> scanAddedSourceFoldersForNewSourceFiles(WorkspaceChanges changes, IFileSystemScanner scanner) {
List<URI> added = new ArrayList<>();
for (SourceFolderSnapshot sourceFolder : changes.getAllAddedSourceFolders()) {
List<URI> sourceFilesOnDisk = sourceFolderScanner.findAllSourceFiles(sourceFolder, scanner);
added.addAll(sourceFilesOnDisk);
}
return added;
}
use of org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot in project n4js by eclipse.
the class N4JSProjectConfig method computeChanges.
/**
* Given two project configuration snapshots representing the old and new state of the receiving project, this
* method computes the corresponding workspace changes. If no changes occurred, an empty {@link WorkspaceChanges}
* instance will be returned.
*/
public static WorkspaceChanges computeChanges(ProjectConfigSnapshot oldProjectConfig, ProjectConfigSnapshot newProjectConfig) {
Set<? extends SourceFolderSnapshot> oldSourceFolders = oldProjectConfig.getSourceFolders();
Set<? extends SourceFolderSnapshot> newSourceFolders = newProjectConfig.getSourceFolders();
// detect added/removed source folders
Map<URI, SourceFolderSnapshot> oldSFs = new HashMap<>();
Map<URI, SourceFolderSnapshot> newSFs = new HashMap<>();
for (SourceFolderSnapshot sourceFolder : oldSourceFolders) {
oldSFs.put(sourceFolder.getPath(), sourceFolder);
}
for (SourceFolderSnapshot sourceFolder : newSourceFolders) {
newSFs.put(sourceFolder.getPath(), sourceFolder);
}
List<SourceFolderSnapshot> addedSourceFolders = new ArrayList<>();
List<SourceFolderSnapshot> removedSourceFolders = new ArrayList<>();
for (URI sfUri : Iterables.concat(oldSFs.keySet(), newSFs.keySet())) {
boolean isOld = oldSFs.containsKey(sfUri);
boolean isNew = newSFs.containsKey(sfUri);
if (isOld && isNew) {
// unchanged
} else if (isOld && !isNew) {
removedSourceFolders.add(oldSFs.get(sfUri));
} else if (!isOld && isNew) {
addedSourceFolders.add(newSFs.get(sfUri));
}
}
if (Objects.equals(oldProjectConfig.getName(), newProjectConfig.getName())) {
// detect changes in project properties
boolean propertiesChanged = !addedSourceFolders.isEmpty() || !removedSourceFolders.isEmpty() || !Objects.equals(oldProjectConfig, newProjectConfig);
return new WorkspaceChanges(ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.copyOf(removedSourceFolders), ImmutableList.copyOf(addedSourceFolders), ImmutableList.of(), ImmutableList.of(), propertiesChanged ? ImmutableList.of(newProjectConfig) : ImmutableList.of());
} else {
return new WorkspaceChanges(ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.copyOf(removedSourceFolders), ImmutableList.copyOf(addedSourceFolders), ImmutableList.of(oldProjectConfig), ImmutableList.of(newProjectConfig), ImmutableList.of());
}
}
use of org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot in project n4js by eclipse.
the class N4JSProjectBuilder method scanForSourceFiles.
/**
* Overridden to exclude all ts files (yet still include d.ts files)
*/
@Override
protected Set<URI> scanForSourceFiles() {
Set<URI> result = new HashSet<>();
for (SourceFolderSnapshot srcFolder : getProjectConfig().getSourceFolders()) {
List<URI> allSourceFileUris = sourceFolderScanner.findAllSourceFiles(srcFolder, fileSystemScanner);
for (URI srcFileUri : allSourceFileUris) {
if (!srcFileUri.hasTrailingPathSeparator()) {
IResourceServiceProvider rsp = resourceServiceProviders.getResourceServiceProvider(srcFileUri);
if (rsp != null) {
String fileExtension = URIUtils.fileExtension(srcFileUri);
if (N4JSGlobals.TS_FILE_EXTENSION.equals(fileExtension)) {
// ignore ts files (yet consider d.ts files)
continue;
}
result.add(srcFileUri);
}
}
}
}
return result;
}
use of org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot in project n4js by eclipse.
the class XWorkspaceBuilder method getURIsFromRemovedSourceFolders.
/**
* @return list of URIs from removed source folders (<em>not</em> including URIs of removed projects).
*/
private List<URI> getURIsFromRemovedSourceFolders(WorkspaceChanges workspaceChanges) {
List<URI> deleted = new ArrayList<>(workspaceChanges.getRemovedURIs());
for (SourceFolderSnapshot sourceFolder : workspaceChanges.getRemovedSourceFolders()) {
URI prefix = sourceFolder.getPath();
ProjectBuilder projectBuilder = workspaceManager.getProjectBuilder(prefix);
if (projectBuilder != null) {
List<URI> matchedURIs = projectBuilder.findResourcesStartingWithPrefix(prefix);
deleted.addAll(matchedURIs);
}
}
return deleted;
}
Aggregations