Fix for Bug 526996 - CompilationUnit.setCommentTable(...) throws
IllegalStateException
Change-Id: Ib74a689825edbdfdb21211acf9ec3622919a1e83
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
index 770540e..dcff49b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
@@ -81,7 +81,7 @@
public int[] commentStarts = new int[COMMENT_ARRAYS_SIZE];
public int[] commentTagStarts = new int[COMMENT_ARRAYS_SIZE];
public int commentPtr = -1; // no comment test with commentPtr value -1
- protected int lastCommentLinePosition = -1;
+ public int lastCommentLinePosition = -1;
// task tag support
public char[][] foundTaskTags = null;
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java
index 9397de3..1186e23 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java
@@ -210,6 +210,9 @@
new String(sourceUnit.getFileName())
}));
}
+ if (this.parser instanceof CommentRecorderParser) {
+ ((CommentRecorderParser) this.parser).resetComments();
+ }
// diet parsing for large collection of units
if (this.totalUnits < this.parseThreshold) {
parsedUnit = this.parser.parse(sourceUnit, unitResult);
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java
index 1c35e23..8d1c0b9 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core.util;
+import java.util.Arrays;
+
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -330,4 +332,14 @@
pushOnCommentsStack(0, this.scanner.commentPtr);
super.resetModifiers();
}
+ public void resetComments() {
+ this.commentPtr = -1;
+ Arrays.fill(this.commentStarts, 0);
+ Arrays.fill(this.commentStops, 0);
+ Arrays.fill(this.scanner.commentStops, 0);
+ Arrays.fill(this.scanner.commentStarts, 0);
+ Arrays.fill(this.scanner.commentTagStarts, 0);
+ this.scanner.commentPtr = -1; // no comment test with commentPtr value -1
+ this.scanner.lastCommentLinePosition = -1;
+ }
}