equal
deleted
inserted
replaced
44 public enum Flags { |
44 public enum Flags { |
45 VERBOSE, // Prints out files as they are compiled |
45 VERBOSE, // Prints out files as they are compiled |
46 USECACHE // Keeps results around for reuse. Only use this is |
46 USECACHE // Keeps results around for reuse. Only use this is |
47 // you're sure that each compilation name maps to the |
47 // you're sure that each compilation name maps to the |
48 // same source code |
48 // same source code |
49 }; |
49 } |
50 |
50 |
51 private static final AtomicInteger counter = new AtomicInteger(); |
51 private static final AtomicInteger counter = new AtomicInteger(); |
52 private static final String targetDir = "gen-separate"; |
52 private static final String targetDir = "gen-separate"; |
53 private static final File root = new File(targetDir); |
53 private static final File root = new File(targetDir); |
54 private static ConcurrentHashMap<String,File> cache = |
54 private static ConcurrentHashMap<String,File> cache = |
83 this.systemJavaCompiler = ToolProvider.getSystemJavaCompiler(); |
83 this.systemJavaCompiler = ToolProvider.getSystemJavaCompiler(); |
84 this.fm = systemJavaCompiler.getStandardFileManager(null, null, null); |
84 this.fm = systemJavaCompiler.getStandardFileManager(null, null, null); |
85 } |
85 } |
86 |
86 |
87 public void setFlags(Flags ... flags) { |
87 public void setFlags(Flags ... flags) { |
88 this.flags = new HashSet<Flags>(Arrays.asList(flags)); |
88 this.flags = new HashSet<>(Arrays.asList(flags)); |
89 } |
89 } |
90 |
90 |
91 public void addPostprocessor(ClassFilePreprocessor cfp) { |
91 public void addPostprocessor(ClassFilePreprocessor cfp) { |
92 this.postprocessors.add(cfp); |
92 this.postprocessors.add(cfp); |
93 } |
93 } |
129 |
129 |
130 File outDir = compileOne(type); |
130 File outDir = compileOne(type); |
131 outputDirs.put(type.getName(), outDir); |
131 outputDirs.put(type.getName(), outDir); |
132 |
132 |
133 Class superClass = type.getSuperclass(); |
133 Class superClass = type.getSuperclass(); |
134 if (superClass != null) { |
134 if (superClass != null) |
135 for( Map.Entry<String,File> each : compileHierarchy(superClass).entrySet()) { |
135 outputDirs.putAll(compileHierarchy(superClass)); |
136 outputDirs.put(each.getKey(), each.getValue()); |
136 for (Extends ext : type.getSupertypes()) |
137 } |
137 outputDirs.putAll(compileHierarchy(ext.getType())); |
138 } |
|
139 for (Extends ext : type.getSupertypes()) { |
|
140 Type iface = ext.getType(); |
|
141 for( Map.Entry<String,File> each : compileHierarchy(iface).entrySet()) { |
|
142 outputDirs.put(each.getKey(), each.getValue()); |
|
143 } |
|
144 } |
|
145 |
138 |
146 return outputDirs; |
139 return outputDirs; |
147 } |
140 } |
148 |
141 |
149 private File compileOne(Type type) { |
142 private File compileOne(Type type) { |
155 } |
148 } |
156 List<JavaFileObject> files = new ArrayList<>(); |
149 List<JavaFileObject> files = new ArrayList<>(); |
157 SourceProcessor accum = |
150 SourceProcessor accum = |
158 (name, src) -> { files.add(new SourceFile(name, src)); }; |
151 (name, src) -> { files.add(new SourceFile(name, src)); }; |
159 |
152 |
160 for (Type dep : type.typeDependencies()) { |
153 Collection<Type> deps = type.typeDependencies(type.isFullCompilation()); |
161 dep.generateAsDependency(accum, type.methodDependencies()); |
154 for (Type dep : deps) { |
|
155 if (type.isFullCompilation()) |
|
156 dep.generate(accum); |
|
157 else |
|
158 dep.generateAsDependency(accum, type.methodDependencies()); |
162 } |
159 } |
163 |
160 |
164 type.generate(accum); |
161 type.generate(accum); |
165 |
162 |
166 JavacTask ct = (JavacTask)this.systemJavaCompiler.getTask( |
163 JavacTask ct = (JavacTask)this.systemJavaCompiler.getTask( |
183 destDir.mkdirs(); |
180 destDir.mkdirs(); |
184 this.fm.setLocation( |
181 this.fm.setLocation( |
185 StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir)); |
182 StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir)); |
186 } catch (IOException e) { |
183 } catch (IOException e) { |
187 throw new RuntimeException( |
184 throw new RuntimeException( |
188 "IOException encountered during compilation"); |
185 "IOException encountered during compilation", e); |
189 } |
186 } |
190 Boolean result = ct.call(); |
187 Boolean result = ct.call(); |
191 if (result == Boolean.FALSE) { |
188 if (result == Boolean.FALSE) { |
192 throw new RuntimeException( |
189 throw new RuntimeException( |
193 "Compilation failure in " + type.getName() + " unit"); |
190 "Compilation failure in " + type.getName() + " unit"); |