Search in sources :

Example 1 with IN4JSSourceContainer

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;
}
Also used : URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 2 with IN4JSSourceContainer

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();
}
Also used : URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 3 with IN4JSSourceContainer

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);
                    }
                }
            }
        }
    }
}
Also used : Script(org.eclipse.n4js.n4JS.Script) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer) IOException(java.io.IOException)

Example 4 with IN4JSSourceContainer

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 &#64;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();
}
Also used : IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Inject(com.google.inject.Inject) TClass(org.eclipse.n4js.ts.types.TClass) ResourceNameComputer(org.eclipse.n4js.utils.ResourceNameComputer) IN4JSCore(org.eclipse.n4js.projectModel.IN4JSCore) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Collections.singletonList(java.util.Collections.singletonList) Optional.fromNullable(com.google.common.base.Optional.fromNullable) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer) Type(org.eclipse.n4js.ts.types.Type) HashMultimap(com.google.common.collect.HashMultimap) Optional(com.google.common.base.Optional) FluentIterable.from(com.google.common.collect.FluentIterable.from) Map(java.util.Map) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) TEST_METHOD(org.eclipse.n4js.AnnotationDefinition.TEST_METHOD) EcoreUtil2.getContainerOfType(org.eclipse.xtext.EcoreUtil2.getContainerOfType) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Collections.emptyList(java.util.Collections.emptyList) EXPORTED_CLASS_KEY(org.eclipse.n4js.resource.N4JSResourceDescriptionStrategy.EXPORTED_CLASS_KEY) Collection(java.util.Collection) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) EObject(org.eclipse.emf.ecore.EObject) TestCase(org.eclipse.n4js.tester.domain.TestCase) TMethod(org.eclipse.n4js.ts.types.TMethod) TestSuite(org.eclipse.n4js.tester.domain.TestSuite) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Stream(java.util.stream.Stream) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration) TRUE(java.lang.Boolean.TRUE) URI(org.eclipse.emf.common.util.URI) TEST_CLASS_KEY(org.eclipse.n4js.resource.N4JSResourceDescriptionStrategy.TEST_CLASS_KEY) Optional.absent(com.google.common.base.Optional.absent) FileExtensionsRegistry(org.eclipse.n4js.fileextensions.FileExtensionsRegistry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) TModule(org.eclipse.n4js.ts.types.TModule) TestTree(org.eclipse.n4js.tester.domain.TestTree) Strings(com.google.common.base.Strings) ContainerTypesHelper(org.eclipse.n4js.utils.ContainerTypesHelper) EClass(org.eclipse.emf.ecore.EClass) FileExtensionType(org.eclipse.n4js.fileextensions.FileExtensionType) StreamSupport(java.util.stream.StreamSupport) ID(org.eclipse.n4js.tester.domain.ID) Iterables.isEmpty(com.google.common.collect.Iterables.isEmpty) ABSTRACT_KEY(org.eclipse.n4js.resource.N4JSResourceDescriptionStrategy.ABSTRACT_KEY) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) TMember(org.eclipse.n4js.ts.types.TMember) N4IDLGlobals(org.eclipse.n4js.n4idl.N4IDLGlobals) UUID.randomUUID(java.util.UUID.randomUUID) N4JSResource(org.eclipse.n4js.resource.N4JSResource) String.valueOf(java.lang.String.valueOf) TypesPackage(org.eclipse.n4js.ts.types.TypesPackage) Comparator(java.util.Comparator) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 5 with IN4JSSourceContainer

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;
}
Also used : URI(org.eclipse.emf.common.util.URI) File(java.io.File) LinkedList(java.util.LinkedList) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Aggregations

IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)18 URI (org.eclipse.emf.common.util.URI)15 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)9 N4JSResource (org.eclipse.n4js.resource.N4JSResource)5 LinkedList (java.util.LinkedList)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 ImmutableList (com.google.common.collect.ImmutableList)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 Optional (com.google.common.base.Optional)2 HashMultimap (com.google.common.collect.HashMultimap)2 Inject (com.google.inject.Inject)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Script (org.eclipse.n4js.n4JS.Script)2 ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)2