use of com.google.devtools.j2objc.pipeline.ProcessingContext 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.pipeline.ProcessingContext in project j2objc by google.
the class JavacParser method processAnnotations.
@Override
public ProcessingResult processAnnotations(Iterable<String> fileArgs, List<ProcessingContext> inputs) {
final List<ProcessingContext> generatedInputs = Lists.newArrayList();
PathClassLoader loader = new PathClassLoader(options.fileUtil().getClassPathEntries());
loader.addPaths(options.getProcessorPathEntries());
Iterator<Processor> serviceIterator = ServiceLoader.load(Processor.class, loader).iterator();
if (serviceIterator.hasNext()) {
List<File> inputFiles = new ArrayList<>();
for (ProcessingContext input : inputs) {
inputFiles.add(new File(input.getFile().getAbsolutePath()));
}
try {
JavacEnvironment env = createEnvironment(inputFiles, null, true);
List<CompilationUnitTree> units = new ArrayList<>();
for (CompilationUnitTree unit : env.task().parse()) {
units.add(unit);
}
// JavacTaskImpl.enter() parses and runs annotation processing, but
// not type checking and attribution (that's done by analyze()).
env.task().enter();
processDiagnostics(env.diagnostics());
// The source output directory is created and set in createEnvironment().
File sourceOutputDirectory = env.fileManager().getLocation(StandardLocation.SOURCE_OUTPUT).iterator().next();
collectGeneratedInputs(sourceOutputDirectory, "", generatedInputs);
return new JavacProcessingResult(generatedInputs, sourceOutputDirectory);
} catch (IOException e) {
ErrorUtil.fatalError(e, "javac file manager error");
}
}
// No annotation processors on classpath, or processing errors reported.
return new JavacProcessingResult(generatedInputs, null);
}
use of com.google.devtools.j2objc.pipeline.ProcessingContext in project j2objc by google.
the class J2ObjC method run.
/**
* Runs the entire J2ObjC pipeline.
* @param fileArgs the files to process, same format as command-line args to {@link #main}.
*/
public static void run(List<String> fileArgs, Options options) {
File preProcessorTempDir = null;
File strippedSourcesDir = null;
Parser parser = null;
try {
List<ProcessingContext> inputs = Lists.newArrayList();
GenerationBatch batch = new GenerationBatch(options);
batch.processFileArgs(fileArgs);
inputs.addAll(batch.getInputs());
if (ErrorUtil.errorCount() > 0) {
return;
}
parser = createParser(options);
Parser.ProcessingResult processingResult = parser.processAnnotations(fileArgs, inputs);
List<ProcessingContext> generatedInputs = processingResult.getGeneratedSources();
// Ensure all generatedInputs are at end of input list.
inputs.addAll(generatedInputs);
preProcessorTempDir = processingResult.getSourceOutputDirectory();
if (ErrorUtil.errorCount() > 0) {
return;
}
if (preProcessorTempDir != null) {
parser.addSourcepathEntry(preProcessorTempDir.getAbsolutePath());
}
InputFilePreprocessor inputFilePreprocessor = new InputFilePreprocessor(parser);
inputFilePreprocessor.processInputs(inputs);
if (ErrorUtil.errorCount() > 0) {
return;
}
strippedSourcesDir = inputFilePreprocessor.getStrippedSourcesDir();
if (strippedSourcesDir != null) {
parser.prependSourcepathEntry(strippedSourcesDir.getPath());
}
options.getHeaderMap().loadMappings();
TranslationProcessor translationProcessor = new TranslationProcessor(parser, loadDeadCodeMap());
translationProcessor.processInputs(inputs);
translationProcessor.processBuildClosureDependencies();
if (ErrorUtil.errorCount() > 0) {
return;
}
translationProcessor.postProcess();
options.getHeaderMap().printMappings();
} finally {
if (parser != null) {
try {
parser.close();
} catch (IOException e) {
ErrorUtil.error(e.getMessage());
}
}
Set<String> tempDirs = options.fileUtil().getTempDirs();
for (String dir : tempDirs) {
FileUtil.deleteTempDir(new File(dir));
}
FileUtil.deleteTempDir(preProcessorTempDir);
FileUtil.deleteTempDir(strippedSourcesDir);
}
}
Aggregations