Search in sources :

Example 6 with SpoonFile

use of spoon.compiler.SpoonFile in project spoon by INRIA.

the class SourceOptions method sources.

/**
 * adds the given {@link spoon.compiler.SpoonFile} as sources
 */
public T sources(List<SpoonFile> sources) {
    if (sources == null || sources.size() == 0) {
        args.add(".");
        return myself;
    }
    for (SpoonFile source : sources) {
        if (source.isActualFile()) {
            args.add(source.toString());
        } else {
            try {
                File file = File.createTempFile(source.getName(), ".java");
                file.deleteOnExit();
                IOUtils.copy(source.getContent(), new FileOutputStream(file));
                args.add(file.toString());
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    }
    return myself;
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) SpoonFile(spoon.compiler.SpoonFile) SpoonFile(spoon.compiler.SpoonFile) File(java.io.File)

Aggregations

SpoonFile (spoon.compiler.SpoonFile)6 File (java.io.File)3 SpoonException (spoon.SpoonException)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)1 CompilationUnit (org.eclipse.jdt.internal.compiler.batch.CompilationUnit)1 InvalidClassPathException (spoon.compiler.InvalidClassPathException)1 SpoonFolder (spoon.compiler.SpoonFolder)1 AdvancedOptions (spoon.compiler.builder.AdvancedOptions)1 ClasspathOptions (spoon.compiler.builder.ClasspathOptions)1 ComplianceOptions (spoon.compiler.builder.ComplianceOptions)1 JDTBuilderImpl (spoon.compiler.builder.JDTBuilderImpl)1 SourceOptions (spoon.compiler.builder.SourceOptions)1 FileSystemFolder (spoon.support.compiler.FileSystemFolder)1