diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2021-04-18 06:33:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-18 06:33:56 +0200 |
commit | 561870c7cc61f16105447d84cf4d732b557296ed (patch) | |
tree | 9b71bc5764b69381ca6084337d274631c3a74649 /src/core/lombok/eclipse/handlers | |
parent | 8e7fcac2e39f7eb8809130ae73b4d17965a5d9f2 (diff) | |
parent | 52d1aa860847629fbb12d008fc708166f000fa6c (diff) | |
download | lombok-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/lombok/eclipse/handlers')
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 39 | ||||
-rwxr-xr-x | src/core/lombok/eclipse/handlers/HandleBuilder.java | 2 |
2 files changed, 20 insertions, 21 deletions
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) {} |