mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 00:17:45 +00:00
[jdk9] forcing new rounds when compiling multiple modules didn’t work. (FilerException on creating the new round).
This commit is contained in:
1 parent
bb95ad218d
commit
55bcc142d0
3 files changed
+31
-11
No files matched your search
@@ -42,14 +42,14 @@ final class InterceptingJavaFileManager extends ForwardingJavaFileManager<JavaFi
|
||||
}
|
||||
|
||||
@Override public JavaFileObject getJavaFileForOutput(Location location, String className, final Kind kind, FileObject sibling) throws IOException {
|
||||
if (className.startsWith("lombok.dummy.ForceNewRound")) {
|
||||
if (className.contains("lombok.dummy.ForceNewRound")) {
|
||||
final String name = className.replace(".", "/") + kind.extension;
|
||||
return LombokFileObjects.createEmpty(compiler, name, kind);
|
||||
}
|
||||
|
||||
JavaFileObject fileObject = fileManager.getJavaFileForOutput(location, className, kind, sibling);
|
||||
if (kind != Kind.CLASS) {
|
||||
return fileObject;
|
||||
}
|
||||
if (kind != Kind.CLASS) return fileObject;
|
||||
|
||||
return LombokFileObjects.createIntercepting(compiler, fileObject, className, diagnostics);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2017 The Project Lombok Authors.
|
||||
* Copyright (C) 2009-2018 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -301,7 +301,10 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
|
||||
// Step 1: Take all CUs which aren't already in the map. Give them the first priority level.
|
||||
|
||||
String randomModuleName = null;
|
||||
|
||||
for (Element element : roundEnv.getRootElements()) {
|
||||
if (randomModuleName == null) randomModuleName = getModuleNameFor(element);
|
||||
JCCompilationUnit unit = toUnit(element);
|
||||
if (unit == null) continue;
|
||||
if (roots.containsKey(unit)) continue;
|
||||
@@ -344,20 +347,22 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
|
||||
if (newLevels.isEmpty()) return false;
|
||||
newLevels.retainAll(priorityLevelsRequiringResolutionReset);
|
||||
if (!newLevels.isEmpty()){
|
||||
if (!newLevels.isEmpty()) {
|
||||
// Force a new round to reset resolution. The next round will cause this method (process) to be called again.
|
||||
forceNewRound((JavacFiler) processingEnv.getFiler());
|
||||
forceNewRound(randomModuleName, (JavacFiler) processingEnv.getFiler());
|
||||
return false;
|
||||
}
|
||||
// None of the new levels need resolution, so just keep going.
|
||||
// None of the new levels need resolution, so just keep going.
|
||||
}
|
||||
}
|
||||
|
||||
private int dummyCount = 0;
|
||||
private void forceNewRound(JavacFiler filer) {
|
||||
private void forceNewRound(String randomModuleName, JavacFiler filer) {
|
||||
if (!filer.newFiles()) {
|
||||
try {
|
||||
JavaFileObject dummy = filer.createSourceFile("lombok.dummy.ForceNewRound" + (dummyCount++));
|
||||
String name = "lombok.dummy.ForceNewRound" + (dummyCount++);
|
||||
if (randomModuleName != null) name = randomModuleName + "/" + name;
|
||||
JavaFileObject dummy = filer.createSourceFile(name);
|
||||
Writer w = dummy.openWriter();
|
||||
w.close();
|
||||
} catch (Exception e) {
|
||||
@@ -368,6 +373,19 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private String getModuleNameFor(Element element) {
|
||||
while (element != null) {
|
||||
if (element.getKind().name().equals("MODULE")) {
|
||||
String n = element.getSimpleName().toString().trim();
|
||||
return n.isEmpty() ? null : n;
|
||||
}
|
||||
Element n = element.getEnclosingElement();
|
||||
if (n == element) return null;
|
||||
element = n;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JCCompilationUnit toUnit(Element element) {
|
||||
TreePath path = trees == null ? null : trees.getPath(element);
|
||||
if (path == null) return null;
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
</ul>
|
||||
Both are equally effective. Note that you will have to add lombok to your <code>module-info.java</code> file:<pre>
|
||||
module <em>myapp</em> {
|
||||
requires lombok;
|
||||
requires static lombok;
|
||||
}</pre>
|
||||
</p><p>
|
||||
The 'static' part ensures that you won't need lombok to be present at runtime.
|
||||
</p><p>
|
||||
Feedback about JDK9 module-info support can be given at <a href="https://github.com/rzwitserloot/lombok/issues/985">github issue #985</a>.
|
||||
</p>
|
||||
|
||||
Reference in new issue
Block a user