Search in sources :

Example 36 with IN4JSProject

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);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 37 with IN4JSProject

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;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 38 with IN4JSProject

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 &#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 39 with IN4JSProject

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);
    }
}
Also used : URI(org.eclipse.emf.common.util.URI) MonitorBasedCancelIndicator(org.eclipse.xtext.builder.MonitorBasedCancelIndicator) LinkedHashMap(java.util.LinkedHashMap) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) ArrayList(java.util.ArrayList) List(java.util.List) MonitorBasedCancelIndicator(org.eclipse.xtext.builder.MonitorBasedCancelIndicator) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Example 40 with IN4JSProject

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

Aggregations

IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)93 URI (org.eclipse.emf.common.util.URI)32 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Inject (com.google.inject.Inject)9 Map (java.util.Map)9 IProject (org.eclipse.core.resources.IProject)9 IN4JSCore (org.eclipse.n4js.projectModel.IN4JSCore)9 Optional (com.google.common.base.Optional)7 File (java.io.File)7 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 IOException (java.io.IOException)5 IN4JSArchive (org.eclipse.n4js.projectModel.IN4JSArchive)5 IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)5 FluentIterable.from (com.google.common.collect.FluentIterable.from)4