Search in sources :

Example 1 with Type

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

the class Compiler method compile.

/**
     * Compile hierarchies starting with each of the 'types' and return
     * a ClassLoader that can be used to load the compiled classes.
     */
public ClassLoader compile(Type... types) {
    ClassFilePreprocessor[] cfps = this.postprocessors.toArray(new ClassFilePreprocessor[0]);
    DirectedClassLoader dcl = new DirectedClassLoader(cfps);
    for (Type t : types) {
        for (Map.Entry<String, File> each : compileHierarchy(t).entrySet()) {
            dcl.setLocationFor(each.getKey(), each.getValue());
        }
    }
    return dcl;
}
Also used : Type(separate.SourceModel.Type) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with Type

use of separate.SourceModel.Type 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)

Example 3 with Type

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

the class Compiler method compileHierarchy.

/**
     * Compiles a hierarchy, starting at 'type' and return a mapping of the
     * name to the location where the classfile for that type resides.
     */
private Map<String, File> compileHierarchy(Type type) {
    HashMap<String, File> outputDirs = new HashMap<>();
    File outDir = compileOne(type);
    outputDirs.put(type.getName(), outDir);
    Class superClass = type.getSuperclass();
    if (superClass != null) {
        for (Map.Entry<String, File> each : compileHierarchy(superClass).entrySet()) {
            outputDirs.put(each.getKey(), each.getValue());
        }
    }
    for (Extends ext : type.getSupertypes()) {
        Type iface = ext.getType();
        for (Map.Entry<String, File> each : compileHierarchy(iface).entrySet()) {
            outputDirs.put(each.getKey(), each.getValue());
        }
    }
    return outputDirs;
}
Also used : Type(separate.SourceModel.Type) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Class(separate.SourceModel.Class) Extends(separate.SourceModel.Extends) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Type (separate.SourceModel.Type)3 Class (separate.SourceModel.Class)2 Extends (separate.SourceModel.Extends)2 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 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 javax.tools (javax.tools)1 SourceProcessor (separate.SourceModel.SourceProcessor)1