Skip to content

Commit 8cb5562

Browse files
snjezailoveeclipse
authored andcommitted
Performance degradation with lombok
1 parent 59a6d4e commit 8cb5562

4 files changed

Lines changed: 101 additions & 5 deletions

File tree

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Scanner.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,10 @@ else if (c >= LOW_SURROGATE_MIN_VALUE && c <= LOW_SURROGATE_MAX_VALUE) {
18701870
}
18711871
} //-----------------end switch while try--------------------
18721872
catch (IndexOutOfBoundsException e) {
1873-
if (this.tokenizeWhiteSpace && (whiteStart != this.currentPosition - 1)) {
1873+
if (this.currentPosition < 0) {
1874+
this.currentPosition = 0;
1875+
return TokenNameInvalid;
1876+
} else if (this.tokenizeWhiteSpace && (whiteStart != this.currentPosition - 1)) {
18741877
// reposition scanner in case we are interested by spaces as tokens
18751878
this.currentPosition--;
18761879
this.startPosition = whiteStart;

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.IOException;
1919
import java.util.List;
20+
import java.util.Locale;
2021
import junit.framework.Test;
2122
import org.eclipse.core.runtime.CoreException;
2223
import org.eclipse.jdt.core.BindingKey;
@@ -29,8 +30,16 @@
2930
import org.eclipse.jdt.core.JavaCore;
3031
import org.eclipse.jdt.core.JavaModelException;
3132
import org.eclipse.jdt.core.dom.*;
33+
import org.eclipse.jdt.internal.compiler.CompilationResult;
34+
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
35+
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
3236
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
37+
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
38+
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
39+
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
3340
import org.eclipse.jdt.internal.core.ResolvedBinaryMethod;
41+
import org.eclipse.jdt.internal.core.dom.SourceRangeVerifier;
42+
import org.eclipse.jdt.internal.core.util.CommentRecorderParser;
3443

3544
@SuppressWarnings({"rawtypes"})
3645
public class ASTConverter18Test extends ConverterTestSetup {
@@ -5513,4 +5522,80 @@ public void acceptBinding(String bindingKey, IBinding binding) {
55135522
parser.createASTs(new ICompilationUnit[] {this.workingCopy}, new String[0], requestor, null);
55145523
}
55155524

5525+
public void testIssue4712() throws JavaModelException {
5526+
String contents =
5527+
"""
5528+
public class Test {
5529+
public String test() {
5530+
// comment; insert System.out.println
5531+
return "'test' called";
5532+
}
5533+
}
5534+
""";
5535+
this.workingCopy = getWorkingCopy("/Converter18/src/test432051/X.java", contents, true/*computeProblems*/);
5536+
CompilerOptions options = new CompilerOptions();
5537+
options.sourceLevel = ClassFileConstants.JDK25;
5538+
options.complianceLevel = ClassFileConstants.JDK25;
5539+
options.docCommentSupport = true;
5540+
CommentRecorderParser parser =
5541+
new CommentRecorderParser(
5542+
new ProblemReporter(
5543+
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
5544+
options,
5545+
new DefaultProblemFactory(Locale.getDefault())),
5546+
false);
5547+
char[] sourceChars = this.workingCopy.getSource().toCharArray();
5548+
org.eclipse.jdt.internal.compiler.batch.CompilationUnit unit =
5549+
new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(sourceChars, this.workingCopy.getElementName(), null);
5550+
CompilationResult compilationResult = new CompilationResult(unit, 0, 0, 10);
5551+
CompilationUnitDeclaration cud = parser.parse(unit, compilationResult);
5552+
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDecl = cud.types[0];
5553+
char[][] tokens = { "System".toCharArray(), "out".toCharArray() };
5554+
long[] positions = { 0L, 0L };
5555+
org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference systemOut =
5556+
new org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference(tokens, positions, 0, 0);
5557+
org.eclipse.jdt.internal.compiler.ast.MessageSend printlnCall =
5558+
new org.eclipse.jdt.internal.compiler.ast.MessageSend();
5559+
printlnCall.receiver = systemOut;
5560+
printlnCall.selector = "println".toCharArray();
5561+
printlnCall.arguments = null;
5562+
printlnCall.sourceStart = typeDecl.sourceStart;
5563+
printlnCall.sourceEnd = typeDecl.sourceEnd;
5564+
printlnCall.nameSourcePosition = 0L;
5565+
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration testMethod = null;
5566+
for (org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration method : typeDecl.methods) {
5567+
if (new String(method.selector).equals("test")) {
5568+
testMethod = method;
5569+
break;
5570+
}
5571+
}
5572+
org.eclipse.jdt.internal.compiler.ast.Statement[] stmts = new org.eclipse.jdt.internal.compiler.ast.Statement[2];
5573+
stmts[0] = printlnCall;
5574+
stmts[1] = testMethod.statements[0];
5575+
testMethod.statements = stmts;
5576+
int reconcileFlags = ICompilationUnit.ENABLE_STATEMENTS_RECOVERY
5577+
| ICompilationUnit.ENABLE_BINDINGS_RECOVERY
5578+
| ICompilationUnit.FORCE_PROBLEM_DETECTION;
5579+
boolean oldDebug = SourceRangeVerifier.DEBUG;
5580+
boolean oldDebugThrow = SourceRangeVerifier.DEBUG_THROW;
5581+
try {
5582+
SourceRangeVerifier.DEBUG = false;
5583+
SourceRangeVerifier.DEBUG_THROW = false;
5584+
long start = System.currentTimeMillis();
5585+
AST.convertCompilationUnit(
5586+
AST.getJLSLatest(),
5587+
cud,
5588+
options.getMap(),
5589+
false,
5590+
(org.eclipse.jdt.internal.core.CompilationUnit) this.workingCopy,
5591+
reconcileFlags,
5592+
null
5593+
);
5594+
// The convertCompilationUnit method would need to take less than one second to complete.
5595+
assertTrue((System.currentTimeMillis() - start) < 1000);
5596+
} finally {
5597+
SourceRangeVerifier.DEBUG = oldDebug;
5598+
SourceRangeVerifier.DEBUG_THROW = oldDebugThrow;
5599+
}
5600+
}
55165601
}

org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,10 @@ public int lastTrailingCommentIndex(ASTNode node) {
751751
* @since 3.0
752752
*/
753753
void initCommentMapper(Scanner scanner) {
754-
this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
755-
this.commentMapper.initialize(this, scanner);
754+
if (this.optionalCommentTable != null && this.optionalCommentTable.length > 0) {
755+
this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
756+
this.commentMapper.initialize(this, scanner);
757+
}
756758
}
757759

758760
@Override

org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,18 @@ class CommentMapperVisitor extends DefaultASTVisitor {
562562
@Override
563563
protected boolean visitNode(ASTNode node) {
564564

565+
// skip generated node - https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4712
566+
if (node.getStartPosition() <= 0 && node.getLength() <= 0) {
567+
return false;
568+
}
565569
// Get default previous end
566570
ASTNode parent = node.getParent();
567571
int previousEnd = parent.getStartPosition();
568572

569573
// Look for sibling node
570574
ASTNode sibling = parent == this.topSiblingParent ? (ASTNode) this.siblings[this.siblingPtr] : null;
571-
if (sibling != null) {
575+
// skip generated node - https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4712
576+
if (sibling != null && sibling.getLength() > 0) {
572577
// Found one previous sibling, so compute its trailing comments using current node start position
573578
try {
574579
previousEnd = storeTrailingComments(sibling, node.getStartPosition(), false, this.parentLineRange[this.siblingPtr]);
@@ -624,7 +629,8 @@ protected void endVisitNode(ASTNode node) {
624629

625630
// Look if a child node is waiting for trailing comments computing
626631
ASTNode sibling = this.topSiblingParent == node ? (ASTNode) this.siblings[this.siblingPtr] : null;
627-
if (sibling != null) {
632+
// skip generated node - https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4712
633+
if (sibling != null && sibling.getLength() > 0) {
628634
try {
629635
storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true, this.parentLineRange[this.siblingPtr]);
630636
} catch (Exception ex) {

0 commit comments

Comments
 (0)