use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ProjectImportEnablingScope method computeImportType.
/**
* Convenience method over {@link ImportSpecifierUtil#computeImportType(QualifiedName, boolean, IN4JSProject)}
*/
private ImportType computeImportType(QualifiedName name, IN4JSProject project) {
final String firstSegment = name.getFirstSegment();
final IN4JSProject targetProject = findProject(firstSegment, project);
final boolean firstSegmentIsProjectId = targetProject != null;
return ImportSpecifierUtil.computeImportType(name, firstSegmentIsProjectId, targetProject);
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class TestDiscoveryHelper method getClassName.
/**
* Returns the name to be used in the test catalog for the given {@link TClass}. We use the fully qualified name for
* this purpose.
*/
private String getClassName(TClass clazz) {
String classStr = "";
if (clazz.getDeclaredVersion() > 0) {
classStr = resourceNameComputer.getFullyQualifiedTypeName(clazz) + N4IDLGlobals.COMPILED_VERSION_SEPARATOR + clazz.getDeclaredVersion();
} else {
classStr = resourceNameComputer.getFullyQualifiedTypeName(clazz);
}
IN4JSProject project = n4jscore.findProject(clazz.eResource().getURI()).orNull();
if (project != null) {
String output = project.getOutputPath();
if (Strings.isNullOrEmpty(output) == false && output != ".") {
if (output.endsWith("/")) {
classStr = output + classStr;
} else {
classStr = output + "/" + classStr;
}
}
}
return classStr;
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class TestDiscoveryHelper method collectTestLocations.
/**
* Most clients should use method {@link #collectTests(URI...)} instead!
* <p>
* Low-level method to collect all test modules, i.e. N4JS files containing classes containing at least one method
* annotated with @Test, as {@link IResourceDescription}s.
*/
private Stream<URI> collectTestLocations(final IResourceDescriptions index, final ResourceSet resSet, final URI location) {
if (null == location) {
return Stream.empty();
}
// does location point to an N4JS project?
if (isProject(location)) {
// yes
// --> collect all test modules (files containing test classes) located in source containers of type "test"
final IN4JSProject p = n4jsCore.create(location);
return p.getSourceContainers().stream().filter(IN4JSSourceContainer::isTest).flatMap(// note: IN4JSSourceContainer is an Iterable<URI>
TestDiscoveryHelper::stream).filter(// filter out everything but N4JS files.
uri -> isTestFile(uri)).filter(uri -> isTestModule(resSet, index.getResourceDescription(uri)));
}
// does location point to an n4js file?
final IResourceDescription resDesc = index.getResourceDescription(location.trimFragment());
if (resDesc != null) {
// yes --> is it a test module? (i.e. does it contain test classes and the class is not abstract?)
if (isTestModule(resSet, resDesc)) {
// yes --> is it contained in a source container of type "test"?
final IN4JSSourceContainer srcContainer = n4jsCore.findN4JSSourceContainer(location.trimFragment()).orNull();
if (srcContainer != null && srcContainer.isTest()) {
// return location with fragment! (if any)
return Stream.of(location);
}
}
return Stream.empty();
}
// does location point to a source container (or sub-folder)?
final IN4JSSourceContainer srcContainer = n4jsCore.findN4JSSourceContainer(location).orNull();
if (srcContainer != null) {
// yes --> is this a source container of type "test"?
if (srcContainer.isTest()) {
// yes --> collect all test modules (files containing test classes) in this source container
final String locationStr = location.toString();
return // note: IN4JSSourceContainer is an Iterable<URI>
stream(srcContainer).filter(// TODO improve?
uri -> uri.toString().startsWith(locationStr)).filter(uri -> isTestModule(resSet, index.getResourceDescription(uri)));
}
return Stream.empty();
}
// invalid location URI
return Stream.empty();
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ResourceLoadingStatistics method computeAndShowStatsForWorkspace.
/**
* Computes and prints resource loading statistics for all N4JS[X] projects in the workspace.
* <p>
* For each N4JS[X] file in the workspace, this method will
* <ol>
* <li>create a new, empty resource set,
* <li>load the file into this resource set and fully process it (parser, types builder, post-processing),
* <li>count how many other files/resources were automatically loaded into the resource set and if they were loaded
* from AST or from Xtext index,
* <li>print statistics to the given stream.
* </ol>
*/
public void computeAndShowStatsForWorkspace(PrintStream out, IProgressMonitor monitor) {
final CancelIndicator cancelIndicator = new MonitorBasedCancelIndicator(monitor);
// for proper progress reporting, first collect all URIs in all N4JS projects
int uriCount = 0;
final Map<IN4JSProject, List<URI>> urisPerProject = new LinkedHashMap<>();
final Iterable<IN4JSProject> projects = n4jsCore.findAllProjects();
for (IN4JSProject project : projects) {
operationCanceledManager.checkCanceled(cancelIndicator);
if (!isManagedByLibraryManager(project)) {
final List<URI> uris = collectURIsToInvestigate(project);
uriCount += uris.size();
urisPerProject.put(project, uris);
}
}
// now do the actual work: compute and show statistics for each project
monitor.beginTask("Investigate projects in workspace ... ", uriCount);
for (Entry<IN4JSProject, List<URI>> entry : urisPerProject.entrySet()) {
operationCanceledManager.checkCanceled(cancelIndicator);
final IN4JSProject project = entry.getKey();
final List<URI> uris = entry.getValue();
final List<FileLoadInfo> results = investigate(project, uris, out, monitor, false);
out.println();
out.println("SUMMARY:");
out.println();
FileLoadInfo.printReport(project, results, out);
}
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ExternalLibraryBuilder method hasWorkspaceCounterpart.
/**
* Returns with {@code true} if the external project is accessible in the workspace as well.
*/
private boolean hasWorkspaceCounterpart(IN4JSProject project) {
URI uri = URI.createPlatformResourceURI(project.getProjectId(), true);
IN4JSProject n4Project = core.findProject(uri).orNull();
return null != n4Project && n4Project.exists() && !n4Project.isExternal();
}
Aggregations