use of org.eclipse.n4js.smith.Measurement in project n4js by eclipse.
the class EcmaScriptSubGenerator method internalDoGenerate.
@Override
protected void internalDoGenerate(Resource resource, GeneratorOption[] options, IFileSystemAccess fsa) {
if (!(resource instanceof N4JSResource)) {
if (IN4JSProject.N4MF_MANIFEST.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;
}
Measurement measurement = this.collector.getMeasurement(resource.getURI().toString());
/*
* 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(fsa, getCompilerID(), resourceCasted);
final Path explicitNavigationToSrc = Paths.get("/sources");
// true use explicitNavigationToSrc | false use relativeNavigationToSrc
boolean useExplicitSourceRef = true;
boolean createSourceMap = true;
if (filename != null) {
final EObject root = rootElement(resource);
if (root != null) {
final Writer 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 = useExplicitSourceRef;
sourceMapDataInstance.explicitNavigationToSrc = explicitNavigationToSrc;
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 (createSourceMap) {
fsa.generateFile(sourceMapFileName, COMPILER_ID, optSourceMapData.get().sourceMapBuff.toString());
}
}
}
}
measurement.end();
}
Aggregations