use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.
the class ManifestAwareResourceValidator method isInSourceFolder.
private boolean isInSourceFolder(Resource resource) {
URI uri = resource.getURI();
Optional<? extends IN4JSSourceContainer> sourceContainerOpt = eclipseCore.findN4JSSourceContainer(uri);
if (sourceContainerOpt.isPresent()) {
IN4JSSourceContainer sourceContainer = sourceContainerOpt.get();
return !sourceContainer.isLibrary() && !sourceContainer.isExternal();
}
return false;
}
use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.
the class NullUndefinedValidator method isInTestFolder.
private boolean isInTestFolder(EObject eobj) {
URI location = eobj.eResource().getURI();
final IN4JSSourceContainer c = n4jsCore.findN4JSSourceContainer(location).orNull();
return c != null && c.isTest();
}
use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.
the class XpectN4JSES5TranspilerHelper method compileImplementationOfN4JSDFile.
private void compileImplementationOfN4JSDFile(final Path root, StringBuilder errorResult, Resource dep, GeneratorOption[] options, boolean replaceQuotes) {
Script script = (Script) dep.getContents().get(0);
if (AnnotationDefinition.PROVIDED_BY_RUNTIME.hasAnnotation(script)) {
return;
}
Optional<? extends IN4JSSourceContainer> sourceOpt = core.findN4JSSourceContainer(dep.getURI());
if (sourceOpt.isPresent()) {
IN4JSSourceContainer source = sourceOpt.get();
IN4JSProject project = source.getProject();
for (IN4JSSourceContainer c : project.getSourceContainers()) {
if (c.isExternal()) {
String sourceRelativePath = dep.getURI().toString().replace(source.getLocation().toString(), "");
String[] potentialExternalSourceRelativeURISegments = null;
String potentialExternalSourceRelativePath = sourceRelativePath.replace(".n4jsd", ".js");
potentialExternalSourceRelativeURISegments = URI.createURI(potentialExternalSourceRelativePath).segments();
if (potentialExternalSourceRelativeURISegments != null) {
URI potentialExternalSourceURI = c.getLocation().appendSegments(potentialExternalSourceRelativeURISegments);
try {
Resource externalDep = dep.getResourceSet().getResource(potentialExternalSourceURI, true);
script = (Script) externalDep.getContents().get(0);
if (xpectGenerator.isCompilable(externalDep, errorResult)) {
createTempJsFileWithScript(root, script, options, replaceQuotes);
}
} catch (Exception e) {
throw new RuntimeException("Couldn't load " + potentialExternalSourceURI + ".", e);
}
}
}
}
}
}
use of org.eclipse.n4js.projectModel.IN4JSSourceContainer 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.IN4JSSourceContainer in project n4js by eclipse.
the class BuiltInProjectNode method getChildren.
@Override
public Object[] getChildren() {
final ResourceNode manifestNode = getManifestResourceNode();
final List<ResourceNode> childrenList = new LinkedList<>();
for (IN4JSSourceContainer srcContainer : project.getSourceContainers()) {
URI location = srcContainer.getLocation();
File file = new File(location.toFileString());
String label = srcContainer.getRelativeLocation();
ResourceNode resourceNode = ResourceNode.create(this, file, label);
if (resourceNode != null) {
childrenList.add(resourceNode);
}
}
final ResourceNode[] children = childrenList.toArray(new ResourceNode[0]);
return null != manifestNode ? Arrays2.add(children, manifestNode) : children;
}
Aggregations