Search in sources :

Example 1 with SourceProcessor

use of separate.SourceModel.SourceProcessor in project jdk8u_jdk by JetBrains.

the class Compiler method compileOne.

private File compileOne(Type type) {
    if (this.flags.contains(Flags.USECACHE)) {
        File dir = cache.get(type.getName());
        if (dir != null) {
            return dir;
        }
    }
    List<JavaFileObject> files = new ArrayList<>();
    SourceProcessor accum = (name, src) -> files.add(new SourceFile(name, src));
    for (Type dep : type.typeDependencies()) {
        dep.generateAsDependency(accum, type.methodDependencies());
    }
    type.generate(accum);
    JavacTask ct = (JavacTask) this.systemJavaCompiler.getTask(null, this.fm, null, null, null, files);
    File destDir = null;
    do {
        int value = counter.incrementAndGet();
        destDir = new File(root, Integer.toString(value));
    } while (destDir.exists());
    if (this.flags.contains(Flags.VERBOSE)) {
        System.out.println("Compilation unit for " + type.getName() + " : compiled into " + destDir);
        for (JavaFileObject jfo : files) {
            System.out.println(jfo.toString());
        }
    }
    try {
        destDir.mkdirs();
        this.fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
    } catch (IOException e) {
        throw new RuntimeException("IOException encountered during compilation");
    }
    Boolean result = ct.call();
    if (result == Boolean.FALSE) {
        throw new RuntimeException("Compilation failure in " + type.getName() + " unit");
    }
    if (this.flags.contains(Flags.USECACHE)) {
        File existing = cache.putIfAbsent(type.getName(), destDir);
        if (existing != null) {
            deleteDir(destDir);
            return existing;
        }
    } else {
        this.tempDirs.add(destDir);
    }
    return destDir;
}
Also used : java.util(java.util) Type(separate.SourceModel.Type) JavacTask(com.sun.source.util.JavacTask) Files(java.nio.file.Files) javax.tools(javax.tools) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Class(separate.SourceModel.Class) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) FileVisitResult(java.nio.file.FileVisitResult) java.io(java.io) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SourceProcessor(separate.SourceModel.SourceProcessor) URI(java.net.URI) Path(java.nio.file.Path) Extends(separate.SourceModel.Extends) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) SourceProcessor(separate.SourceModel.SourceProcessor) Type(separate.SourceModel.Type) JavacTask(com.sun.source.util.JavacTask)

Aggregations

JavacTask (com.sun.source.util.JavacTask)1 java.io (java.io)1 URI (java.net.URI)1 FileVisitResult (java.nio.file.FileVisitResult)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 java.util (java.util)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 javax.tools (javax.tools)1 Class (separate.SourceModel.Class)1 Extends (separate.SourceModel.Extends)1 SourceProcessor (separate.SourceModel.SourceProcessor)1 Type (separate.SourceModel.Type)1