use of com.google.devtools.j2objc.gen.GenerationUnit in project j2objc by google.
the class GenerationTest method translateCombinedFiles.
protected String translateCombinedFiles(String outputPath, String extension, String... sources) throws IOException {
List<ProcessingContext> inputs = new ArrayList<>();
GenerationUnit genUnit = GenerationUnit.newCombinedJarUnit(outputPath + ".testfile", options);
for (String sourceFile : sources) {
inputs.add(new ProcessingContext(new RegularInputFile(tempDir + "/" + sourceFile, sourceFile), genUnit));
}
parser.setEnableDocComments(options.docCommentsEnabled());
new InputFilePreprocessor(parser).processInputs(inputs);
new TranslationProcessor(parser, CodeReferenceMap.builder().build()).processInputs(inputs);
return getTranslatedFile(outputPath + extension);
}
use of com.google.devtools.j2objc.gen.GenerationUnit in project j2objc by google.
the class GenerationBatch method processJarFile.
private void processJarFile(String filename) {
File f = findJarFile(filename);
if (f == null) {
ErrorUtil.error("No such file: " + filename);
return;
}
// don't support Java-like source paths.
if (options.emitLineDirectives() && options.isVerbose()) {
ErrorUtil.warning("source debugging of jar files is not supported: " + filename);
}
GenerationUnit combinedUnit = null;
if (globalCombinedUnit != null) {
combinedUnit = globalCombinedUnit;
} else if (options.getHeaderMap().combineSourceJars()) {
combinedUnit = GenerationUnit.newCombinedJarUnit(filename, options);
}
try {
ZipFile zfile = new ZipFile(f);
try {
boolean containsJavaFile = false;
Enumeration<? extends ZipEntry> enumerator = zfile.entries();
File tempDir = FileUtil.createTempDir(J2OBJC_TEMP_DIR_PREFIX);
String tempDirPath = tempDir.getAbsolutePath();
options.fileUtil().addTempDir(tempDirPath);
options.fileUtil().appendSourcePath(tempDirPath);
while (enumerator.hasMoreElements()) {
ZipEntry entry = enumerator.nextElement();
String internalPath = entry.getName();
if (internalPath.endsWith(".java") || (options.translateClassfiles() && internalPath.endsWith(".class"))) {
// Extract JAR file to a temporary directory
File outputFile = options.fileUtil().extractZipEntry(tempDir, zfile, entry);
InputFile newFile = new RegularInputFile(outputFile.getAbsolutePath(), internalPath);
if (combinedUnit != null) {
inputs.add(new ProcessingContext(newFile, combinedUnit));
} else {
addExtractedJarSource(newFile, filename, internalPath);
}
containsJavaFile = true;
}
}
if (!options.translateClassfiles() && !containsJavaFile) {
ErrorUtil.error(filename + " does not contain any Java source files.");
}
} finally {
// Also closes input stream.
zfile.close();
}
} catch (ZipException e) {
// Also catches JarExceptions
logger.fine(e.getMessage());
ErrorUtil.error("Error reading file " + filename + " as a zip or jar file.");
} catch (IOException e) {
ErrorUtil.error(e.getMessage());
}
}
use of com.google.devtools.j2objc.gen.GenerationUnit in project j2objc by google.
the class ProcessingContext method fromFile.
public static ProcessingContext fromFile(InputFile file, Options options) {
Options.CombinedOutput globalOutput = options.globalCombinedOutput();
GenerationUnit newGenUnit = globalOutput != null ? globalOutput.globalGenerationUnit() : GenerationUnit.newSingleFileUnit(file, options);
return new ProcessingContext(file, newGenUnit);
}
use of com.google.devtools.j2objc.gen.GenerationUnit in project j2objc by google.
the class ProcessingContext method fromExtractedJarEntry.
public static ProcessingContext fromExtractedJarEntry(InputFile file, String sourceName, Options options) {
Options.CombinedOutput globalOutput = options.globalCombinedOutput();
GenerationUnit newGenUnit = globalOutput != null ? globalOutput.globalGenerationUnit() : GenerationUnit.newSingleExtractedJarEntryUnit(file, sourceName, options);
return new ProcessingContext(file, newGenUnit);
}
use of com.google.devtools.j2objc.gen.GenerationUnit in project j2objc by google.
the class TranslationProcessor method processConvertedTree.
@Override
protected void processConvertedTree(ProcessingContext input, CompilationUnit unit) {
String unitName = input.getOriginalSourcePath();
if (logger.isLoggable(Level.INFO)) {
System.out.println("translating " + unitName);
}
TimeTracker ticker = TimeTracker.getTicker(unitName, options.timingLevel());
if (options.dumpAST()) {
// Dump compilation unit to an .ast output file instead of translating.
DebugASTDump.dumpUnit(unit);
} else {
applyMutations(unit, deadCodeMap, options.externalAnnotations(), ticker);
ticker.tick("Tree mutations");
ticker.printResults(System.out);
GenerationUnit genUnit = input.getGenerationUnit();
genUnit.addCompilationUnit(unit);
outputs.add(genUnit);
// Add out-of-date dependencies to translation list.
if (closureQueue != null) {
checkDependencies(unit);
}
}
processedCount++;
}
Aggregations