Search in sources :

Example 1 with RegularInputFile

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;
}
Also used : RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) File(java.io.File) Parser(com.google.devtools.j2objc.util.Parser)

Example 2 with RegularInputFile

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;
}
Also used : RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) InputFile(com.google.devtools.j2objc.file.InputFile) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) File(java.io.File) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile) ZipFile(java.util.zip.ZipFile) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile)

Example 3 with RegularInputFile

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);
}
Also used : RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile)

Example 4 with RegularInputFile

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);
}
Also used : ProcessingContext(com.google.devtools.j2objc.pipeline.ProcessingContext) GenerationUnit(com.google.devtools.j2objc.gen.GenerationUnit) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) TranslationProcessor(com.google.devtools.j2objc.pipeline.TranslationProcessor) ArrayList(java.util.ArrayList) InputFilePreprocessor(com.google.devtools.j2objc.pipeline.InputFilePreprocessor)

Example 5 with RegularInputFile

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;
}
Also used : RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) File(java.io.File) ProGuardUsageParser(com.google.devtools.j2objc.util.ProGuardUsageParser) Parser(com.google.devtools.j2objc.util.Parser)

Aggregations

RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)12 File (java.io.File)5 InputFile (com.google.devtools.j2objc.file.InputFile)4 Parser (com.google.devtools.j2objc.util.Parser)3 IOException (java.io.IOException)3 GenerationUnit (com.google.devtools.j2objc.gen.GenerationUnit)2 InputFilePreprocessor (com.google.devtools.j2objc.pipeline.InputFilePreprocessor)2 ParserEnvironment (com.google.devtools.j2objc.util.ParserEnvironment)2 TranslationEnvironment (com.google.devtools.j2objc.util.TranslationEnvironment)2 ZipFile (java.util.zip.ZipFile)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 JarredInputFile (com.google.devtools.j2objc.file.JarredInputFile)1 GenerationBatch (com.google.devtools.j2objc.pipeline.GenerationBatch)1 ProcessingContext (com.google.devtools.j2objc.pipeline.ProcessingContext)1 TranslationProcessor (com.google.devtools.j2objc.pipeline.TranslationProcessor)1 ProGuardUsageParser (com.google.devtools.j2objc.util.ProGuardUsageParser)1 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 ZipException (java.util.zip.ZipException)1 ASTParser (org.eclipse.jdt.core.dom.ASTParser)1