Search in sources :

Example 1 with JDTBuilderImpl

use of spoon.compiler.builder.JDTBuilderImpl in project spoon by INRIA.

the class JDTBasedSpoonCompiler method buildUnits.

/**
 * Build the CompilationUnit found in the source folder
 * @param jdtBuilder The instance of JDTBuilder to prepare the right JDT arguments
 * @param sourcesFolder The source folder
 * @param classpath The complete classpath
 * @param debugMessagePrefix Useful to help debugging
 * @return All compilationUnitDeclaration from JDT found in source folder
 */
protected CompilationUnitDeclaration[] buildUnits(JDTBuilder jdtBuilder, SpoonFolder sourcesFolder, String[] classpath, String debugMessagePrefix) {
    List<SpoonFile> sourceFiles = Collections.unmodifiableList(sourcesFolder.getAllJavaFiles());
    if (sourceFiles.isEmpty()) {
        return EMPTY_RESULT;
    }
    JDTBatchCompiler batchCompiler = createBatchCompiler(new FileCompilerConfig(sourceFiles));
    String[] args;
    if (jdtBuilder == null) {
        args = // 
        new JDTBuilderImpl().classpathOptions(// 
        new ClasspathOptions().encoding(this.getEnvironment().getEncoding().displayName()).classpath(classpath)).complianceOptions(// 
        new ComplianceOptions().compliance(javaCompliance)).advancedOptions(// 
        new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()).sources(// no sources, handled by the JDTBatchCompiler
        new SourceOptions().sources(sourceFiles)).build();
    } else {
        args = jdtBuilder.build();
    }
    getFactory().getEnvironment().debugMessage(debugMessagePrefix + "build args: " + Arrays.toString(args));
    batchCompiler.configure(args);
    CompilationUnitDeclaration[] units = batchCompiler.getUnits();
    return units;
}
Also used : SourceOptions(spoon.compiler.builder.SourceOptions) ComplianceOptions(spoon.compiler.builder.ComplianceOptions) SpoonFile(spoon.compiler.SpoonFile) ClasspathOptions(spoon.compiler.builder.ClasspathOptions) AdvancedOptions(spoon.compiler.builder.AdvancedOptions) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) JDTBuilderImpl(spoon.compiler.builder.JDTBuilderImpl)

Example 2 with JDTBuilderImpl

use of spoon.compiler.builder.JDTBuilderImpl in project spoon by INRIA.

the class JDTBasedSpoonCompiler method compile.

@Override
public boolean compile(InputType... types) {
    factory.getEnvironment().debugMessage("compiling sources: " + factory.CompilationUnit().getMap().keySet());
    long t = System.currentTimeMillis();
    javaCompliance = factory.getEnvironment().getComplianceLevel();
    JDTBatchCompiler batchCompiler = createBatchCompiler(types);
    final String[] args = // 
    new JDTBuilderImpl().classpathOptions(// 
    new ClasspathOptions().encoding(this.getEnvironment().getEncoding().displayName()).classpath(getSourceClasspath()).binaries(getBinaryOutputDirectory())).complianceOptions(// 
    new ComplianceOptions().compliance(javaCompliance)).annotationProcessingOptions(// 
    new AnnotationProcessingOptions().compileProcessors()).advancedOptions(// 
    new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()).sources(// no sources, handled by the JDTBatchCompiler
    new SourceOptions().sources(sources.getAllJavaFiles())).build();
    getFactory().getEnvironment().debugMessage("compile args: " + Arrays.toString(args));
    System.setProperty("jdt.compiler.useSingleThread", "true");
    batchCompiler.compile(args);
    reportProblems(factory.getEnvironment());
    factory.getEnvironment().debugMessage("compiled in " + (System.currentTimeMillis() - t) + " ms");
    return probs.size() == 0;
}
Also used : AdvancedOptions(spoon.compiler.builder.AdvancedOptions) AnnotationProcessingOptions(spoon.compiler.builder.AnnotationProcessingOptions) SourceOptions(spoon.compiler.builder.SourceOptions) JDTBuilderImpl(spoon.compiler.builder.JDTBuilderImpl) ComplianceOptions(spoon.compiler.builder.ComplianceOptions) ClasspathOptions(spoon.compiler.builder.ClasspathOptions)

Example 3 with JDTBuilderImpl

use of spoon.compiler.builder.JDTBuilderImpl in project spoon by INRIA.

the class JDTBuilderTest method testJdtBuilder.

@Test
public void testJdtBuilder() throws Exception {
    final String[] builder = // 
    new JDTBuilderImpl().classpathOptions(// 
    new ClasspathOptions().classpath(TEST_CLASSPATH).bootclasspath(TEST_CLASSPATH).binaries(".").encoding("UTF-8")).complianceOptions(// 
    new ComplianceOptions().compliance(8)).annotationProcessingOptions(// 
    new AnnotationProcessingOptions().compileProcessors()).advancedOptions(// 
    new AdvancedOptions().continueExecution().enableJavadoc().preserveUnusedVars()).sources(// 
    new SourceOptions().sources(".")).build();
    assertEquals("-cp", builder[0]);
    assertEquals(TEST_CLASSPATH, builder[1]);
    assertEquals("-bootclasspath", builder[2]);
    assertEquals(TEST_CLASSPATH, builder[3]);
    assertEquals("-d", builder[4]);
    assertEquals(new File(".").getAbsolutePath(), builder[5]);
    assertEquals("-encoding", builder[6]);
    assertEquals("UTF-8", builder[7]);
    assertEquals("-1.8", builder[8]);
    assertEquals("-proc:none", builder[9]);
    assertEquals("-noExit", builder[10]);
    assertEquals("-enableJavadoc", builder[11]);
    assertEquals("-preserveAllLocals", builder[12]);
    assertEquals(".", builder[13]);
}
Also used : AdvancedOptions(spoon.compiler.builder.AdvancedOptions) AnnotationProcessingOptions(spoon.compiler.builder.AnnotationProcessingOptions) SourceOptions(spoon.compiler.builder.SourceOptions) JDTBuilderImpl(spoon.compiler.builder.JDTBuilderImpl) ComplianceOptions(spoon.compiler.builder.ComplianceOptions) File(java.io.File) ClasspathOptions(spoon.compiler.builder.ClasspathOptions) Test(org.junit.Test)

Aggregations

AdvancedOptions (spoon.compiler.builder.AdvancedOptions)3 ClasspathOptions (spoon.compiler.builder.ClasspathOptions)3 ComplianceOptions (spoon.compiler.builder.ComplianceOptions)3 JDTBuilderImpl (spoon.compiler.builder.JDTBuilderImpl)3 SourceOptions (spoon.compiler.builder.SourceOptions)3 AnnotationProcessingOptions (spoon.compiler.builder.AnnotationProcessingOptions)2 File (java.io.File)1 CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)1 Test (org.junit.Test)1 SpoonFile (spoon.compiler.SpoonFile)1