### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java,v retrieving revision 1.175 diff -u -r1.175 CompletionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 16 Mar 2007 11:08:20 -0000 1.175 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 6 Apr 2007 16:22:43 -0000 @@ -26,6 +26,7 @@ import org.eclipse.jdt.internal.compiler.ast.*; import org.eclipse.jdt.internal.compiler.parser.*; import org.eclipse.jdt.internal.compiler.problem.*; +import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.internal.codeassist.impl.*; @@ -264,7 +265,8 @@ if (method != null){ AbstractMethodDeclaration methodDecl = method.methodDeclaration; if ((methodDecl.bodyStart == methodDecl.sourceEnd+1) // was missing opening brace - && (scanner.getLineNumber(orphan.sourceStart) == scanner.getLineNumber(methodDecl.sourceEnd))){ + && (Util.getLineNumber(orphan.sourceStart, scanner.lineEnds, 0, scanner.linePtr) + == Util.getLineNumber(methodDecl.sourceEnd, scanner.lineEnds, 0, scanner.linePtr))){ return; } } @@ -440,7 +442,8 @@ if (method != null){ AbstractMethodDeclaration methodDecl = method.methodDeclaration; if ((methodDecl.bodyStart == methodDecl.sourceEnd+1) // was missing opening brace - && (this.scanner.getLineNumber(node.sourceStart) == this.scanner.getLineNumber(methodDecl.sourceEnd))){ + && (Util.getLineNumber(node.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr) + == Util.getLineNumber(methodDecl.sourceEnd, this.scanner.lineEnds, 0, this.scanner.linePtr))){ return; } } @@ -463,7 +466,8 @@ if (method != null){ AbstractMethodDeclaration methodDecl = method.methodDeclaration; if ((methodDecl.bodyStart == methodDecl.sourceEnd+1) // was missing opening brace - && (scanner.getLineNumber(expression.sourceStart) == scanner.getLineNumber(methodDecl.sourceEnd))){ + && (Util.getLineNumber(expression.sourceStart, scanner.lineEnds, 0, scanner.linePtr) + == Util.getLineNumber(methodDecl.sourceEnd, scanner.lineEnds, 0, scanner.linePtr))){ return; } } @@ -1540,8 +1544,8 @@ /* check if on line with an error already - to avoid completing inside illegal type names e.g. int[ */ if (lastErrorEndPosition <= cursorLocation+1 - && scanner.getLineNumber(lastErrorEndPosition) - == scanner.getLineNumber(((CompletionScanner)scanner).completedIdentifierStart)){ + && Util.getLineNumber(lastErrorEndPosition, scanner.lineEnds, 0, scanner.linePtr) + == Util.getLineNumber(((CompletionScanner)scanner).completedIdentifierStart, scanner.lineEnds, 0, scanner.linePtr)){ return false; } RecoveredMethod recoveredMethod = (RecoveredMethod)currentElement; @@ -1593,8 +1597,8 @@ /* check if on line with an error already - to avoid completing inside illegal type names e.g. int[ */ if ((lastErrorEndPosition <= cursorLocation+1) - && scanner.getLineNumber(lastErrorEndPosition) - == scanner.getLineNumber(((CompletionScanner)scanner).completedIdentifierStart)){ + && Util.getLineNumber(lastErrorEndPosition, scanner.lineEnds, 0, scanner.linePtr) + == Util.getLineNumber(((CompletionScanner)scanner).completedIdentifierStart, scanner.lineEnds, 0, scanner.linePtr)){ return false; } RecoveredType recoveredType = (RecoveredType)currentElement; @@ -2030,8 +2034,8 @@ if (!(currentElement instanceof RecoveredType) && (currentToken == TokenNameDOT - || (scanner.getLineNumber(type.sourceStart) - != scanner.getLineNumber(nameSourceStart)))){ + || (Util.getLineNumber(type.sourceStart, scanner.lineEnds, 0, scanner.linePtr) + != Util.getLineNumber(nameSourceStart, scanner.lineEnds, 0, scanner.linePtr)))){ lastCheckPoint = nameSourceStart; restartRecovery = true; return; @@ -2296,7 +2300,8 @@ int declarationSourceStart = intStack[intPtr--]; int mod = intStack[intPtr--]; - if(scanner.getLineNumber(type.sourceStart) != scanner.getLineNumber((int) (selectorSource >>> 32))) { + if(Util.getLineNumber(type.sourceStart, scanner.lineEnds, 0, scanner.linePtr) + != Util.getLineNumber((int) (selectorSource >>> 32), scanner.lineEnds, 0, scanner.linePtr)) { FieldDeclaration completionFieldDecl = new CompletionOnFieldType(type, false); // consume annotations int length; @@ -2381,8 +2386,8 @@ if (currentElement != null){ if (currentElement instanceof RecoveredType //|| md.modifiers != 0 - || (scanner.getLineNumber(md.returnType.sourceStart) - == scanner.getLineNumber(md.sourceStart))){ + || (Util.getLineNumber(md.returnType.sourceStart, scanner.lineEnds, 0, scanner.linePtr) + == Util.getLineNumber(md.sourceStart, scanner.lineEnds, 0, scanner.linePtr))){ lastCheckPoint = md.bodyStart; currentElement = currentElement.add(md, 0); lastIgnoredToken = -1; Index: compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/LexStream.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/LexStream.java,v retrieving revision 1.11 diff -u -r1.11 LexStream.java --- compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/LexStream.java 24 Nov 2006 01:32:06 -0000 1.11 +++ compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/LexStream.java 6 Apr 2007 16:22:50 -0000 @@ -14,6 +14,7 @@ import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.internal.compiler.parser.Scanner; import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; +import org.eclipse.jdt.internal.compiler.util.Util; public class LexStream implements TerminalTokens { public static final int IS_AFTER_JUMP = 1; @@ -89,7 +90,7 @@ token.name = scanner.getCurrentTokenSource(); token.start = start; token.end = end; - token.line = scanner.getLineNumber(end); + token.line = Util.getLineNumber(end, scanner.lineEnds, 0, scanner.linePtr); if(currentInterval != previousInterval && (intervalFlagsToSkip[currentInterval] & RangeUtil.IGNORE) == 0){ token.flags = IS_AFTER_JUMP; @@ -113,7 +114,7 @@ token.name = CharOperation.NO_CHAR; token.start = start; token.end = end; - token.line = scanner.getLineNumber(end); + token.line = Util.getLineNumber(end, scanner.lineEnds, 0, scanner.linePtr); tokenCache[++tokenCacheIndex % length] = token; Index: compiler/org/eclipse/jdt/internal/compiler/problem/AbortCompilation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/AbortCompilation.java,v retrieving revision 1.15 diff -u -r1.15 AbortCompilation.java --- compiler/org/eclipse/jdt/internal/compiler/problem/AbortCompilation.java 3 Oct 2006 19:38:26 -0000 1.15 +++ compiler/org/eclipse/jdt/internal/compiler/problem/AbortCompilation.java 6 Apr 2007 16:22:50 -0000 @@ -61,7 +61,8 @@ if (this.problem.getSourceStart() != 0 || this.problem.getSourceEnd() != 0) return; this.problem.setSourceStart(invocationSite.sourceStart()); this.problem.setSourceEnd(invocationSite.sourceEnd()); - this.problem.setSourceLineNumber(Util.searchLineNumber(unitResult.getLineSeparatorPositions(), invocationSite.sourceStart())); + int[] lineEnds = unitResult.getLineSeparatorPositions(); + this.problem.setSourceLineNumber(Util.getLineNumber(invocationSite.sourceStart(), lineEnds, 0, lineEnds.length-1)); this.compilationResult = unitResult; } @@ -70,7 +71,8 @@ if (this.problem.getSourceStart() != 0 || this.problem.getSourceEnd() != 0) return; this.problem.setSourceStart(astNode.sourceStart()); this.problem.setSourceEnd(astNode.sourceEnd()); - this.problem.setSourceLineNumber(Util.searchLineNumber(unitResult.getLineSeparatorPositions(), astNode.sourceStart())); + int[] lineEnds = unitResult.getLineSeparatorPositions(); + this.problem.setSourceLineNumber(Util.getLineNumber(astNode.sourceStart(), lineEnds, 0, lineEnds.length-1)); this.compilationResult = unitResult; } } Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java,v retrieving revision 1.28 diff -u -r1.28 ProblemHandler.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java 24 Nov 2006 01:32:06 -0000 1.28 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java 6 Apr 2007 16:22:50 -0000 @@ -100,8 +100,9 @@ } } + int[] lineEnds; int lineNumber = problemStartPosition >= 0 - ? Util.searchLineNumber(unitResult.getLineSeparatorPositions(), problemStartPosition) + ? Util.getLineNumber(problemStartPosition, lineEnds = unitResult.getLineSeparatorPositions(), 0, lineEnds.length-1) : 0; int columnNumber = problemStartPosition >= 0 ? Util.searchColumnNumber(unitResult.getLineSeparatorPositions(), lineNumber, problemStartPosition) Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.367 diff -u -r1.367 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 16 Mar 2007 11:08:19 -0000 1.367 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 6 Apr 2007 16:22:49 -0000 @@ -3030,8 +3030,8 @@ if (!(this.currentElement instanceof RecoveredType) && (this.currentToken == TokenNameDOT //|| declaration.modifiers != 0 - || (this.scanner.getLineNumber(declaration.type.sourceStart) - != this.scanner.getLineNumber((int) (namePosition >>> 32))))){ + || (Util.getLineNumber(declaration.type.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr) + != Util.getLineNumber((int) (namePosition >>> 32), this.scanner.lineEnds, 0, this.scanner.linePtr)))){ this.lastCheckPoint = (int) (namePosition >>> 32); this.restartRecovery = true; return; @@ -4267,8 +4267,8 @@ if (this.currentElement != null){ if (this.currentElement instanceof RecoveredType //|| md.modifiers != 0 - || (this.scanner.getLineNumber(md.returnType.sourceStart) - == this.scanner.getLineNumber(md.sourceStart))){ + || (Util.getLineNumber(md.returnType.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr) + == Util.getLineNumber(md.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr))){ this.lastCheckPoint = md.bodyStart; this.currentElement = this.currentElement.add(md, 0); this.lastIgnoredToken = -1; @@ -4330,8 +4330,8 @@ boolean isType; if ((isType = this.currentElement instanceof RecoveredType) //|| md.modifiers != 0 - || (this.scanner.getLineNumber(md.returnType.sourceStart) - == this.scanner.getLineNumber(md.sourceStart))){ + || (Util.getLineNumber(md.returnType.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr) + == Util.getLineNumber(md.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr))){ if(isType) { ((RecoveredType) this.currentElement).pendingTypeParameters = null; } @@ -7256,7 +7256,7 @@ this.scanner.getCurrentTokenSourceString(), this.scanner.startPosition, this.scanner.currentPosition - 1, - this.scanner.getLineNumber(this.scanner.startPosition)); + Util.getLineNumber(this.scanner.startPosition, this.scanner.lineEnds, 0, this.scanner.linePtr)); this.compilationUnit.recordStringLiteral(stringLiteral); } else { stringLiteral = this.createStringLiteral( @@ -8091,7 +8091,8 @@ if (immediateCommentEnd > 0){ // only tolerating non-javadoc comments // is there any line break until the end of the immediate comment ? (thus only tolerating line comment) immediateCommentEnd--; // comment end in one char too far - if (this.scanner.getLineNumber(position) == this.scanner.getLineNumber(immediateCommentEnd)){ + if (Util.getLineNumber(position, this.scanner.lineEnds, 0, this.scanner.linePtr) + == Util.getLineNumber(immediateCommentEnd, this.scanner.lineEnds, 0, this.scanner.linePtr)){ position = immediateCommentEnd; validCount--; // flush this comment index++; Index: compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java,v retrieving revision 1.185 diff -u -r1.185 Scanner.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 6 Mar 2007 02:38:51 -0000 1.185 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 6 Apr 2007 16:22:50 -0000 @@ -3543,34 +3543,14 @@ return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral; } + /** * Search the line number corresponding to a specific position * @param position int * @return int */ public final int getLineNumber(int position) { - - if (this.lineEnds == null) - return 1; - int length = this.linePtr+1; - if (length == 0) - return 1; - int g = 0, d = length - 1; - int m = 0; - while (g <= d) { - m = g + (d - g) /2; - if (position < this.lineEnds[m]) { - d = m-1; - } else if (position > this.lineEnds[m]) { - g = m+1; - } else { - return m + 1; - } - } - if (position < this.lineEnds[m]) { - return m+1; - } - return m+2; + return Util.getLineNumber(position, this.lineEnds, 0, this.linePtr); } public final void setSource(char[] sourceString){ //the source-buffer is set to sourceString Index: compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java,v retrieving revision 1.57 diff -u -r1.57 RecoveredMethod.java --- compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java 16 Oct 2006 08:40:41 -0000 1.57 +++ compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java 6 Apr 2007 16:22:49 -0000 @@ -28,6 +28,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; +import org.eclipse.jdt.internal.compiler.util.Util; /** * Internal method structure for parsing recovery @@ -502,8 +503,9 @@ int lastParameterEnd = parameters[parameters.length - 1].sourceEnd; Parser parser = this.parser(); - if(parser.scanner.getLineNumber(methodDeclaration.declarationSourceStart) - != parser.scanner.getLineNumber(lastParameterEnd)) return; + Scanner scanner = parser.scanner; + if(Util.getLineNumber(methodDeclaration.declarationSourceStart, scanner.lineEnds, 0, scanner.linePtr) + != Util.getLineNumber(lastParameterEnd, scanner.lineEnds, 0, scanner.linePtr)) return; if(parser.modifiersSourceStart > lastParameterEnd && parser.modifiersSourceStart < methodDeclaration.declarationSourceStart) return; Index: compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java,v retrieving revision 1.60 diff -u -r1.60 JavadocParser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java 1 Dec 2006 21:44:04 -0000 1.60 +++ compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java 6 Apr 2007 16:22:46 -0000 @@ -16,6 +16,7 @@ import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.internal.compiler.ast.*; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.util.Util; /** * Parser specialized for decoding javadoc comments @@ -82,8 +83,9 @@ } else { // Parse comment - int firstLineNumber = this.sourceParser.scanner.getLineNumber(javadocStart); - int lastLineNumber = this.sourceParser.scanner.getLineNumber(javadocEnd); + Scanner sourceScanner = this.sourceParser.scanner; + int firstLineNumber = Util.getLineNumber(javadocStart, sourceScanner.lineEnds, 0, sourceScanner.linePtr); + int lastLineNumber = Util.getLineNumber(javadocEnd, sourceScanner.lineEnds, 0, sourceScanner.linePtr); this.index = javadocStart +3; // scan line per line, since tags must be at beginning of lines only Index: compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java,v retrieving revision 1.29 diff -u -r1.29 RecoveredElement.java --- compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java 29 Mar 2006 02:47:34 -0000 1.29 +++ compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java 6 Apr 2007 16:22:49 -0000 @@ -21,6 +21,7 @@ import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.util.Util; public class RecoveredElement { @@ -210,7 +211,7 @@ Scanner scanner = parser.scanner; if (scanner.lineEnds == null) return position; - int index = scanner.getLineNumber(position); + int index = Util.getLineNumber(position, scanner.lineEnds, 0, scanner.linePtr); if (index < 2) return position; int previousLineEnd = scanner.lineEnds[index-2]; Index: compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java,v retrieving revision 1.65 diff -u -r1.65 AbstractCommentParser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java 21 Nov 2006 12:43:58 -0000 1.65 +++ compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java 6 Apr 2007 16:22:46 -0000 @@ -16,6 +16,7 @@ import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.util.Util; /** * Parser specialized for decoding javadoc comments @@ -358,29 +359,11 @@ private int getLineNumber(int position) { if (this.scanner.linePtr != -1) { - return this.scanner.getLineNumber(position); + return Util.getLineNumber(position, this.scanner.lineEnds, 0, this.scanner.linePtr); } if (this.lineEnds == null) return 1; - int length = this.lineEnds.length; - if (length == 0) - return 1; - int g = 0, d = length - 1; - int m = 0; - while (g <= d) { - m = g + (d - g) /2; - if (position < this.lineEnds[m]) { - d = m-1; - } else if (position > this.lineEnds[m]) { - g = m+1; - } else { - return m + 1; - } - } - if (position < this.lineEnds[m]) { - return m+1; - } - return m+2; + return Util.getLineNumber(position, this.lineEnds, 0, this.lineEnds.length-1); } private int getTokenEndPosition() { Index: model/org/eclipse/jdt/internal/core/util/PublicScanner.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/PublicScanner.java,v retrieving revision 1.99 diff -u -r1.99 PublicScanner.java --- model/org/eclipse/jdt/internal/core/util/PublicScanner.java 24 Nov 2006 01:32:05 -0000 1.99 +++ model/org/eclipse/jdt/internal/core/util/PublicScanner.java 6 Apr 2007 16:22:51 -0000 @@ -65,7 +65,7 @@ public boolean scanningFloatLiteral = false; //support for /** comments - public static int COMMENT_ARRAYS_SIZE = 30; + public final static int COMMENT_ARRAYS_SIZE = 30; public int[] commentStops = new int[COMMENT_ARRAYS_SIZE]; public int[] commentStarts = new int[COMMENT_ARRAYS_SIZE]; public int[] commentTagStarts = new int[COMMENT_ARRAYS_SIZE]; @@ -3540,34 +3540,14 @@ return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral; } + /** * Search the line number corresponding to a specific position * @param position int * @return int */ public final int getLineNumber(int position) { - - if (this.lineEnds == null) - return 1; - int length = this.linePtr+1; - if (length == 0) - return 1; - int g = 0, d = length - 1; - int m = 0; - while (g <= d) { - m = g + (d - g) /2; - if (position < this.lineEnds[m]) { - d = m-1; - } else if (position > this.lineEnds[m]) { - g = m+1; - } else { - return m + 1; - } - } - if (position < this.lineEnds[m]) { - return m+1; - } - return m+2; + return Util.getLineNumber(position, this.lineEnds, 0, this.linePtr); } public final void setSource(char[] sourceString){ //the source-buffer is set to sourceString Index: model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java,v retrieving revision 1.21 diff -u -r1.21 CommentRecorderParser.java --- model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 5 Sep 2006 18:35:00 -0000 1.21 +++ model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 6 Apr 2007 16:22:51 -0000 @@ -164,7 +164,8 @@ while (index 0){ // only tolerating non-javadoc comments (non-javadoc comment end positions are negative) // is there any line break until the end of the immediate comment ? (thus only tolerating line comment) immediateCommentEnd--; // comment end in one char too far - if (this.scanner.getLineNumber(position) != this.scanner.getLineNumber(immediateCommentEnd)) break; + if (org.eclipse.jdt.internal.compiler.util.Util.getLineNumber(position, this.scanner.lineEnds, 0, this.scanner.linePtr) + != org.eclipse.jdt.internal.compiler.util.Util.getLineNumber(immediateCommentEnd, this.scanner.lineEnds, 0, this.scanner.linePtr)) break; position = immediateCommentEnd; validCount--; // flush this comment index++; Index: dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java,v retrieving revision 1.30 diff -u -r1.30 DefaultCommentMapper.java --- dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java 24 Nov 2006 13:33:40 -0000 1.30 +++ dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java 6 Apr 2007 16:22:51 -0000 @@ -10,12 +10,11 @@ *******************************************************************************/ package org.eclipse.jdt.core.dom; -import java.util.HashMap; - import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.internal.compiler.parser.Scanner; import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; +import org.eclipse.jdt.internal.compiler.util.Util; /** * Internal class for associating comments with AST nodes. @@ -135,6 +134,19 @@ } /* + * Search the line number corresponding to a specific position + * between the given line range (inclusive) + * @param position int + * @parem lineRange size-2 int[] + * @return int + */ + public final int getLineNumber(int position, int[] lineRange) { + int[] lineEnds = this.scanner.lineEnds; + int length = lineEnds.length; + return Util.getLineNumber(position, lineEnds, (lineRange[0] > length ? length : lineRange[0]) -1, (lineRange[1] > length ? length : lineRange[1]) - 1); + } + + /* * Returns the extended end position of the given node. */ public int getExtendedEnd(ASTNode node) { @@ -285,14 +297,14 @@ * If finally there's leading still comments, then stores indexes of the first and last one * in leading comments table. */ - int storeLeadingComments(ASTNode node, int previousEnd) { + int storeLeadingComments(ASTNode node, int previousEnd, int[] parentLineRange) { // Init extended position int nodeStart = node.getStartPosition(); int extended = nodeStart; // Get line of node start position - int previousEndLine = this.scanner.getLineNumber(previousEnd); - int nodeStartLine = this.scanner.getLineNumber(nodeStart); + int previousEndLine = getLineNumber(previousEnd, parentLineRange); + int nodeStartLine = getLineNumber(nodeStart, parentLineRange); // Find first comment index int idx = getCommentIndex(0, nodeStart, -1); @@ -309,7 +321,7 @@ Comment comment = this.comments[idx]; int commentStart = comment.getStartPosition(); int end = commentStart+comment.getLength()-1; - int commentLine = this.scanner.getLineNumber(commentStart); + int commentLine = getLineNumber(commentStart, parentLineRange); if (end <= previousEnd || (commentLine == previousEndLine && commentLine != nodeStartLine)) { // stop search on condition 1) and 2) break; @@ -360,9 +372,9 @@ } catch (InvalidInputException e) { // do nothing } - int lastTokenLine = this.scanner.getLineNumber(lastTokenEnd); + int lastTokenLine = getLineNumber(lastTokenEnd, parentLineRange); int length = this.comments.length; - while (startIdx -1 ? this.parentLineRange[this.siblingPtr] : new int[] {1, DefaultCommentMapper.this.scanner.linePtr+1}; try { - storeLeadingComments(node, previousEnd); + storeLeadingComments(node, previousEnd, previousLineRange); } catch (Exception ex) { // Give up extended ranges at this level if unexpected exception happens... } // Store current node as waiting sibling for its parent - this.waitingSiblings.put(parent, node); + if (this.topSiblingParent != parent) { + if (this.siblings.length == ++this.siblingPtr) { + System.arraycopy(this.siblings, 0, this.siblings = new ASTNode[this.siblingPtr*2], 0, this.siblingPtr); + System.arraycopy(this.parentLineRange, 0, this.parentLineRange = new int[this.siblingPtr*2][], 0, this.siblingPtr); + } + if (this.topSiblingParent == null) { + // node is a CompilationUnit + this.parentLineRange[this.siblingPtr] = previousLineRange; + } else { + int parentStart = parent.getStartPosition(); + int firstLine = getLineNumber(parentStart, previousLineRange); + int lastLine = getLineNumber(parentStart + parent.getLength() - 1, previousLineRange); + if (this.parentLineRange[this.siblingPtr] == null) { + this.parentLineRange[this.siblingPtr] = new int[] {firstLine, lastLine}; + } else { + int[] lineRange = this.parentLineRange[this.siblingPtr]; + lineRange[0] = firstLine; + lineRange[1] = lastLine; + } + } + this.topSiblingParent = parent; + } + this.siblings[this.siblingPtr] = node; // We're always ok to visit sub-levels return true; @@ -582,14 +620,20 @@ protected void endVisitNode(ASTNode node) { // Look if a child node is waiting for trailing comments computing - ASTNode sibling = (ASTNode) this.waitingSiblings.get(node); + ASTNode sibling = this.topSiblingParent == node ? (ASTNode) this.siblings[this.siblingPtr] : null; if (sibling != null) { try { - storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true); + storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true, this.parentLineRange[this.siblingPtr]); } catch (Exception ex) { // Give up extended ranges at this level if unexpected exception happens... } } + // Remove sibling if needed + if (this.topSiblingParent != null /*not a CompilationUnit*/ + && this.topSiblingParent == node) { + this.siblingPtr--; + this.topSiblingParent = node.getParent(); + } } public boolean visit ( CompilationUnit node) { Index: dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java,v retrieving revision 1.5 diff -u -r1.5 DefaultASTVisitor.java --- dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java 24 Nov 2006 13:33:40 -0000 1.5 +++ dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java 6 Apr 2007 16:22:50 -0000 @@ -239,6 +239,9 @@ public boolean visit(LineComment node) { return visitNode(node); } + public boolean visit(MarkerAnnotation node) { + return visitNode(node); + } public boolean visit(MemberRef node) { return visitNode(node); } @@ -455,6 +458,9 @@ public void endVisit(LineComment node) { endVisitNode(node); } + public void endVisit(MarkerAnnotation node) { + endVisitNode(node); + } public void endVisit(MemberRef node) { endVisitNode(node); } Index: compiler/org/eclipse/jdt/internal/compiler/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java,v retrieving revision 1.60 diff -u -r1.60 Util.java --- compiler/org/eclipse/jdt/internal/compiler/util/Util.java 24 Nov 2006 01:32:03 -0000 1.60 +++ compiler/org/eclipse/jdt/internal/compiler/util/Util.java 6 Apr 2007 16:22:50 -0000 @@ -248,6 +248,28 @@ return contents; } + public static int getLineNumber(int position, int[] lineEnds, int g, int d) { + if (lineEnds == null) + return 1; + if (d == -1) + return 1; + int m = g, start; + while (g <= d) { + m = g + (d - g) /2; + if (position < (start = lineEnds[m])) { + d = m-1; + } else if (position > start) { + g = m+1; + } else { + return m + 1; + } + } + if (position < lineEnds[m]) { + return m+1; + } + return m+2; + } + /** * Returns the contents of the given zip entry as a byte array. * @throws IOException if a problem occured reading the zip entry. @@ -425,31 +447,6 @@ } } /** - * INTERNAL USE-ONLY - * Search the line number corresponding to a specific position - */ - public static final int searchLineNumber(int[] startLineIndexes, int position) { - int length = startLineIndexes.length; - if (length == 0) - return 1; - int g = 0, d = length - 1; - int m = 0, start; - while (g <= d) { - m = d + (g - d) / 2; - if (position < (start = startLineIndexes[m])) { - d = m - 1; - } else if (position > start) { - g = m + 1; - } else { - return m + 1; - } - } - if (position < startLineIndexes[m]) { - return m + 1; - } - return m + 2; - } - /** * Converts a boolean value into Boolean. * @param bool The boolean to convert * @return The corresponding Boolean object (TRUE or FALSE). Index: compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java,v retrieving revision 1.150 diff -u -r1.150 CodeStream.java --- compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java 6 Mar 2007 02:38:51 -0000 1.150 +++ compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java 6 Apr 2007 16:22:46 -0000 @@ -5765,7 +5765,7 @@ // resize the array pcToSourceMap System.arraycopy(pcToSourceMap, 0, pcToSourceMap = new int[pcToSourceMapSize << 1], 0, pcToSourceMapSize); } - int lineNumber = Util.searchLineNumber(lineSeparatorPositions, sourcePos); + int lineNumber = Util.getLineNumber(sourcePos, lineSeparatorPositions, 0, lineSeparatorPositions.length-1); // lastEntryPC represents the endPC of the lastEntry. if (pcToSourceMapSize > 0) { // in this case there is already an entry in the table Index: compiler/org/eclipse/jdt/internal/compiler/ClassFile.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java,v retrieving revision 1.146 diff -u -r1.146 ClassFile.java --- compiler/org/eclipse/jdt/internal/compiler/ClassFile.java 6 Mar 2007 02:38:51 -0000 1.146 +++ compiler/org/eclipse/jdt/internal/compiler/ClassFile.java 6 Apr 2007 16:22:44 -0000 @@ -3270,7 +3270,7 @@ this.contents[localContentsOffset++] = 0; this.contents[localContentsOffset++] = 1; if (problemLine == 0) { - problemLine = Util.searchLineNumber(startLineIndexes, binding.sourceStart()); + problemLine = Util.getLineNumber(binding.sourceStart(), startLineIndexes, 0, startLineIndexes.length-1); } // first entry at pc = 0 this.contents[localContentsOffset++] = 0; @@ -3712,7 +3712,7 @@ this.contents[localContentsOffset++] = 0; this.contents[localContentsOffset++] = 1; if (problemLine == 0) { - problemLine = Util.searchLineNumber(startLineIndexes, binding.sourceStart()); + problemLine = Util.getLineNumber(binding.sourceStart(), startLineIndexes, 0, startLineIndexes.length-1); } // first entry at pc = 0 this.contents[localContentsOffset++] = 0; @@ -4431,7 +4431,7 @@ localContentsOffset += 6; // leave space for attribute_length and line_number_table_length // Seems like do would be better, but this preserves the existing behavior. - index = Util.searchLineNumber(startLineIndexes, binding.sourceStart); + index = Util.getLineNumber(binding.sourceStart, startLineIndexes, 0, startLineIndexes.length-1); contents[localContentsOffset++] = 0; contents[localContentsOffset++] = 0; contents[localContentsOffset++] = (byte) (index >> 8); Index: codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java,v retrieving revision 1.8 diff -u -r1.8 UnresolvedReferenceNameFinder.java --- codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java 6 Mar 2007 02:38:51 -0000 1.8 +++ codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java 6 Apr 2007 16:22:42 -0000 @@ -30,6 +30,7 @@ import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.lookup.Scope; import org.eclipse.jdt.internal.compiler.util.SimpleSetOfCharArray; +import org.eclipse.jdt.internal.compiler.util.Util; public class UnresolvedReferenceNameFinder extends ASTVisitor { private static final int MAX_LINE_COUNT = 100; @@ -111,7 +112,7 @@ int maxEnd = this.completionScanner.getLineEnd( - this.completionScanner.getLineNumber(from) + maxLineCount); + Util.getLineNumber(from, this.completionScanner.lineEnds, 0, this.completionScanner.linePtr) + maxLineCount); int end; if (maxEnd < 0) { @@ -160,7 +161,7 @@ int minStart = this.completionScanner.getLineStart( - this.completionScanner.getLineNumber(to) - maxLineCount); + Util.getLineNumber(to, this.completionScanner.lineEnds, 0, this.completionScanner.linePtr) - maxLineCount); int start; int fakeBlocksCount;