aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-10-10 20:41:29 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-10-10 23:24:04 +0200
commit08961edcfeef9b181621351e36bbc267f9395415 (patch)
tree8aa4f4ae8e6af3247a547d01bb1dee5f8e66cdf4
parent728dddbc81d9f9bfbbd3f8217b8c94f3f201c83d (diff)
downloadlombok-08961edcfeef9b181621351e36bbc267f9395415.tar.gz
lombok-08961edcfeef9b181621351e36bbc267f9395415.tar.bz2
lombok-08961edcfeef9b181621351e36bbc267f9395415.zip
Whoops, Classload errors running lombok on javac with backing JVM 7 or below; fixed.
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java78
-rw-r--r--src/delombok/lombok/delombok/DocCommentIntegrator.java15
-rw-r--r--src/utils/lombok/javac/Javac.java14
3 files changed, 69 insertions, 38 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 6d6426aa..50e80169 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -1323,51 +1323,61 @@ public class JavacHandlerUtil {
*
* in 'SETTER' mode, stripping works similarly to 'GETTER' mode, except {@code param} are copied and stripped from the original and {@code @return} are skipped.
*/
- @SuppressWarnings("unchecked")
public static void copyJavadoc(JavacNode from, JCTree to, CopyJavadoc copyMode) {
if (copyMode == null) copyMode = CopyJavadoc.VERBATIM;
try {
JCCompilationUnit cu = ((JCCompilationUnit) from.top().get());
Object dc = Javac.getDocComments(cu);
if (dc instanceof Map) {
- Map<JCTree, String> docComments = (Map<JCTree, String>) dc;
- String javadoc = docComments.get(from.get());
-
- if (javadoc != null) {
- String[] filtered = copyMode.split(javadoc);
- docComments.put(to, filtered[0]);
- docComments.put(from.get(), filtered[1]);
- }
- } else if (dc instanceof DocCommentTable) {
- DocCommentTable dct = (DocCommentTable) dc;
- Comment javadoc = dct.getComment(from.get());
-
- if (javadoc != null) {
- String[] filtered = copyMode.split(javadoc.getText());
- dct.putComment(to, createJavadocComment(filtered[0], from));
- dct.putComment(from.get(), createJavadocComment(filtered[1], from));
- }
+ copyJavadoc_jdk6_7(from, to, copyMode, dc);
+ } else if (Javac.instanceOfDocCommentTable(dc)) {
+ CopyJavadoc_8.copyJavadoc(from, to, copyMode, dc);
}
} catch (Exception ignore) {}
}
- private static Comment createJavadocComment(final String text, final JavacNode field) {
- return new Comment() {
- @Override public String getText() {
- return text;
- }
+ private static class CopyJavadoc_8 {
+ static void copyJavadoc(JavacNode from, JCTree to, CopyJavadoc copyMode, Object dc) {
+ DocCommentTable dct = (DocCommentTable) dc;
+ Comment javadoc = dct.getComment(from.get());
- @Override public int getSourcePos(int index) {
- return -1;
+ if (javadoc != null) {
+ String[] filtered = copyMode.split(javadoc.getText());
+ dct.putComment(to, createJavadocComment(filtered[0], from));
+ dct.putComment(from.get(), createJavadocComment(filtered[1], from));
}
-
- @Override public CommentStyle getStyle() {
- return CommentStyle.JAVADOC;
- }
-
- @Override public boolean isDeprecated() {
- return text.contains("@deprecated") && field.getKind() == Kind.FIELD && isFieldDeprecated(field);
- }
- };
+ }
+
+ private static Comment createJavadocComment(final String text, final JavacNode field) {
+ return new Comment() {
+ @Override public String getText() {
+ return text;
+ }
+
+ @Override public int getSourcePos(int index) {
+ return -1;
+ }
+
+ @Override public CommentStyle getStyle() {
+ return CommentStyle.JAVADOC;
+ }
+
+ @Override public boolean isDeprecated() {
+ return text.contains("@deprecated") && field.getKind() == Kind.FIELD && isFieldDeprecated(field);
+ }
+ };
+ }
+ }
+
+ @SuppressWarnings({"unchecked", "all"})
+ private static void copyJavadoc_jdk6_7(JavacNode from, JCTree to, CopyJavadoc copyMode, Object dc) {
+ Map<JCTree, String> docComments = (Map<JCTree, String>) dc;
+ String javadoc = docComments.get(from.get());
+
+ if (javadoc != null) {
+ String[] filtered = copyMode.split(javadoc);
+ docComments.put(to, filtered[0]);
+ docComments.put(from.get(), filtered[1]);
+ }
}
}
diff --git a/src/delombok/lombok/delombok/DocCommentIntegrator.java b/src/delombok/lombok/delombok/DocCommentIntegrator.java
index c1eb02b6..0955a003 100644
--- a/src/delombok/lombok/delombok/DocCommentIntegrator.java
+++ b/src/delombok/lombok/delombok/DocCommentIntegrator.java
@@ -66,7 +66,17 @@ public class DocCommentIntegrator {
if (map_ instanceof Map) {
((Map<JCTree, String>) map_).put(node, docCommentContent);
return true;
- } else if (map_ instanceof DocCommentTable) {
+ } else if (Javac.instanceOfDocCommentTable(map_)) {
+ CommentAttacher_8.attach(node, docCommentContent, map_);
+ return true;
+ }
+
+ return false;
+ }
+
+ /* Container for code which will cause class loader exceptions on javac below 8. By being in a separate class, we avoid the problem. */
+ private static class CommentAttacher_8 {
+ static void attach(final JCTree node, String docCommentContent, Object map_) {
final String docCommentContent_ = docCommentContent;
((DocCommentTable) map_).putComment(node, new Comment() {
@Override public String getText() {
@@ -85,10 +95,7 @@ public class DocCommentIntegrator {
return JavacHandlerUtil.nodeHasDeprecatedFlag(node);
}
});
- return true;
}
-
- return false;
}
private JCTree findJavadocableNodeOnOrAfter(JCCompilationUnit unit, int endPos) {
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index 554c778d..bdf5e7a0 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -103,6 +103,20 @@ public class Javac {
return 6;
}
+ private static final Class<?> DOCCOMMENTTABLE_CLASS;
+
+ static {
+ Class<?> c = null;
+ try {
+ c = Class.forName("com.sun.tools.javac.tree.DocCommentTable");
+ } catch (Throwable ignore) {}
+ DOCCOMMENTTABLE_CLASS = c;
+ }
+
+ public static boolean instanceOfDocCommentTable(Object o) {
+ return DOCCOMMENTTABLE_CLASS != null && DOCCOMMENTTABLE_CLASS.isInstance(o);
+ }
+
/**
* Checks if the given expression (that really ought to refer to a type
* expression) represents a primitive type.