Skip to content

Commit

Permalink
Make the listener a static inner class
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacomet authored and melix committed Apr 24, 2020
1 parent 68d01c5 commit 18a6bf9
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

public class IncrementalCompileTask implements JavaCompiler.CompilationTask {

private final Map<String, Collection<String>> mapping = new HashMap<>();
private final File mappingFile;
private final CompilationSourceDirs compilationSourceDirs;
private final JavaCompiler.CompilationTask delegate;
Expand Down Expand Up @@ -64,24 +63,30 @@ public void setLocale(Locale locale) {
@Override
public Boolean call() {
if (delegate instanceof JavacTask) {
TaskListener collector = new ClassNameCollector();
ClassNameCollector collector = new ClassNameCollector(compilationSourceDirs);
((JavacTask) delegate).addTaskListener(collector);
try {
return delegate.call();
} finally {
persistMappingFile(collector.getMapping());
}
} else {
throw new UnsupportedOperationException("Unexpected Java compile task : " + delegate.getClass().getName());
}
try {
return delegate.call();
} finally {
persistMappingFile();
}
}

void persistMappingFile() {
void persistMappingFile(Map<String, Collection<String>> mapping) {
SourceClassesMappingFileAccessor.writeSourceClassesMappingFile(mappingFile, mapping);
}

private class ClassNameCollector implements TaskListener {
private static class ClassNameCollector implements TaskListener {
private final Map<File, Optional<String>> relativePaths = new HashMap<>();
private final Map<String, Collection<String>> mapping = new HashMap<>();
private final CompilationSourceDirs compilationSourceDirs;

private ClassNameCollector(CompilationSourceDirs compilationSourceDirs) {
this.compilationSourceDirs = compilationSourceDirs;
}

@Override
public void started(TaskEvent e) {
Expand Down Expand Up @@ -145,5 +150,9 @@ public void registerMapping(String key, String symbol) {
}
symbols.add(symbol);
}

private Map<String, Collection<String>> getMapping() {
return mapping;
}
}
}

0 comments on commit 18a6bf9

Please sign in to comment.