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;
}
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;
}
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;
}
Aggregations