Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java,v
retrieving revision 1.48
diff -u -r1.48 CompletionScanner.java
--- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java 28 Jul 2005 16:33:23 -0000 1.48
+++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java 21 Sep 2005 18:34:39 -0000
@@ -133,8 +133,6 @@
//checkNonExternalizedString();
if (this.recordLineSeparator) {
pushLineSeparator();
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
isWhiteSpace =
@@ -613,8 +611,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
if (this.tokenizeComments) {
@@ -659,8 +655,6 @@
if (!isUnicode) {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
isUnicode = false;
@@ -689,8 +683,6 @@
if (!isUnicode) {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
star = this.currentCharacter == '*';
Index: compiler/org/eclipse/jdt/core/compiler/CharOperation.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/CharOperation.java,v
retrieving revision 1.47
diff -u -r1.47 CharOperation.java
--- compiler/org/eclipse/jdt/core/compiler/CharOperation.java 3 Aug 2005 15:46:51 -0000 1.47
+++ compiler/org/eclipse/jdt/core/compiler/CharOperation.java 21 Sep 2005 18:34:39 -0000
@@ -1605,6 +1605,53 @@
}
/**
+ * Answers the first index in the array for which the corresponding character is
+ * equal to toBeFound starting the search at index start and before the ending index.
+ * Answers -1 if no occurrence of this character is found.
+ *
+ *
+ * For example:
+ *
+ *
+ * toBeFound = 'c'
+ * array = { ' a', 'b', 'c', 'd' }
+ * start = 2
+ * result => 2
+ *
+ *
+ *
+ * toBeFound = 'c'
+ * array = { ' a', 'b', 'c', 'd' }
+ * start = 3
+ * result => -1
+ *
+ *
+ *
+ * toBeFound = 'e'
+ * array = { ' a', 'b', 'c', 'd' }
+ * start = 1
+ * result => -1
+ *
+ *
+ *
+ *
+ * @param toBeFound the character to search
+ * @param array the array to be searched
+ * @param start the starting index (inclusive)
+ * @param end the ending index (exclusive)
+ * @return the first index in the array for which the corresponding character is
+ * equal to toBeFound, -1 otherwise
+ * @throws NullPointerException if array is null
+ * @throws ArrayIndexOutOfBoundsException if start is lower than 0 or ending greater than array length
+ */
+ public static final int indexOf(char toBeFound, char[] array, int start, int end) {
+ for (int i = start; i < end; i++)
+ if (toBeFound == array[i])
+ return i;
+ return -1;
+ }
+
+ /**
* Answers the last index in the array for which the corresponding character is
* equal to toBeFound starting from the end of the array.
* Answers -1 if no occurrence of this character is found.
Index: compiler/org/eclipse/jdt/internal/compiler/parser/NLSLine.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/NLSLine.java,v
retrieving revision 1.15
diff -u -r1.15 NLSLine.java
--- compiler/org/eclipse/jdt/internal/compiler/parser/NLSLine.java 28 Jul 2005 16:33:24 -0000 1.15
+++ compiler/org/eclipse/jdt/internal/compiler/parser/NLSLine.java 21 Sep 2005 18:34:39 -0000
@@ -18,6 +18,7 @@
public class NLSLine {
public List elements;
+ public int remainingElementsSize;
public NLSLine() {
this.elements = new ArrayList();
@@ -28,6 +29,7 @@
*/
public void add(StringLiteral element) {
this.elements.add(element);
+ this.remainingElementsSize++;
}
public StringLiteral get(int index) {
@@ -36,10 +38,7 @@
public void set(int index, StringLiteral literal) {
this.elements.set(index, literal);
- }
-
- public boolean exists(int index) {
- return index >= 0 && index < this.elements.size();
+ this.remainingElementsSize--;
}
public int size(){
Index: compiler/org/eclipse/jdt/internal/compiler/parser/NLSTag.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/NLSTag.java,v
retrieving revision 1.2
diff -u -r1.2 NLSTag.java
--- compiler/org/eclipse/jdt/internal/compiler/parser/NLSTag.java 12 Aug 2005 18:27:40 -0000 1.2
+++ compiler/org/eclipse/jdt/internal/compiler/parser/NLSTag.java 21 Sep 2005 18:34:39 -0000
@@ -15,6 +15,7 @@
public int start;
public int end;
public int bits;
+
public static final int USED = 1;
public static final int UNUSED = 2;
Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v
retrieving revision 1.315
diff -u -r1.315 Parser.java
--- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 7 Sep 2005 07:45:57 -0000 1.315
+++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 21 Sep 2005 18:34:40 -0000
@@ -8028,7 +8028,6 @@
this.firstToken = TokenNamePLUS_PLUS ;
this.scanner.foundTaskCount = 0;
this.scanner.recordLineSeparator = true;
- if (this.scanner.currentLine != null) this.scanner.currentLine.clear();
}
public void goForExpression() {
//tells the scanner to go for an expression parsing
@@ -8481,7 +8480,59 @@
} while (act <= NUM_RULES);
}
endParse(act);
- reportNonExternalizedStringLiterals();
+ if (this.scanner.currentLine != null) {
+ final Set nonNLSStrings = this.scanner.nonNLSStrings;
+ if (nonNLSStrings != null) {
+ final int nonNLSStringsSize = nonNLSStrings.size();
+ StringLiteral[] literals = new StringLiteral[nonNLSStringsSize];
+ nonNLSStrings.toArray(literals);
+ Arrays.sort(literals, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ StringLiteral literal1 = (StringLiteral) o1;
+ StringLiteral literal2 = (StringLiteral) o2;
+ return literal1.sourceStart - literal2.sourceStart;
+ }
+ });
+ for (int i = 0; i < nonNLSStringsSize; i++) {
+ problemReporter().nonExternalizedStringLiteral(literals[i]);
+ }
+ }
+ final Set unnecessaryNLSTags = this.scanner.unnecessaryNLSTags;
+ if (unnecessaryNLSTags != null) {
+ final int unnecessaryNLSTagsSize = unnecessaryNLSTags.size();
+ if (unnecessaryNLSTagsSize != 0) {
+/* NLSTag[] tags = new NLSTag[unnecessaryNLSTagsSize];
+ unnecessaryNLSTags.toArray(tags);
+ // filter out all used nls tags
+ ArrayList arrayList = new ArrayList();
+ for (int i = 0; i < unnecessaryNLSTagsSize; i++) {
+ NLSTag tag = tags[i];
+ if ((tag.bits & NLSTag.UNUSED) != 0) {
+ arrayList.add(tag);
+ }
+ }*/
+ ArrayList arrayList = new ArrayList();
+ arrayList.addAll(unnecessaryNLSTags);
+ Collections.sort(arrayList, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ NLSTag tag1 = (NLSTag) o1;
+ NLSTag tag2 = (NLSTag) o1;
+ return tag1.start - tag2.start;
+ }
+ });
+ loop : for (int i = 0, max = arrayList.size(); i < max; i++) {
+ NLSTag tag = (NLSTag) arrayList.get(i);
+ if (tag.bits != NLSTag.UNUSED) {
+ continue loop;
+ }
+ problemReporter().unnecessaryNLSTags(tag.start, tag.end);
+ }
+ }
+ }
+ this.scanner.nonNLSStrings = null;
+ this.scanner.unnecessaryNLSTags = null;
+ this.scanner.currentLine = null;
+ }
if (this.reportSyntaxErrorIsRequired && this.hasError) {
reportSyntaxErrors(isDietParse, oldFirstToken);
}
@@ -9100,52 +9151,6 @@
}
this.ignoreNextOpeningBrace = false;
}
-protected void reportNonExternalizedStringLiterals() {
- final Set nonNLSStrings = this.scanner.nonNLSStrings;
- final int nonNLSStringsSize = nonNLSStrings == null ? 0 : nonNLSStrings.size();
- if (nonNLSStringsSize != 0) {
- StringLiteral[] literals = new StringLiteral[nonNLSStringsSize];
- nonNLSStrings.toArray(literals);
- Arrays.sort(literals, new Comparator() {
- public int compare(Object o1, Object o2) {
- StringLiteral literal1 = (StringLiteral) o1;
- StringLiteral literal2 = (StringLiteral) o2;
- return literal1.sourceStart - literal2.sourceStart;
- }
- });
- for (int i = 0; i < nonNLSStringsSize; i++) {
- problemReporter().nonExternalizedStringLiteral(literals[i]);
- }
- }
- final Set unnecessaryNLSTags = this.scanner.unnecessaryNLSTags;
- final int unnecessaryNLSTagsSize = unnecessaryNLSTags == null ? 0 : unnecessaryNLSTags.size();
- if (unnecessaryNLSTagsSize != 0) {
- NLSTag[] tags = new NLSTag[unnecessaryNLSTagsSize];
- unnecessaryNLSTags.toArray(tags);
- // filter out all used nls tags
- ArrayList arrayList = new ArrayList();
- for (int i = 0; i < unnecessaryNLSTagsSize; i++) {
- NLSTag tag = tags[i];
- if ((tag.bits & NLSTag.UNUSED) != 0) {
- arrayList.add(tag);
- }
- }
- Collections.sort(arrayList, new Comparator() {
- public int compare(Object o1, Object o2) {
- NLSTag tag1 = (NLSTag) o1;
- NLSTag tag2 = (NLSTag) o1;
- return tag1.start - tag2.start;
- }
- });
- for (int i = 0, max = arrayList.size(); i < max; i++) {
- NLSTag tag = (NLSTag) arrayList.get(i);
- problemReporter().unnecessaryNLSTags(tag.start, tag.end);
- }
- }
- this.scanner.nonNLSStrings = null;
- this.scanner.unnecessaryNLSTags = null;
- this.scanner.currentLine = null;
-}
// A P I
protected void reportSyntaxErrors(boolean isDietParse, int oldFirstToken) {
if(this.referenceContext instanceof MethodDeclaration) {
@@ -9239,8 +9244,11 @@
this.listLength = 0;
this.listTypeParameterLength = 0;
// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=29365
- if (this.scanner != null && this.scanner.currentLine != null) {
- this.scanner.currentLine.clear();
+ if (this.scanner != null) {
+ final NLSLine line = this.scanner.currentLine;
+ if (line != null) {
+ line.clear();
+ }
}
this.genericsIdentifiersLengthPtr = -1;
Index: compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java,v
retrieving revision 1.156
diff -u -r1.156 Scanner.java
--- compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 12 Aug 2005 18:27:40 -0000 1.156
+++ compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 21 Sep 2005 18:34:40 -0000
@@ -913,13 +913,11 @@
} else {
offset = this.currentPosition - offset;
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
pushLineSeparator();
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
// inline version of:
@@ -1355,8 +1353,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
if (this.tokenizeComments) {
@@ -1400,7 +1396,7 @@
star = true;
}
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1409,8 +1405,6 @@
} else {
pushLineSeparator();
}
- } else if (currentLine != null){
- this.currentLine.clear();
}
}
isUnicode = false;
@@ -1436,7 +1430,7 @@
int firstTag = 0;
while ((this.currentCharacter != '/') || (!star)) {
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1445,8 +1439,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
switch (this.currentCharacter) {
@@ -1638,7 +1630,7 @@
} else {
if (this.recordLineSeparator
&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
pushLineSeparator();
@@ -1863,7 +1855,7 @@
star = true;
}
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1872,8 +1864,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
isUnicode = false;
@@ -1898,7 +1888,7 @@
int firstTag = 0;
while ((this.currentCharacter != '/') || (!star)) {
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1907,8 +1897,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
switch (this.currentCharacter) {
@@ -2257,14 +2245,12 @@
}
protected void parseTags(boolean hasLineComment) {
- final NLSLine line = this.currentLine;
if (!hasLineComment) {
- if (line.size() == 0) return; // nothing to do
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
- this.nonNLSStrings.addAll(line.elements);
+ this.nonNLSStrings.addAll(this.currentLine.elements);
} else {
int position = 0;
- if (linePtr >= 0) {
+ if (this.linePtr >= 0) {
position = this.lineEnds[this.linePtr] + 1;
}
while (Character.isWhitespace(this.source[position])) {
@@ -2274,33 +2260,51 @@
// the whole line is commented out
return;
}
- char[] s = getCurrentTokenSource();
- int pos = CharOperation.indexOf(TAG_PREFIX, s, true);
+ final NLSLine line = this.currentLine;
+ char[] s = null;
+ int sourceEnd = this.currentPosition;
+ int sourceStart = this.startPosition;
+ int sourceDelta = 0;
+ if (this.withoutUnicodePtr != 0) {
+ // 0 is used as a fast test flag so the real first char is in position 1
+ System.arraycopy(
+ this.withoutUnicodeBuffer,
+ 1,
+ s = new char[this.withoutUnicodePtr],
+ 0,
+ this.withoutUnicodePtr);
+ sourceEnd = this.withoutUnicodePtr;
+ sourceStart = 1;
+ sourceDelta = this.getCurrentTokenStartPosition();
+ } else {
+ s = this.source;
+ }
+ int pos = CharOperation.indexOf(TAG_PREFIX, s, true, sourceStart, sourceEnd);
+ final int lineSize = line.size();
if (pos != -1) {
if (this.unnecessaryNLSTags == null) this.unnecessaryNLSTags = new HashSet();
while (pos != -1) {
int start = pos + TAG_PREFIX_LENGTH;
- int end = CharOperation.indexOf(TAG_POSTFIX, s, start);
+ int end = CharOperation.indexOf(TAG_POSTFIX, s, start, sourceEnd);
if (end != -1) {
String index = new String(CharOperation.subarray(s, start, end));
- int i = 0;
try {
- i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
- } catch (NumberFormatException e) {
- i = -1; // we don't want to consider this as a valid NLS tag
- }
- if (line != null && line.exists(i)) {
- if (line.get(i) == null) {
- this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
- } else {
- line.set(i, null);
- final NLSTag tag = new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end, NLSTag.USED);
- if (!this.unnecessaryNLSTags.add(tag)) {
- this.unnecessaryNLSTags.remove(tag);
- this.unnecessaryNLSTags.add(tag);
+ final int i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
+ if (i >= 0 && i < lineSize) {
+ if (line.get(i) == null) {
+ this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
+ } else {
+ line.set(i, null);
+ final NLSTag tag = new NLSTag(pos + sourceDelta , end + sourceDelta, NLSTag.USED);
+ if (!this.unnecessaryNLSTags.add(tag)) {
+ this.unnecessaryNLSTags.remove(tag);
+ this.unnecessaryNLSTags.add(tag);
+ }
}
+ } else {
+ this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
}
- } else {
+ } catch (NumberFormatException e) {
this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
}
}
@@ -2308,10 +2312,10 @@
}
}
- if (line.size() != 0) {
+ if (line.remainingElementsSize != 0) {
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
for (Iterator iterator = line.iterator(); iterator.hasNext(); ) {
- StringLiteral literal = (StringLiteral) iterator.next();
+ final StringLiteral literal = (StringLiteral) iterator.next();
if (literal != null) {
this.nonNLSStrings.add(literal);
}
@@ -2324,13 +2328,7 @@
public final void pushLineSeparator() {
//see comment on isLineDelimiter(char) for the use of '\n' and '\r'
final int INCREMENT = 250;
-
- if (this.currentLine != null) {
- // reinitialize the current line for non externalize strings purpose
- this.currentLine.clear();
- }
//currentCharacter is at position currentPosition-1
-
// cr 000D
if (this.currentCharacter == '\r') {
int separatorPos = this.currentPosition - 1;
@@ -2370,12 +2368,7 @@
}
}
}
-public final void pushUnicodeLineSeparator() {
- if (this.currentLine != null) {
- // reinitialize the current line for non externalize strings purpose
- this.currentLine.clear();
- }
-
+public final void pushUnicodeLineSeparator() {
// cr 000D
if (this.currentCharacter == '\r') {
if (this.source[this.currentPosition] == '\n') {
Index: model/org/eclipse/jdt/internal/core/util/PublicScanner.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/PublicScanner.java,v
retrieving revision 1.76
diff -u -r1.76 PublicScanner.java
--- model/org/eclipse/jdt/internal/core/util/PublicScanner.java 11 Aug 2005 15:51:16 -0000 1.76
+++ model/org/eclipse/jdt/internal/core/util/PublicScanner.java 21 Sep 2005 18:34:41 -0000
@@ -209,7 +209,7 @@
public static final char TAG_POSTFIX= '$';
public static final int TAG_POSTFIX_LENGTH= 1;
public Set nonNLSStrings = null;
- public Set unnecessaryNONNLSTags = null;
+ public Set unnecessaryNLSTags = null;
// generic support
public boolean returnOnlyGreater = false;
@@ -904,7 +904,6 @@
if (this.currentPosition > this.eofPosition)
return TokenNameEOF;
}
- //little trick to get out in the middle of a source compuation
if (this.currentPosition > this.eofPosition)
return TokenNameEOF;
if (checkIfUnicode) {
@@ -913,13 +912,11 @@
} else {
offset = this.currentPosition - offset;
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
pushLineSeparator();
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
// inline version of:
@@ -1355,8 +1352,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
if (this.tokenizeComments) {
@@ -1400,7 +1395,7 @@
star = true;
}
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1409,8 +1404,6 @@
} else {
pushLineSeparator();
}
- } else if (currentLine != null){
- this.currentLine.clear();
}
}
isUnicode = false;
@@ -1436,7 +1429,7 @@
int firstTag = 0;
while ((this.currentCharacter != '/') || (!star)) {
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1445,8 +1438,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
switch (this.currentCharacter) {
@@ -1638,7 +1629,7 @@
} else {
if (this.recordLineSeparator
&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
pushLineSeparator();
@@ -1863,7 +1854,7 @@
star = true;
}
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1872,8 +1863,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
isUnicode = false;
@@ -1898,7 +1887,7 @@
int firstTag = 0;
while ((this.currentCharacter != '/') || (!star)) {
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
- if (this.currentLine != null) {
+ if (this.currentLine != null && this.currentLine.size() != 0) {
parseTags(false);
}
if (this.recordLineSeparator) {
@@ -1907,8 +1896,6 @@
} else {
pushLineSeparator();
}
- } else if (this.currentLine != null) {
- this.currentLine.clear();
}
}
switch (this.currentCharacter) {
@@ -2257,46 +2244,77 @@
}
protected void parseTags(boolean hasLineComment) {
- final NLSLine line = this.currentLine;
if (!hasLineComment) {
- if (line.size() == 0) return; // nothing to do
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
- this.nonNLSStrings.addAll(line.elements);
+ this.nonNLSStrings.addAll(this.currentLine.elements);
} else {
- char[] s = getCurrentTokenSource();
- int pos = CharOperation.indexOf(TAG_PREFIX, s, true);
+ int position = 0;
+ if (this.linePtr >= 0) {
+ position = this.lineEnds[this.linePtr] + 1;
+ }
+ while (Character.isWhitespace(this.source[position])) {
+ position++;
+ }
+ if (getCurrentTokenStartPosition() == position) {
+ // the whole line is commented out
+ return;
+ }
+ final NLSLine line = this.currentLine;
+ char[] s = null;
+ int sourceEnd = this.currentPosition;
+ int sourceStart = this.startPosition;
+ int sourceDelta = 0;
+ if (this.withoutUnicodePtr != 0) {
+ // 0 is used as a fast test flag so the real first char is in position 1
+ System.arraycopy(
+ this.withoutUnicodeBuffer,
+ 1,
+ s = new char[this.withoutUnicodePtr],
+ 0,
+ this.withoutUnicodePtr);
+ sourceEnd = this.withoutUnicodePtr;
+ sourceStart = 1;
+ sourceDelta = this.getCurrentTokenStartPosition();
+ } else {
+ s = this.source;
+ }
+ int pos = CharOperation.indexOf(TAG_PREFIX, s, true, sourceStart, sourceEnd);
+ final int lineSize = line.size();
if (pos != -1) {
- if (this.unnecessaryNONNLSTags == null) this.unnecessaryNONNLSTags = new HashSet();
+ if (this.unnecessaryNLSTags == null) this.unnecessaryNLSTags = new HashSet();
while (pos != -1) {
int start = pos + TAG_PREFIX_LENGTH;
- int end = CharOperation.indexOf(TAG_POSTFIX, s, start);
+ int end = CharOperation.indexOf(TAG_POSTFIX, s, start, sourceEnd);
if (end != -1) {
String index = new String(CharOperation.subarray(s, start, end));
- int i = 0;
try {
- i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
- } catch (NumberFormatException e) {
- i = -1; // we don't want to consider this as a valid NLS tag
- }
- if (line != null && line.exists(i)) {
- line.set(i, null);
- final NLSTag tag = new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end, NLSTag.USED);
- if (!this.unnecessaryNONNLSTags.add(tag)) {
- this.unnecessaryNONNLSTags.remove(tag);
- this.unnecessaryNONNLSTags.add(tag);
+ final int i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
+ if (i >= 0 && i < lineSize) {
+ if (line.get(i) == null) {
+ this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
+ } else {
+ line.set(i, null);
+ final NLSTag tag = new NLSTag(pos + sourceDelta , end + sourceDelta, NLSTag.USED);
+ if (!this.unnecessaryNLSTags.add(tag)) {
+ this.unnecessaryNLSTags.remove(tag);
+ this.unnecessaryNLSTags.add(tag);
+ }
+ }
+ } else {
+ this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
}
- } else {
- this.unnecessaryNONNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
+ } catch (NumberFormatException e) {
+ this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
}
}
pos = CharOperation.indexOf(TAG_PREFIX, s, true, start);
}
}
- if (line.size() != 0) {
+ if (line.remainingElementsSize != 0) {
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
for (Iterator iterator = line.iterator(); iterator.hasNext(); ) {
- StringLiteral literal = (StringLiteral) iterator.next();
+ final StringLiteral literal = (StringLiteral) iterator.next();
if (literal != null) {
this.nonNLSStrings.add(literal);
}
@@ -2309,13 +2327,7 @@
public final void pushLineSeparator() {
//see comment on isLineDelimiter(char) for the use of '\n' and '\r'
final int INCREMENT = 250;
-
- if (this.currentLine != null) {
- // reinitialize the current line for non externalize strings purpose
- this.currentLine.clear();
- }
//currentCharacter is at position currentPosition-1
-
// cr 000D
if (this.currentCharacter == '\r') {
int separatorPos = this.currentPosition - 1;
@@ -2356,11 +2368,6 @@
}
}
public final void pushUnicodeLineSeparator() {
- if (this.currentLine != null) {
- // reinitialize the current line for non externalize strings purpose
- this.currentLine.clear();
- }
-
// cr 000D
if (this.currentCharacter == '\r') {
if (this.source[this.currentPosition] == '\n') {