Search in sources :

Example 76 with IN4JSProject

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

the class StaticPolyfillHelper method findStaticPolyfiller.

/**
 * Find the corresponding static-polyfill to this {@code @@PolyfillAware} resource in the same project. returns null
 * if not found or this resource has no {@code @@PolyfillAware} annotation.
 */
public URI findStaticPolyfiller(Resource resource) {
    // ensure right resource
    if (resource instanceof N4JSResource) {
        final N4JSResource res = (N4JSResource) resource;
        if (!isContainedInStaticPolyfillAware(res.getScript()))
            return null;
        final QualifiedName qnFilled = qualifiedNameConverter.toQualifiedName(res.getModule().getQualifiedName());
        final IN4JSProject project = projectResolver.resolveProject(res.getURI());
        final QualifiedName fqn = qnFilled;
        // see Req.155#4: "Both
        final Optional<String> fileExtension = Optional.of(res.getURI().fileExtension());
        // extensions are
        // equal."
        final IN4JSSourceContainer filledSrcContainer = n4jsCore.findN4JSSourceContainer(res.getURI()).get();
        for (IN4JSSourceContainer srcConti : project.getSourceContainers()) {
            if (!Objects.equals(filledSrcContainer, srcConti)) {
                final URI uri = srcConti.findArtifact(fqn, fileExtension);
                if (uri != null) {
                    return uri;
                }
            }
        }
    }
    return null;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) N4JSResource(org.eclipse.n4js.resource.N4JSResource) URI(org.eclipse.emf.common.util.URI) IN4JSSourceContainer(org.eclipse.n4js.projectModel.IN4JSSourceContainer)

Example 77 with IN4JSProject

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

the class EObjectDescriptionHelper method isDescriptionOfModuleWith.

/**
 * Helper method that checks if given {@link IEObjectDescription description} describes {@link TModule} containing
 * given {@link EObject}.
 *
 * Returns <code>true</code> only if provided {@link IEObjectDescription description} has the same
 * {@link QualifiedName} as module of the {@link EObject}. Additionally if {@link IEObjectDescription description}
 * describes {@link TModule#isMainModule() main module} then it is checked if both are contained in the same
 * {@link IN4JSProject}.
 *
 * @returns true if {@link IEObjectDescription} describes module of {@link EObject}
 */
public boolean isDescriptionOfModuleWith(IEObjectDescription eoDescription, EObject eObject) {
    // check if module names are the same
    final String eobjectModuleName = EcoreUtil2.getContainerOfType(eObject, Script.class).getModule().getQualifiedName();
    if (!eobjectModuleName.equals(qualifiedNameConverter.toString(eoDescription.getQualifiedName()))) {
        return false;
    }
    // if not a main module we assume true
    if (!isMainModule(eoDescription)) {
        return true;
    }
    // for main modules we check containing project
    final IN4JSProject targetProject = n4jsCore.findProject(eoDescription.getEObjectURI()).orNull();
    final IN4JSProject currentProject = n4jsCore.findProject(eObject.eResource().getURI()).orNull();
    return targetProject == currentProject;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 78 with IN4JSProject

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

the class ImportSpecifierUtil method computeImportType.

/**
 * Convenience method over {@link ImportSpecifierUtil#computeImportType(QualifiedName, boolean, IN4JSProject)}
 */
public static ImportType computeImportType(QualifiedName name, IN4JSProject project) {
    final String firstSegment = name.getFirstSegment();
    final IN4JSProject targetProject = getDependencyWithID(firstSegment, project);
    final boolean firstSegmentIsProjectId = targetProject != null;
    return ImportSpecifierUtil.computeImportType(name, firstSegmentIsProjectId, targetProject);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 79 with IN4JSProject

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

the class JSDoc2AdocFullTest method fullTest.

@Override
@SuppressWarnings("unused")
protected void fullTest(String projectId) throws IOException, InterruptedException, InterruptedException {
    String systemSeparator = System.getProperty("line.separator", "\n");
    try {
        for (String lsep : new String[] { "\n", "\r\n", "\r" }) {
            System.setProperty("line.separator", lsep);
            String expectationFileName = projectId + "/expected.adoc";
            workspace = new FileBasedWorkspace(resourceSetProvider, classpathPackageManager);
            URI uriProject = URI.createFileURI(new File(TESTRESOURCES + projectId).getAbsolutePath());
            workspace.registerProject(uriProject);
            N4JSModel model = new N4JSModel(workspace);
            injector.injectMembers(model);
            runtimeCore = new N4JSRuntimeCore(workspace, model);
            IN4JSProject project = runtimeCore.findProject(uriProject).get();
            assertNotNull("Project not found", project);
            Collection<SpecFile> specChangeSet = jSDoc2SpecProcessor.convert(new File(TESTRESOURCES), Collections.singleton(project), (p) -> resourceSetProvider.get(), SubMonitorMsg.nullProgressMonitor());
            String adocRootName = TESTRESOURCES + projectId + "/expectedADoc";
            Collection<String> expectedFileNames = getExpectedFileNames(adocRootName, specChangeSet);
            assertFalse(expectedFileNames.isEmpty());
            File adocRoot = new File(adocRootName);
            String completeActual = "";
            String completeExpected = "";
            for (SpecFile specFile : specChangeSet) {
                String expectedFile = getExpectedFile(expectedFileNames, specFile);
                if (expectedFile == null)
                    continue;
                String fullExpectationFileName = adocRoot.toPath().resolve(expectedFile).toString();
                String expectedADoc = Files.readFileIntoString(fullExpectationFileName);
                String actualADoc = specFile.getNewContent();
                if (UPDATE_EXPECTION && !actualADoc.equals(expectedADoc)) {
                    expectedADoc = actualADoc;
                    Files.writeStringIntoFile(fullExpectationFileName, expectedADoc);
                    System.out.println("Updated expectation " + fullExpectationFileName);
                }
                completeActual += "\n//////// " + expectedFile + " ////////\n";
                completeActual += actualADoc;
                completeExpected += "\n//////// " + expectedFile + " ////////\n";
                completeExpected += expectedADoc;
            }
            assertEqualsIgnoreWS(completeExpected, completeActual);
        }
    } finally {
        System.setProperty("line.separator", systemSeparator);
    }
}
Also used : FileBasedWorkspace(org.eclipse.n4js.internal.FileBasedWorkspace) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) N4JSRuntimeCore(org.eclipse.n4js.internal.N4JSRuntimeCore) URI(org.eclipse.emf.common.util.URI) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile) File(java.io.File) N4JSModel(org.eclipse.n4js.internal.N4JSModel) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile)

Example 80 with IN4JSProject

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

the class AbstractN4JSCoreTest method testCreateYieldsEqualsInstances_02.

@SuppressWarnings("javadoc")
@Test
public void testCreateYieldsEqualsInstances_02() {
    URI doesNotExist = myProjectURI.trimSegments(1).appendSegment("doesNotExist");
    IN4JSProject first = getN4JSCore().create(doesNotExist);
    IN4JSProject second = getN4JSCore().create(doesNotExist);
    assertEquals(first, second);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

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