aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-02-06 22:14:03 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-02-07 00:01:16 +0100
commit55bcc142d08ac8a4de0c3965333e3816c496799f (patch)
treef80823205b3bd3742565c23b788b1ec0f1987345
parentbb95ad218d29a9f5b1011b7c7b919ed41337a00b (diff)
downloadlombok-55bcc142d08ac8a4de0c3965333e3816c496799f.tar.gz
lombok-55bcc142d08ac8a4de0c3965333e3816c496799f.tar.bz2
lombok-55bcc142d08ac8a4de0c3965333e3816c496799f.zip
[jdk9] forcing new rounds when compiling multiple modules didn’t work. (FilerException on creating the new round).
-rw-r--r--src/core/lombok/javac/apt/InterceptingJavaFileManager.java8
-rw-r--r--src/core/lombok/javac/apt/LombokProcessor.java30
-rw-r--r--website/templates/setup/javac.html4
3 files changed, 31 insertions, 11 deletions
diff --git a/src/core/lombok/javac/apt/InterceptingJavaFileManager.java b/src/core/lombok/javac/apt/InterceptingJavaFileManager.java
index 303bdc2f..a9a4d200 100644
--- a/src/core/lombok/javac/apt/InterceptingJavaFileManager.java
+++ b/src/core/lombok/javac/apt/InterceptingJavaFileManager.java
@@ -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);
}
} \ No newline at end of file
diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java
index 5c7e47ee..9c0a2dfa 100644
--- a/src/core/lombok/javac/apt/LombokProcessor.java
+++ b/src/core/lombok/javac/apt/LombokProcessor.java
@@ -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;
diff --git a/website/templates/setup/javac.html b/website/templates/setup/javac.html
index 113be9c0..f90cb727 100644
--- a/website/templates/setup/javac.html
+++ b/website/templates/setup/javac.html
@@ -17,9 +17,11 @@
</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>
</@s.section>