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