Search in sources :

Example 16 with IN4JSProject

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

the class ImportsFactory method createDefaultImport.

/**
 * Creates a new default import with name 'name' from object description.
 */
private ImportDeclaration createDefaultImport(String name, IN4JSProject contextProject, TExportableElement te, Adapter nodelessMarker) {
    String moduleQN = te.getContainingModule().getQualifiedName();
    QualifiedName qn = qualifiedNameConverter.toQualifiedName(moduleQN);
    String firstSegment = qn.getFirstSegment();
    IN4JSProject project = ImportSpecifierUtil.getDependencyWithID(firstSegment, contextProject);
    return createImportDeclaration(qn, name, project, nodelessMarker, this::addDefaultImport);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 17 with IN4JSProject

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

the class N4JSRuntimeCoreWithMockProject method createMockProject.

private IN4JSProject createMockProject(MockN4JSModel model) {
    N4JSProject project = new MockProject(MockProject.MOCK_URI, model);
    model.setMockProject(project);
    return project;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) N4JSProject(org.eclipse.n4js.internal.N4JSProject)

Example 18 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject 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 19 with IN4JSProject

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

the class XpectN4JSES5TranspilerHelper method getCompiledFileBasePath.

private String getCompiledFileBasePath(final Script script) {
    String path = script.getModule().getProjectId() + N4JSLanguageConstants.DEFAULT_PROJECT_OUTPUT;
    IN4JSProject project = core.findProject(script.eResource().getURI()).orNull();
    if (project != null) {
        path = AbstractSubGenerator.calculateProjectBasedOutputDirectory(project);
    }
    return path;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 20 with IN4JSProject

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

the class ProjectCompareHelper method compareModules.

/**
 * Get the comparison for a module in a specific implementation specified by it's ID.
 *
 * @param module
 *            can be either Implementation or API
 * @param implementationID
 *            the current context to compare with
 *
 * @param includePolyfills
 *            {@code true} if polyfills should be considered as the part of the API and the implementation.
 *            Otherwise {@code false}.
 * @return a comparison between API and implementation with implementationID, or <code>null</code> if no project
 *         could be found, the module is not part of an API/IMPL ...
 */
public ProjectComparisonEntry compareModules(TModule module, String implementationID, final boolean includePolyfills) {
    Optional<? extends IN4JSProject> opt = n4jsCore.findProject(module.eResource().getURI());
    if (!opt.isPresent()) {
        return null;
    }
    IN4JSProject project = opt.get();
    IN4JSProject implProject = null;
    IN4JSProject apiProject = null;
    TModule apiModule = null;
    TModule apiImplModule = null;
    if (!project.getImplementationId().isPresent()) {
        // this is NOT an implementation project, so assume we have the api
        // need to load the correct implementation. Since there might be multiple implementors
        // TODO replace with central instance
        final ApiImplMapping mapping = ApiImplMapping.of(n4jsCore);
        implProject = mapping.getImpl(project.getProjectId(), implementationID);
        if (implProject == null) {
            // no implementation found.
            return null;
        }
        apiProject = project;
        apiModule = module;
        URI impUri = artifactHelper.findArtifact(implProject, apiModule.getQualifiedName(), Optional.of(N4JSGlobals.N4JS_FILE_EXTENSION));
        if (impUri != null) {
            IResourceDescriptions xtextIndex = n4jsCore.getXtextIndex(module.eResource().getResourceSet());
            IResourceDescription resourceDescription = xtextIndex.getResourceDescription(impUri);
            if (resourceDescription != null) {
                apiImplModule = n4jsCore.loadModuleFromIndex(module.eResource().getResourceSet(), resourceDescription, false);
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("...ouch nothing in index for " + impUri);
                }
                Resource implResource = module.eResource().getResourceSet().getResource(impUri, true);
                apiImplModule = (TModule) implResource.getContents().get(1);
                // .get(1);
                if (logger.isDebugEnabled()) {
                    logger.debug("TModule loaded from Resource: " + apiImplModule);
                }
            }
        } else {
            // No implementation present.
            if (logger.isDebugEnabled()) {
                logger.debug("No implementation given. For " + apiModule.getQualifiedName());
            }
        }
    } else {
        // check that the implementation ID matches.
        if (implementationID.equals(project.getImplementationId().get())) {
            implProject = project;
            apiImplModule = module;
            ImmutableList<? extends IN4JSProject> apiProjects = implProject.getImplementedProjects();
            labelA: for (IN4JSProject ap : apiProjects) {
                URI apiURI = artifactHelper.findArtifact(ap, apiImplModule.getQualifiedName(), Optional.of(N4JSGlobals.N4JSD_FILE_EXTENSION));
                if (apiURI != null) {
                    IResourceDescriptions xtextIndex = n4jsCore.getXtextIndex(apiImplModule.eResource().getResourceSet());
                    IResourceDescription resourceDescription = xtextIndex.getResourceDescription(apiURI);
                    if (resourceDescription != null) {
                        apiModule = n4jsCore.loadModuleFromIndex(apiImplModule.eResource().getResourceSet(), resourceDescription, false);
                        if (apiModule != null)
                            break labelA;
                    }
                }
            }
        } else {
            return null;
        }
    }
    if (apiModule != null) {
        return compareModules(apiProject, apiModule, implProject, apiImplModule, includePolyfills);
    } else {
        // no apiModule --> this is not an implementation of API.
        return null;
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) TModule(org.eclipse.n4js.ts.types.TModule) 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