use of com.google.devtools.j2objc.file.RegularInputFile in project j2objc by google.
the class CycleFinder method stripIncompatible.
private File stripIncompatible(List<String> sourceFileNames, Parser parser) throws IOException {
File strippedDir = null;
for (int i = 0; i < sourceFileNames.size(); i++) {
String fileName = sourceFileNames.get(i);
RegularInputFile file = new RegularInputFile(fileName);
String source = j2objcOptions.fileUtil().readFile(file);
if (!source.contains("J2ObjCIncompatible")) {
continue;
}
if (strippedDir == null) {
strippedDir = Files.createTempDir();
parser.prependSourcepathEntry(strippedDir.getPath());
}
Parser.ParseResult parseResult = parser.parseWithoutBindings(file, source);
String qualifiedName = parseResult.mainTypeName();
parseResult.stripIncompatibleSource();
String relativePath = qualifiedName.replace('.', File.separatorChar) + ".java";
File strippedFile = new File(strippedDir, relativePath);
Files.createParentDirs(strippedFile);
Files.write(parseResult.getSource(), strippedFile, Charset.forName(options.fileEncoding()));
sourceFileNames.set(i, strippedFile.getPath());
}
return strippedDir;
}
use of com.google.devtools.j2objc.file.RegularInputFile in project j2objc by google.
the class FileUtil method findOnPaths.
private static InputFile findOnPaths(String qualifiedName, List<String> paths, String extension) throws IOException {
String sourceFileName = qualifiedName.replace('.', File.separatorChar) + extension;
// Zip/jar files always use forward slashes.
String jarEntryName = qualifiedName.replace('.', '/') + extension;
for (String pathEntry : paths) {
File f = new File(pathEntry);
if (f.isDirectory()) {
RegularInputFile regularFile = new RegularInputFile(pathEntry + File.separatorChar + sourceFileName, sourceFileName);
if (regularFile.exists()) {
return regularFile;
}
} else {
// Assume it's a jar file
JarredInputFile jarFile = new JarredInputFile(pathEntry, jarEntryName);
if (jarFile.exists()) {
return jarFile;
}
}
}
return null;
}
use of com.google.devtools.j2objc.file.RegularInputFile in project j2objc by google.
the class TranslationProcessorTest method testSingleSourceFileBuildClosure.
public void testSingleSourceFileBuildClosure() throws IOException {
options.setBuildClosure(true);
addSourceFile("class Test { }", "Test.java");
GenerationBatch batch = new GenerationBatch(options);
batch.addSource(new RegularInputFile(getTempDir() + "/Test.java", "Test.java"));
TranslationProcessor processor = new TranslationProcessor(J2ObjC.createParser(options), null);
processor.processInputs(batch.getInputs());
processor.processBuildClosureDependencies();
String translation = getTranslatedFile("Test.h");
assertTranslation(translation, "@interface Test");
assertErrorCount(0);
assertWarningCount(0);
}
use of com.google.devtools.j2objc.file.RegularInputFile 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.file.RegularInputFile in project j2objc by google.
the class TreeShaker method stripIncompatible.
private File stripIncompatible(List<String> sourceFileNames, Parser parser) throws IOException {
File strippedDir = null;
for (int i = 0; i < sourceFileNames.size(); i++) {
String fileName = sourceFileNames.get(i);
RegularInputFile file = new RegularInputFile(fileName);
String source = j2objcOptions.fileUtil().readFile(file);
if (!source.contains("J2ObjCIncompatible")) {
continue;
}
if (strippedDir == null) {
strippedDir = Files.createTempDir();
parser.prependSourcepathEntry(strippedDir.getPath());
}
Parser.ParseResult parseResult = parser.parseWithoutBindings(file, source);
String qualifiedName = parseResult.mainTypeName();
parseResult.stripIncompatibleSource();
String relativePath = qualifiedName.replace('.', File.separatorChar) + ".java";
File strippedFile = new File(strippedDir, relativePath);
Files.createParentDirs(strippedFile);
Files.write(parseResult.getSource(), strippedFile, j2objcOptions.fileUtil().getCharset());
sourceFileNames.set(i, strippedFile.getPath());
}
return strippedDir;
}
Aggregations