Search in sources :

Example 31 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class N4JSResourceDescriptionManager method hasDependencyTo.

/**
 * Returns true iff the project containing the 'fromUri' has a direct dependency to the project containing the
 * 'toUri'.
 */
private boolean hasDependencyTo(URI fromUri, URI toUri) {
    final IN4JSProject fromProject = n4jsCore.findProject(fromUri).orNull();
    final IN4JSProject toProject = n4jsCore.findProject(toUri).orNull();
    if (null != fromProject && null != toProject) {
        if (Objects.equals(fromProject, toProject)) {
            return true;
        }
        for (IN4JSProject fromProjectDependency : fromProject.getDependenciesAndImplementedApis()) {
            // workspace one and/or vice versa.
            if (Objects.equals(fromProjectDependency, toProject) && fromProjectDependency.isExternal() == fromProject.isExternal()) {
                return true;
            }
        }
    }
    return false;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 32 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class AbstractTypeVisibilityChecker method isTestedProjectOf.

/**
 * Returns with {@code true} if the context module argument belongs to a {@link ProjectType#TEST test} project and
 * any of its tested projects contains the element module argument.
 *
 * @param contextModule
 *            the content module.
 * @param elementModule
 *            the element module.
 * @return {@code true} if the element module's container project is the tested project of the context module.
 *         Otherwise returns with {@code false}.
 */
public boolean isTestedProjectOf(final TModule contextModule, final TModule elementModule) {
    if (null == elementModule || null == contextModule || null == elementModule.eResource() || null == contextModule.eResource()) {
        return false;
    }
    for (final IN4JSProject testedProject : getTestedProjects(contextModule.eResource().getURI())) {
        final URI testProjectLocation = testedProject.getLocation();
        if (null != testProjectLocation) {
            final Resource eResource = elementModule.eResource();
            if (null != eResource) {
                final URI resourceUri = eResource.getURI();
                final IN4JSProject elementProject = core.findProject(resourceUri).orNull();
                if (null != elementProject) {
                    if (emptyIfNull(elementProject.getProjectId()).equals(testedProject.getProjectId())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 33 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class N4JSModel method getTestedProjects.

public Collection<IN4JSProject> getTestedProjects(final N4JSProject project) {
    if (null == project || !project.exists()) {
        return emptyList();
    }
    // Shortcut to avoid reading the project description at all.
    if (!TEST.equals(project.getProjectType())) {
        return emptyList();
    }
    final Builder<IN4JSProject> builder = ImmutableList.builder();
    final URI location = project.getLocation();
    final ProjectDescription description = getProjectDescription(location);
    if (null != description) {
        for (TestedProject testedProject : description.getAllTestedProjects()) {
            if (null != testedProject.getProject()) {
                URI hostLocation = workspace.getLocation(location, testedProject, PROJECT);
                if (null == hostLocation) {
                    hostLocation = externalLibraryWorkspace.getLocation(location, testedProject, PROJECT);
                }
                if (hostLocation != null) {
                    final N4JSProject tested = getN4JSProject(hostLocation);
                    if (null != tested && tested.exists()) {
                        builder.add(tested);
                    }
                }
            }
        }
    }
    return builder.build();
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) SimpleProjectDescription(org.eclipse.n4js.n4mf.SimpleProjectDescription) TestedProject(org.eclipse.n4js.n4mf.TestedProject)

Example 34 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class N4JSModel method getDependencies.

private ImmutableList<? extends IN4JSProject> getDependencies(N4JSProject project, boolean includeApis) {
    ImmutableList.Builder<IN4JSProject> result = ImmutableList.builder();
    URI location = project.getLocation();
    ProjectDescription description = getProjectDescription(location);
    if (description != null) {
        result.addAll(resolveProjectReferences(project, description.getAllRequiredRuntimeLibraries()));
        result.addAll(resolveProjectReferences(project, description.getAllProjectDependencies()));
        result.addAll(getTestedProjects(project));
        if (includeApis) {
            result.addAll(resolveProjectReferences(project, description.getImplementedProjects()));
        }
    }
    return result.build();
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) ImmutableList(com.google.common.collect.ImmutableList) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) SimpleProjectDescription(org.eclipse.n4js.n4mf.SimpleProjectDescription)

Example 35 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class ProjectImportEnablingScope method getElements.

@Override
public Iterable<IEObjectDescription> getElements(QualifiedName name) {
    switch(computeImportType(name, this.contextProject)) {
        case PROJECT_IMPORT:
            final String firstSegment = name.getFirstSegment();
            final IN4JSProject targetProject = findProject(firstSegment, contextProject);
            return getElementsWithDesiredProjectID(ImportSpecifierUtil.getMainModuleOfProject(targetProject), name.getFirstSegment());
        case COMPLETE_IMPORT:
            return getElementsWithDesiredProjectID(name.skipFirst(1), name.getFirstSegment());
        case SIMPLE_IMPORT:
            return parent.getElements(name);
        default:
            return Collections.emptyList();
    }
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

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