aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:51:33 +0200
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:51:33 +0200
commit1b534d17d39f687d42ebab733327a59c3466a949 (patch)
treed24e04a9c95b0caa0df855fb5d20b63730fc7707 /src/core/lombok/eclipse/handlers
parenteadd3b8ccea16d46249e6b01c4ac4b295c691abd (diff)
downloadlombok-1b534d17d39f687d42ebab733327a59c3466a949.tar.gz
lombok-1b534d17d39f687d42ebab733327a59c3466a949.tar.bz2
lombok-1b534d17d39f687d42ebab733327a59c3466a949.zip
Untangling patches to classes that only exist in eclipse, not ecj
Specifically, Rawi01's patches to make javadoc behaviour in eclipse better, which cannot be applied to ecj as you get load errors (javadoc not a thing there). As part of this commit, tests can be limited to ecj or eclipse, and I made cut-down versions of a few tests (to run on ecj, as the main one cannot be, due to javadoc issues). The tests now marked as eclipse only don't fail on ecj, but they don't generate the same result. Alternatively, we could go with a separated out after-ecj and after-eclipse dir instead, but that's perhaps going overboard.
Diffstat (limited to 'src/core/lombok/eclipse/handlers')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index d85c2ee8..03f26341 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -23,7 +23,7 @@ package lombok.eclipse.handlers;
import static lombok.core.handlers.HandlerUtil.*;
import static lombok.eclipse.Eclipse.*;
-import static lombok.eclipse.EclipseAugments.*;
+import static lombok.eclipse.EcjAugments.*;
import static lombok.eclipse.handlers.EclipseHandlerUtil.EclipseReflectiveMembers.*;
import java.lang.reflect.Array;
@@ -2649,22 +2649,42 @@ public class EclipseHandlerUtil {
return null;
}
+ private static class EclipseOnlyUtil {
+ public static void setDocComment(CompilationUnitDeclaration cud, TypeDeclaration type, ASTNode node, String doc) {
+ if (cud.compilationResult.compilationUnit instanceof CompilationUnit) {
+ CompilationUnit compilationUnit = (CompilationUnit) cud.compilationResult.compilationUnit;
+ Map<String, String> docs = EclipseAugments.CompilationUnit_javadoc.setIfAbsent(compilationUnit, new HashMap<String, String>());
+
+ if (node instanceof AbstractMethodDeclaration) {
+ AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
+ String signature = getSignature(type, methodDeclaration);
+ /* Add javadoc start marker, add leading asterisks to each line, add javadoc end marker */
+ docs.put(signature, String.format("/**%n%s%n */", doc.replaceAll("(?m)^", " * ")));
+ }
+ }
+ }
+ }
+
+ private static Boolean eclipseMode;
+ private static boolean eclipseMode() {
+ if (eclipseMode != null) return eclipseMode.booleanValue();
+ try {
+ Class.forName("org.eclipse.jdt.internal.core.CompilationUnit");
+ eclipseMode = true;
+ } catch (Exception e) {
+ eclipseMode = false;
+ }
+ return eclipseMode;
+ }
+
public static void setDocComment(CompilationUnitDeclaration cud, EclipseNode eclipseNode, String doc) {
+ if (!eclipseMode()) return;
setDocComment(cud, (TypeDeclaration) upToTypeNode(eclipseNode).get(), eclipseNode.get(), doc);
}
-
+
public static void setDocComment(CompilationUnitDeclaration cud, TypeDeclaration type, ASTNode node, String doc) {
- if (cud.compilationResult.compilationUnit instanceof CompilationUnit) {
- CompilationUnit compilationUnit = (CompilationUnit) cud.compilationResult.compilationUnit;
- Map<String, String> docs = CompilationUnit_javadoc.setIfAbsent(compilationUnit, new HashMap<String, String>());
-
- if (node instanceof AbstractMethodDeclaration) {
- AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
- String signature = getSignature(type, methodDeclaration);
- /* Add javadoc start marker, add leading asterisks to each line, add javadoc end marker */
- docs.put(signature, String.format("/**%n%s%n */", doc.replaceAll("(?m)^", " * ")));
- }
- }
+ if (!eclipseMode()) return;
+ EclipseOnlyUtil.setDocComment(cud, type, node, doc);
}
public static String getSignature(TypeDeclaration type, AbstractMethodDeclaration methodDeclaration) {