use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class DtsUtils method isDtsExportableReference.
/**
* Tells whether references (e.g. imports, type references) to the given resource and its contents can be exported
* to .d.ts. Iff this returns <code>false</code>, the .d.ts export will be cut off at this reference.
*/
public static boolean isDtsExportableReference(Resource resource, TranspilerState state) {
if (resource == null) {
return false;
}
if (N4Scheme.isResourceWithN4Scheme(resource)) {
return true;
}
N4JSProjectConfigSnapshot project = state.workspaceAccess.findProjectContaining(resource);
ProjectDescription pd = project != null ? project.getProjectDescription() : null;
return pd != null && pd.hasN4JSNature() && (N4JSLanguageUtils.isDtsGenerationActive(pd) || isDefinition(pd) || isRuntime(pd));
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class EcmaScriptSubGenerator method internalDoGenerate.
@Override
protected void internalDoGenerate(N4JSWorkspaceConfigSnapshot ws, Resource resource, GeneratorOption[] options, IFileSystemAccess fsa) {
if (!(resource instanceof N4JSResource)) {
if (N4JSGlobals.PACKAGE_JSON.equals(resource.getURI().lastSegment())) {
return;
}
throw new IllegalArgumentException("Given resource is not an N4JSResource. " + resource);
}
final N4JSResource resourceCasted = (N4JSResource) resource;
if (resourceCasted.getModule().isStaticPolyfillModule()) {
// do not transpile static polyfill modules (i.e. the fillers)
return;
}
/*
* In addition to here, check for cancellation is done also on file-emit boundaries, see fsa.generateFile().
*/
CancelIndicator monitor = ciExtractor.extractCancelIndicator(fsa);
// if the transpile-conditions are all met, then transpile:
if (shouldBeCompiled(resource, monitor)) {
final String compiledFileExtension = getCompiledFileExtension(resource);
final String filename = getTargetFileName(resource, compiledFileExtension);
final String sourceMapFileExtension = getCompiledFileSourceMapExtension(resource);
final String sourceMapFileName = getTargetFileName(resource, sourceMapFileExtension);
// used within the file-content to refer to sibling-file:
final String simpleSourceMapFileName = new File(sourceMapFileName).toPath().getFileName().toString();
final String simpleCompiledFileName = new File(filename).toPath().getFileName().toString();
// the next two variables store the navigation-prefix to get to the sources
final Path relativeNavigationToSrc = calculateNavigationFromOutputToSourcePath(ws, fsa, getCompilerID(), resourceCasted);
final N4JSProjectConfigSnapshot project = ws.findProjectContaining(resource.getURI());
boolean createSourceMap = project.getProjectDescription().isGeneratorEnabledSourceMaps();
if (filename != null) {
final EObject root = rootElement(resource);
if (root != null) {
final StringWriter buffCode = new StringWriter();
Optional<SourceMapInfo> optSourceMapData = Optional.absent();
if (createSourceMap) {
SourceMapInfo sourceMapDataInstance = getTranspiler().new SourceMapInfo();
sourceMapDataInstance.sourceMapBuff = new StringWriter();
sourceMapDataInstance.simpleSourceMapFileName = simpleSourceMapFileName;
sourceMapDataInstance.simpleCompiledFileName = simpleCompiledFileName;
sourceMapDataInstance.isExplicitSourceRef = false;
sourceMapDataInstance.n4jsFilePath = relativeNavigationToSrc.resolve(resourceCasted.getURI().lastSegment()).toString();
sourceMapDataInstance.sourceMapFileExtension = sourceMapFileExtension;
optSourceMapData = Optional.of(sourceMapDataInstance);
}
getTranspiler().transpile(resourceCasted, options, buffCode, optSourceMapData);
fsa.generateFile(filename, COMPILER_ID, buffCode.toString());
if (resourceCasted.getScript().getHashbang() != null) {
makeGeneratedFileExecutable(resourceCasted, filename);
}
if (createSourceMap) {
fsa.generateFile(sourceMapFileName, COMPILER_ID, optSourceMapData.get().sourceMapBuff.toString());
}
}
}
}
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class PreparationStep method prepare.
/**
* Creates and initializes the transpiler state. In particular, this will create the intermediate model as a copy of
* the original AST with some modifications (esp. rewiring of cross-references to ensure intermediate model is
* self-contained).
*
* @param options
* the {@link GeneratorOption generator options} to use during generation.
*/
public TranspilerState prepare(Script script, GeneratorOption[] options) {
final N4JSResource resource = (N4JSResource) script.eResource();
final N4JSProjectConfigSnapshot project = workspaceAccess.findProjectContaining(resource);
final ContainerTypesHelper.MemberCollector memberCollector = containerTypesHelper.fromContext(resource);
final Tracer tracer = new Tracer();
final InformationRegistry info = new InformationRegistry();
final STECache steCache = createIM(script, tracer, info);
final IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(resource);
return new TranspilerState(resource, project, options, memberCollector, steCache.im, steCache, tracer, info, index, workspaceAccess);
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class XpectN4JSES5TranspilerHelper method getCompiledFileBasePath.
private String getCompiledFileBasePath(final Script script) {
String path = N4JSLanguageConstants.DEFAULT_PROJECT_OUTPUT;
N4JSProjectConfigSnapshot project = workspaceAccess.findProjectContaining(script);
if (project != null) {
path = AbstractSubGenerator.calculateProjectBasedOutputDirectory(project, false);
}
return path;
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class AbstractTypeVisibilityChecker method isProjectVisible.
private boolean isProjectVisible(Resource contextResource, final IEObjectDescription element) {
if (contextResource != null) {
final TModule contextModule = N4JSResource.getModule(contextResource);
if (contextModule == null) {
return false;
}
N4JSProjectConfigSnapshot project = this.workspaceAccess.findProjectByNestedLocation(contextResource, element.getEObjectURI());
if (project == null) {
return true;
}
return Strings.equal(contextModule.getProjectID(), project.getName()) && Strings.equal(contextModule.getVendorID(), project.getVendorId()) || isTestedProjectOf(contextModule, project);
}
return false;
}
Aggregations