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;
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations