aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2021-04-18 06:33:56 +0200
committerGitHub <noreply@github.com>2021-04-18 06:33:56 +0200
commit561870c7cc61f16105447d84cf4d732b557296ed (patch)
tree9b71bc5764b69381ca6084337d274631c3a74649 /src/core
parent8e7fcac2e39f7eb8809130ae73b4d17965a5d9f2 (diff)
parent52d1aa860847629fbb12d008fc708166f000fa6c (diff)
downloadlombok-561870c7cc61f16105447d84cf4d732b557296ed.tar.gz
lombok-561870c7cc61f16105447d84cf4d732b557296ed.tar.bz2
lombok-561870c7cc61f16105447d84cf4d732b557296ed.zip
Merge pull request #2809 from Rawi01/eclipse-javadoc-performance
Avoid reading file from disk by reusing the parser source
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/eclipse/EclipseAST.java9
-rw-r--r--src/core/lombok/eclipse/TransformEclipseAST.java1
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java39
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleBuilder.java2
4 files changed, 30 insertions, 21 deletions
diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java
index 0036ec23..4a0854a4 100644
--- a/src/core/lombok/eclipse/EclipseAST.java
+++ b/src/core/lombok/eclipse/EclipseAST.java
@@ -232,6 +232,14 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> {
}
}
+ public void setSource(char[] source) {
+ this.source = source;
+ }
+
+ public char[] getSource() {
+ return source;
+ }
+
/**
* Eclipse starts off with a 'diet' parse which leaves method bodies blank, amongst other shortcuts.
*
@@ -309,6 +317,7 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> {
}
private final CompilationUnitDeclaration compilationUnitDeclaration;
+ private char[] source;
private boolean completeParse;
private static String toFileName(CompilationUnitDeclaration ast) {
diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java
index 59a0709e..201d4695 100644
--- a/src/core/lombok/eclipse/TransformEclipseAST.java
+++ b/src/core/lombok/eclipse/TransformEclipseAST.java
@@ -182,6 +182,7 @@ public class TransformEclipseAST {
DebugSnapshotStore.INSTANCE.snapshot(ast, "transform entry");
long histoToken = lombokTracker == null ? 0L : lombokTracker.start();
EclipseAST existing = getAST(ast, false);
+ existing.setSource(parser.scanner.getSource());
new TransformEclipseAST(existing).go();
if (lombokTracker != null) lombokTracker.end(histoToken);
DebugSnapshotStore.INSTANCE.snapshot(ast, "transform exit");
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 70d98cc6..5eea980c 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -95,7 +95,6 @@ import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
-import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding;
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
@@ -2689,11 +2688,13 @@ public class EclipseHandlerUtil {
return annotations;
}
- public static String getDocComment(CompilationUnitDeclaration cud, ASTNode node) {
- ICompilationUnit compilationUnit = cud.compilationResult.compilationUnit;
+ public static String getDocComment(EclipseNode eclipseNode) {
+ if (eclipseNode.getAst().getSource() == null) return null;
+
+ final ASTNode node = eclipseNode.get();
if (node instanceof FieldDeclaration) {
FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
- char[] rawContent = CharOperation.subarray(compilationUnit.getContents(), fieldDeclaration.declarationSourceStart, fieldDeclaration.declarationSourceEnd);
+ char[] rawContent = CharOperation.subarray(eclipseNode.getAst().getSource(), fieldDeclaration.declarationSourceStart, fieldDeclaration.declarationSourceEnd);
String rawContentString = new String(rawContent);
int startIndex = rawContentString.indexOf("/**");
int endIndex = rawContentString.indexOf("*/");
@@ -2739,14 +2740,13 @@ public class EclipseHandlerUtil {
public static enum CopyJavadoc {
VERBATIM {
- @Override public String apply(final CompilationUnitDeclaration cu, final EclipseNode node) {
- return getDocComment(cu, node.get());
+ @Override public String apply(final EclipseNode node) {
+ return getDocComment(node);
}
},
GETTER {
- @Override public String apply(final CompilationUnitDeclaration cu, final EclipseNode node) {
- final ASTNode n = node.get();
- String javadoc = getDocComment(cu, n);
+ @Override public String apply(final EclipseNode node) {
+ String javadoc = getDocComment(node);
// step 1: Check if there is a 'GETTER' section. If yes, that becomes the new method's javadoc.
String out = getJavadocSection(javadoc, "GETTER");
final boolean sectionBased = out != null;
@@ -2757,26 +2757,25 @@ public class EclipseHandlerUtil {
}
},
SETTER {
- @Override public String apply(final CompilationUnitDeclaration cu, final EclipseNode node) {
- return applySetter(cu, node, "SETTER");
+ @Override public String apply(final EclipseNode node) {
+ return applySetter(node, "SETTER");
}
},
WITH {
- @Override public String apply(final CompilationUnitDeclaration cu, final EclipseNode node) {
- return addReturnsUpdatedSelfIfNeeded(applySetter(cu, node, "WITH|WITHER"));
+ @Override public String apply(final EclipseNode node) {
+ return addReturnsUpdatedSelfIfNeeded(applySetter(node, "WITH|WITHER"));
}
},
WITH_BY {
- @Override public String apply(final CompilationUnitDeclaration cu, final EclipseNode node) {
- return applySetter(cu, node, "WITHBY|WITH_BY");
+ @Override public String apply( final EclipseNode node) {
+ return applySetter(node, "WITHBY|WITH_BY");
}
};
- public abstract String apply(final CompilationUnitDeclaration cu, final EclipseNode node);
+ public abstract String apply(final EclipseNode node);
- private static String applySetter(final CompilationUnitDeclaration cu, EclipseNode node, String sectionName) {
- final ASTNode n = node.get();
- String javadoc = getDocComment(cu, n);
+ private static String applySetter(EclipseNode node, String sectionName) {
+ String javadoc = getDocComment(node);
// step 1: Check if there is a 'SETTER' section. If yes, that becomes the new method's javadoc.
String out = getJavadocSection(javadoc, sectionName);
final boolean sectionBased = out != null;
@@ -2824,7 +2823,7 @@ public class EclipseHandlerUtil {
if (copyMode == null) copyMode = CopyJavadoc.VERBATIM;
try {
CompilationUnitDeclaration cud = ((CompilationUnitDeclaration) from.top().get());
- String newJavadoc = copyMode.apply(cud, from);
+ String newJavadoc = copyMode.apply(from);
if (forceAddReturn) {
newJavadoc = addReturnsThisIfNeeded(newJavadoc);
}
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index c002c4ca..dab774f3 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -1057,7 +1057,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
private void copyJavadocFromParam(EclipseNode from, MethodDeclaration to, TypeDeclaration type, String param) {
try {
CompilationUnitDeclaration cud = (CompilationUnitDeclaration) from.top().get();
- String methodComment = getDocComment(cud, from.get());
+ String methodComment = getDocComment(from);
String newJavadoc = addReturnsThisIfNeeded(getParamJavadoc(methodComment, param));
setDocComment(cud, type, to, newJavadoc);
} catch (Exception ignore) {}