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