View | Details | Raw Unified | Return to bug 110082
Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java (-8 lines)
Lines 133-140 Link Here
133
						//checkNonExternalizedString();
133
						//checkNonExternalizedString();
134
						if (this.recordLineSeparator) {
134
						if (this.recordLineSeparator) {
135
							pushLineSeparator();
135
							pushLineSeparator();
136
						} else if (this.currentLine != null) {
137
							this.currentLine.clear();
138
						}
136
						}
139
					}
137
					}
140
					isWhiteSpace = 
138
					isWhiteSpace = 
Lines 613-620 Link Here
613
										} else {
611
										} else {
614
											pushLineSeparator();
612
											pushLineSeparator();
615
										}
613
										}
616
									} else if (this.currentLine != null) {
617
										this.currentLine.clear();
618
									}
614
									}
619
								}
615
								}
620
								if (this.tokenizeComments) {
616
								if (this.tokenizeComments) {
Lines 659-666 Link Here
659
										if (!isUnicode) {
655
										if (!isUnicode) {
660
											pushLineSeparator();
656
											pushLineSeparator();
661
										}
657
										}
662
									} else if (this.currentLine != null) {
663
										this.currentLine.clear();
664
									}
658
									}
665
								}
659
								}
666
								isUnicode = false;
660
								isUnicode = false;
Lines 689-696 Link Here
689
											if (!isUnicode) {
683
											if (!isUnicode) {
690
												pushLineSeparator();
684
												pushLineSeparator();
691
											}
685
											}
692
										} else if (this.currentLine != null) {
693
											this.currentLine.clear();
694
										}
686
										}
695
									}
687
									}
696
									star = this.currentCharacter == '*';
688
									star = this.currentCharacter == '*';
(-)compiler/org/eclipse/jdt/core/compiler/CharOperation.java (+47 lines)
Lines 1605-1610 Link Here
1605
	}
1605
	}
1606
1606
1607
	/**
1607
	/**
1608
	 * Answers the first index in the array for which the corresponding character is
1609
	 * equal to toBeFound starting the search at index start and before the ending index.
1610
	 * Answers -1 if no occurrence of this character is found.
1611
	 * <br>
1612
	 * <br>
1613
	 * For example:
1614
	 * <ol>
1615
	 * <li><pre>
1616
	 *    toBeFound = 'c'
1617
	 *    array = { ' a', 'b', 'c', 'd' }
1618
	 *    start = 2
1619
	 *    result => 2
1620
	 * </pre>
1621
	 * </li>
1622
	 * <li><pre>
1623
	 *    toBeFound = 'c'
1624
	 *    array = { ' a', 'b', 'c', 'd' }
1625
	 *    start = 3
1626
	 *    result => -1
1627
	 * </pre>
1628
	 * </li>
1629
	 * <li><pre>
1630
	 *    toBeFound = 'e'
1631
	 *    array = { ' a', 'b', 'c', 'd' }
1632
	 *    start = 1
1633
	 *    result => -1
1634
	 * </pre>
1635
	 * </li>
1636
	 * </ol>
1637
	 * 
1638
	 * @param toBeFound the character to search
1639
	 * @param array the array to be searched
1640
	 * @param start the starting index (inclusive)
1641
	 * @param end the ending index (exclusive)
1642
	 * @return the first index in the array for which the corresponding character is
1643
	 * equal to toBeFound, -1 otherwise
1644
	 * @throws NullPointerException if array is null
1645
	 * @throws ArrayIndexOutOfBoundsException if  start is lower than 0 or ending greater than array length
1646
	 */
1647
	public static final int indexOf(char toBeFound, char[] array, int start, int end) {
1648
		for (int i = start; i < end; i++)
1649
			if (toBeFound == array[i])
1650
				return i;
1651
		return -1;
1652
	}
1653
	
1654
	/**
1608
	 * Answers the last index in the array for which the corresponding character is
1655
	 * Answers the last index in the array for which the corresponding character is
1609
	 * equal to toBeFound starting from the end of the array.
1656
	 * equal to toBeFound starting from the end of the array.
1610
	 * Answers -1 if no occurrence of this character is found.
1657
	 * Answers -1 if no occurrence of this character is found.
(-)compiler/org/eclipse/jdt/internal/compiler/parser/NLSLine.java (-4 / +3 lines)
Lines 18-23 Link Here
18
public class NLSLine {
18
public class NLSLine {
19
19
20
	public List elements;
20
	public List elements;
21
	public int remainingElementsSize;
21
22
22
	public NLSLine() {
23
	public NLSLine() {
23
		this.elements = new ArrayList();
24
		this.elements = new ArrayList();
Lines 28-33 Link Here
28
	 */
29
	 */
29
	public void add(StringLiteral element) {
30
	public void add(StringLiteral element) {
30
		this.elements.add(element);
31
		this.elements.add(element);
32
		this.remainingElementsSize++;
31
	}
33
	}
32
	
34
	
33
	public StringLiteral get(int index) {
35
	public StringLiteral get(int index) {
Lines 36-45 Link Here
36
	
38
	
37
	public void set(int index, StringLiteral literal) {
39
	public void set(int index, StringLiteral literal) {
38
		this.elements.set(index, literal);
40
		this.elements.set(index, literal);
39
	}
41
		this.remainingElementsSize--;
40
	
41
	public boolean exists(int index) {
42
		return index >= 0 && index < this.elements.size();
43
	}
42
	}
44
	
43
	
45
	public int size(){
44
	public int size(){
(-)compiler/org/eclipse/jdt/internal/compiler/parser/NLSTag.java (+1 lines)
Lines 15-20 Link Here
15
	public int start;
15
	public int start;
16
	public int end;
16
	public int end;
17
	public int bits;
17
	public int bits;
18
18
	public static final int USED = 1;
19
	public static final int USED = 1;
19
	public static final int UNUSED = 2;
20
	public static final int UNUSED = 2;
20
	
21
	
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-50 / +58 lines)
Lines 8028-8034 Link Here
8028
	this.firstToken = TokenNamePLUS_PLUS ;
8028
	this.firstToken = TokenNamePLUS_PLUS ;
8029
	this.scanner.foundTaskCount = 0;
8029
	this.scanner.foundTaskCount = 0;
8030
	this.scanner.recordLineSeparator = true;
8030
	this.scanner.recordLineSeparator = true;
8031
	if (this.scanner.currentLine != null) this.scanner.currentLine.clear();
8032
}
8031
}
8033
public void goForExpression() {
8032
public void goForExpression() {
8034
	//tells the scanner to go for an expression parsing
8033
	//tells the scanner to go for an expression parsing
Lines 8481-8487 Link Here
8481
		} while (act <= NUM_RULES);
8480
		} while (act <= NUM_RULES);
8482
	}
8481
	}
8483
	endParse(act);
8482
	endParse(act);
8484
	reportNonExternalizedStringLiterals();
8483
	if (this.scanner.currentLine != null) {
8484
		final Set nonNLSStrings = this.scanner.nonNLSStrings;
8485
		if (nonNLSStrings != null) {
8486
			final int nonNLSStringsSize = nonNLSStrings.size();
8487
			StringLiteral[] literals = new StringLiteral[nonNLSStringsSize];
8488
			nonNLSStrings.toArray(literals);
8489
			Arrays.sort(literals, new Comparator() {
8490
				public int compare(Object o1, Object o2) {
8491
					StringLiteral literal1 = (StringLiteral) o1;
8492
					StringLiteral literal2 = (StringLiteral) o2;
8493
					return literal1.sourceStart - literal2.sourceStart;
8494
				}
8495
			});
8496
			for (int i = 0; i < nonNLSStringsSize; i++) {
8497
				problemReporter().nonExternalizedStringLiteral(literals[i]);
8498
			}
8499
		}
8500
		final Set unnecessaryNLSTags = this.scanner.unnecessaryNLSTags;
8501
		if (unnecessaryNLSTags != null) {
8502
			final int unnecessaryNLSTagsSize = unnecessaryNLSTags.size();
8503
			if (unnecessaryNLSTagsSize != 0) {
8504
/*				NLSTag[] tags = new NLSTag[unnecessaryNLSTagsSize];
8505
				unnecessaryNLSTags.toArray(tags);
8506
				// filter out all used nls tags
8507
				ArrayList arrayList = new ArrayList();
8508
				for (int i = 0; i < unnecessaryNLSTagsSize; i++) {
8509
					NLSTag tag = tags[i];
8510
					if ((tag.bits & NLSTag.UNUSED) != 0) {
8511
						arrayList.add(tag);
8512
					}
8513
				}*/
8514
				ArrayList arrayList = new ArrayList();
8515
				arrayList.addAll(unnecessaryNLSTags);
8516
				Collections.sort(arrayList, new Comparator() {
8517
					public int compare(Object o1, Object o2) {
8518
						NLSTag tag1 = (NLSTag) o1;
8519
						NLSTag tag2 = (NLSTag) o1;
8520
						return tag1.start - tag2.start;
8521
					}
8522
				});
8523
				loop : for (int i = 0, max = arrayList.size(); i < max; i++) {
8524
					NLSTag tag = (NLSTag) arrayList.get(i); 
8525
					if (tag.bits != NLSTag.UNUSED) {
8526
						continue loop;
8527
					}
8528
					problemReporter().unnecessaryNLSTags(tag.start, tag.end);
8529
				}
8530
			}
8531
		}
8532
		this.scanner.nonNLSStrings = null;
8533
		this.scanner.unnecessaryNLSTags = null;
8534
		this.scanner.currentLine = null;
8535
	}
8485
	if (this.reportSyntaxErrorIsRequired && this.hasError) {
8536
	if (this.reportSyntaxErrorIsRequired && this.hasError) {
8486
		reportSyntaxErrors(isDietParse, oldFirstToken);
8537
		reportSyntaxErrors(isDietParse, oldFirstToken);
8487
	}	
8538
	}	
Lines 9100-9151 Link Here
9100
	}
9151
	}
9101
	this.ignoreNextOpeningBrace = false;
9152
	this.ignoreNextOpeningBrace = false;
9102
}
9153
}
9103
protected void reportNonExternalizedStringLiterals() {
9104
	final Set nonNLSStrings = this.scanner.nonNLSStrings;
9105
	final int nonNLSStringsSize = nonNLSStrings == null ? 0 : nonNLSStrings.size();
9106
	if (nonNLSStringsSize != 0) {
9107
		StringLiteral[] literals = new StringLiteral[nonNLSStringsSize];
9108
		nonNLSStrings.toArray(literals);
9109
		Arrays.sort(literals, new Comparator() {
9110
			public int compare(Object o1, Object o2) {
9111
				StringLiteral literal1 = (StringLiteral) o1;
9112
				StringLiteral literal2 = (StringLiteral) o2;
9113
				return literal1.sourceStart - literal2.sourceStart;
9114
			}
9115
		});
9116
		for (int i = 0; i < nonNLSStringsSize; i++) {
9117
			problemReporter().nonExternalizedStringLiteral(literals[i]);
9118
		}
9119
	}
9120
	final Set unnecessaryNLSTags = this.scanner.unnecessaryNLSTags;
9121
	final int unnecessaryNLSTagsSize = unnecessaryNLSTags == null ? 0 : unnecessaryNLSTags.size();
9122
	if (unnecessaryNLSTagsSize != 0) {
9123
		NLSTag[] tags = new NLSTag[unnecessaryNLSTagsSize];
9124
		unnecessaryNLSTags.toArray(tags);
9125
		// filter out all used nls tags
9126
		ArrayList arrayList = new ArrayList();
9127
		for (int i = 0; i < unnecessaryNLSTagsSize; i++) {
9128
			NLSTag tag = tags[i];
9129
			if ((tag.bits & NLSTag.UNUSED) != 0) {
9130
				arrayList.add(tag);
9131
			}
9132
		}
9133
		Collections.sort(arrayList, new Comparator() {
9134
			public int compare(Object o1, Object o2) {
9135
				NLSTag tag1 = (NLSTag) o1;
9136
				NLSTag tag2 = (NLSTag) o1;
9137
				return tag1.start - tag2.start;
9138
			}
9139
		});
9140
		for (int i = 0, max = arrayList.size(); i < max; i++) {
9141
			NLSTag tag = (NLSTag) arrayList.get(i); 
9142
			problemReporter().unnecessaryNLSTags(tag.start, tag.end);
9143
		}
9144
	}
9145
	this.scanner.nonNLSStrings = null;
9146
	this.scanner.unnecessaryNLSTags = null;
9147
	this.scanner.currentLine = null;
9148
}
9149
// A P I
9154
// A P I
9150
protected void reportSyntaxErrors(boolean isDietParse, int oldFirstToken) {
9155
protected void reportSyntaxErrors(boolean isDietParse, int oldFirstToken) {
9151
	if(this.referenceContext instanceof MethodDeclaration) {
9156
	if(this.referenceContext instanceof MethodDeclaration) {
Lines 9239-9246 Link Here
9239
	this.listLength = 0;
9244
	this.listLength = 0;
9240
	this.listTypeParameterLength = 0;
9245
	this.listTypeParameterLength = 0;
9241
	// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=29365
9246
	// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=29365
9242
	if (this.scanner != null && this.scanner.currentLine != null) {
9247
	if (this.scanner != null) {
9243
		this.scanner.currentLine.clear();
9248
		final NLSLine line = this.scanner.currentLine;
9249
		if (line != null) {
9250
			line.clear();
9251
		}
9244
	}
9252
	}
9245
	
9253
	
9246
	this.genericsIdentifiersLengthPtr = -1;
9254
	this.genericsIdentifiersLengthPtr = -1;
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java (-54 / +47 lines)
Lines 913-925 Link Here
913
				} else {
913
				} else {
914
					offset = this.currentPosition - offset;
914
					offset = this.currentPosition - offset;
915
					if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
915
					if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
916
						if (this.currentLine != null) {
916
						if (this.currentLine != null && this.currentLine.size() != 0) {
917
							parseTags(false);
917
							parseTags(false);
918
						}
918
						}
919
						if (this.recordLineSeparator) {
919
						if (this.recordLineSeparator) {
920
							pushLineSeparator();
920
							pushLineSeparator();
921
						} else if (this.currentLine != null) {
922
							this.currentLine.clear();
923
						}
921
						}
924
					}
922
					}
925
					// inline version of:
923
					// inline version of:
Lines 1355-1362 Link Here
1355
										} else {
1353
										} else {
1356
											pushLineSeparator();
1354
											pushLineSeparator();
1357
										}
1355
										}
1358
									} else if (this.currentLine != null) {
1359
										this.currentLine.clear();
1360
									}
1356
									}
1361
								}
1357
								}
1362
								if (this.tokenizeComments) {
1358
								if (this.tokenizeComments) {
Lines 1400-1406 Link Here
1400
									star = true;
1396
									star = true;
1401
								}
1397
								}
1402
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1398
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1403
									if (this.currentLine != null) {
1399
									if (this.currentLine != null && this.currentLine.size() != 0) {
1404
										parseTags(false);
1400
										parseTags(false);
1405
									}
1401
									}
1406
									if (this.recordLineSeparator) {
1402
									if (this.recordLineSeparator) {
Lines 1409-1416 Link Here
1409
										} else {
1405
										} else {
1410
											pushLineSeparator();
1406
											pushLineSeparator();
1411
										}
1407
										}
1412
									} else if (currentLine != null){
1413
										this.currentLine.clear();
1414
									}
1408
									}
1415
								}
1409
								}
1416
								isUnicode = false;
1410
								isUnicode = false;
Lines 1436-1442 Link Here
1436
								int firstTag = 0;
1430
								int firstTag = 0;
1437
								while ((this.currentCharacter != '/') || (!star)) {
1431
								while ((this.currentCharacter != '/') || (!star)) {
1438
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1432
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1439
										if (this.currentLine != null) {
1433
										if (this.currentLine != null && this.currentLine.size() != 0) {
1440
											parseTags(false);
1434
											parseTags(false);
1441
										}
1435
										}
1442
										if (this.recordLineSeparator) {
1436
										if (this.recordLineSeparator) {
Lines 1445-1452 Link Here
1445
											} else {
1439
											} else {
1446
												pushLineSeparator();
1440
												pushLineSeparator();
1447
											}
1441
											}
1448
										} else if (this.currentLine != null) {
1449
											this.currentLine.clear();
1450
										}
1442
										}
1451
									}
1443
									}
1452
									switch (this.currentCharacter) {
1444
									switch (this.currentCharacter) {
Lines 1638-1644 Link Here
1638
				} else {
1630
				} else {
1639
					if (this.recordLineSeparator
1631
					if (this.recordLineSeparator
1640
							&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1632
							&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1641
						if (this.currentLine != null) {
1633
						if (this.currentLine != null && this.currentLine.size() != 0) {
1642
							parseTags(false);
1634
							parseTags(false);
1643
						}
1635
						}
1644
						pushLineSeparator();
1636
						pushLineSeparator();
Lines 1863-1869 Link Here
1863
									star = true;
1855
									star = true;
1864
								}
1856
								}
1865
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1857
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1866
									if (this.currentLine != null) {
1858
									if (this.currentLine != null && this.currentLine.size() != 0) {
1867
										parseTags(false);
1859
										parseTags(false);
1868
									}
1860
									}
1869
									if (this.recordLineSeparator) {
1861
									if (this.recordLineSeparator) {
Lines 1872-1879 Link Here
1872
										} else {
1864
										} else {
1873
											pushLineSeparator();
1865
											pushLineSeparator();
1874
										}
1866
										}
1875
									} else if (this.currentLine != null) {
1876
										this.currentLine.clear();
1877
									}
1867
									}
1878
								}
1868
								}
1879
								isUnicode = false;
1869
								isUnicode = false;
Lines 1898-1904 Link Here
1898
								int firstTag = 0;
1888
								int firstTag = 0;
1899
								while ((this.currentCharacter != '/') || (!star)) {
1889
								while ((this.currentCharacter != '/') || (!star)) {
1900
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1890
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1901
										if (this.currentLine != null) {
1891
										if (this.currentLine != null && this.currentLine.size() != 0) {
1902
											parseTags(false);
1892
											parseTags(false);
1903
										}
1893
										}
1904
										if (this.recordLineSeparator) {
1894
										if (this.recordLineSeparator) {
Lines 1907-1914 Link Here
1907
											} else {
1897
											} else {
1908
												pushLineSeparator();
1898
												pushLineSeparator();
1909
											}
1899
											}
1910
										} else if (this.currentLine != null) {
1911
											this.currentLine.clear();
1912
										}
1900
										}
1913
									}
1901
									}
1914
									switch (this.currentCharacter) {
1902
									switch (this.currentCharacter) {
Lines 2257-2270 Link Here
2257
}
2245
}
2258
2246
2259
protected void parseTags(boolean hasLineComment) {
2247
protected void parseTags(boolean hasLineComment) {
2260
	final NLSLine line = this.currentLine;
2261
	if (!hasLineComment) {
2248
	if (!hasLineComment) {
2262
		if (line.size() == 0) return; // nothing to do
2263
		if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2249
		if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2264
		this.nonNLSStrings.addAll(line.elements);
2250
		this.nonNLSStrings.addAll(this.currentLine.elements);
2265
	} else {
2251
	} else {
2266
		int position = 0;
2252
		int position = 0;
2267
		if (linePtr >= 0) {
2253
		if (this.linePtr >= 0) {
2268
			position = this.lineEnds[this.linePtr] + 1; 
2254
			position = this.lineEnds[this.linePtr] + 1; 
2269
		}
2255
		}
2270
		while (Character.isWhitespace(this.source[position])) {
2256
		while (Character.isWhitespace(this.source[position])) {
Lines 2274-2306 Link Here
2274
			// the whole line is commented out
2260
			// the whole line is commented out
2275
			return;
2261
			return;
2276
		}
2262
		}
2277
		char[] s = getCurrentTokenSource();
2263
		final NLSLine line = this.currentLine;
2278
		int pos = CharOperation.indexOf(TAG_PREFIX, s, true);
2264
		char[] s = null;
2265
		int sourceEnd = this.currentPosition;
2266
		int sourceStart = this.startPosition;
2267
		int sourceDelta = 0;
2268
		if (this.withoutUnicodePtr != 0) {
2269
			// 0 is used as a fast test flag so the real first char is in position 1
2270
			System.arraycopy(
2271
				this.withoutUnicodeBuffer, 
2272
				1, 
2273
				s = new char[this.withoutUnicodePtr], 
2274
				0, 
2275
				this.withoutUnicodePtr);
2276
			sourceEnd = this.withoutUnicodePtr;
2277
			sourceStart = 1;
2278
			sourceDelta = this.getCurrentTokenStartPosition();
2279
		} else {
2280
			s = this.source;
2281
		}
2282
		int pos = CharOperation.indexOf(TAG_PREFIX, s, true, sourceStart, sourceEnd);
2283
		final int lineSize = line.size();
2279
		if (pos != -1) {
2284
		if (pos != -1) {
2280
			if (this.unnecessaryNLSTags == null) this.unnecessaryNLSTags = new HashSet();
2285
			if (this.unnecessaryNLSTags == null) this.unnecessaryNLSTags = new HashSet();
2281
			while (pos != -1) {
2286
			while (pos != -1) {
2282
				int start = pos + TAG_PREFIX_LENGTH;
2287
				int start = pos + TAG_PREFIX_LENGTH;
2283
				int end = CharOperation.indexOf(TAG_POSTFIX, s, start);
2288
				int end = CharOperation.indexOf(TAG_POSTFIX, s, start, sourceEnd);
2284
				if (end != -1) {
2289
				if (end != -1) {
2285
					String index = new String(CharOperation.subarray(s, start, end));
2290
					String index = new String(CharOperation.subarray(s, start, end));
2286
					int i = 0;
2287
					try {
2291
					try {
2288
						i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
2292
						final int i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
2289
					} catch (NumberFormatException e) {
2293
						if (i >= 0 && i < lineSize) {
2290
						i = -1; // we don't want to consider this as a valid NLS tag
2294
							if (line.get(i) == null) {
2291
					}
2295
								this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
2292
					if (line != null && line.exists(i)) {
2296
							} else {
2293
						if (line.get(i) == null) {
2297
								line.set(i, null);
2294
							this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
2298
								final NLSTag tag = new NLSTag(pos + sourceDelta , end + sourceDelta, NLSTag.USED);
2295
						} else {
2299
								if (!this.unnecessaryNLSTags.add(tag)) {
2296
							line.set(i, null);
2300
									this.unnecessaryNLSTags.remove(tag);
2297
							final NLSTag tag = new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end, NLSTag.USED);
2301
									this.unnecessaryNLSTags.add(tag);
2298
							if (!this.unnecessaryNLSTags.add(tag)) {
2302
								}
2299
								this.unnecessaryNLSTags.remove(tag);
2300
								this.unnecessaryNLSTags.add(tag);
2301
							}
2303
							}
2304
						} else {
2305
							this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
2302
						}
2306
						}
2303
					} else {
2307
					} catch (NumberFormatException e) {
2304
						this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
2308
						this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
2305
					}
2309
					}
2306
				}
2310
				}
Lines 2308-2317 Link Here
2308
			}
2312
			}
2309
		}
2313
		}
2310
	
2314
	
2311
		if (line.size() != 0) {
2315
		if (line.remainingElementsSize != 0) {
2312
			if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2316
			if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2313
			for (Iterator iterator = line.iterator(); iterator.hasNext(); ) {
2317
			for (Iterator iterator = line.iterator(); iterator.hasNext(); ) {
2314
				StringLiteral literal = (StringLiteral) iterator.next();
2318
				final StringLiteral literal = (StringLiteral) iterator.next();
2315
				if (literal != null) {
2319
				if (literal != null) {
2316
					this.nonNLSStrings.add(literal);
2320
					this.nonNLSStrings.add(literal);
2317
				}
2321
				}
Lines 2324-2336 Link Here
2324
public final void pushLineSeparator() {
2328
public final void pushLineSeparator() {
2325
	//see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2329
	//see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2326
	final int INCREMENT = 250;
2330
	final int INCREMENT = 250;
2327
	
2328
	if (this.currentLine != null) {
2329
		// reinitialize the current line for non externalize strings purpose
2330
		this.currentLine.clear();
2331
	}
2332
	//currentCharacter is at position currentPosition-1
2331
	//currentCharacter is at position currentPosition-1
2333
2334
	// cr 000D
2332
	// cr 000D
2335
	if (this.currentCharacter == '\r') {
2333
	if (this.currentCharacter == '\r') {
2336
		int separatorPos = this.currentPosition - 1;
2334
		int separatorPos = this.currentPosition - 1;
Lines 2370-2381 Link Here
2370
		}
2368
		}
2371
	}
2369
	}
2372
}
2370
}
2373
public final void pushUnicodeLineSeparator() {
2371
public final void pushUnicodeLineSeparator() {	
2374
	if (this.currentLine != null) {
2375
		// reinitialize the current line for non externalize strings purpose
2376
		this.currentLine.clear();
2377
	}
2378
	
2379
	// cr 000D
2372
	// cr 000D
2380
	if (this.currentCharacter == '\r') {
2373
	if (this.currentCharacter == '\r') {
2381
		if (this.source[this.currentPosition] == '\n') {
2374
		if (this.source[this.currentPosition] == '\n') {
(-)model/org/eclipse/jdt/internal/core/util/PublicScanner.java (-53 / +60 lines)
Lines 209-215 Link Here
209
	public static final char TAG_POSTFIX= '$';
209
	public static final char TAG_POSTFIX= '$';
210
	public static final int TAG_POSTFIX_LENGTH= 1;
210
	public static final int TAG_POSTFIX_LENGTH= 1;
211
	public Set nonNLSStrings = null;
211
	public Set nonNLSStrings = null;
212
	public Set unnecessaryNONNLSTags = null;
212
	public Set unnecessaryNLSTags = null;
213
213
214
	// generic support
214
	// generic support
215
	public boolean returnOnlyGreater = false;
215
	public boolean returnOnlyGreater = false;
Lines 904-910 Link Here
904
					if (this.currentPosition > this.eofPosition)
904
					if (this.currentPosition > this.eofPosition)
905
						return TokenNameEOF;
905
						return TokenNameEOF;
906
				}
906
				}
907
				//little trick to get out in the middle of a source compuation
908
				if (this.currentPosition > this.eofPosition)
907
				if (this.currentPosition > this.eofPosition)
909
					return TokenNameEOF;
908
					return TokenNameEOF;
910
				if (checkIfUnicode) {
909
				if (checkIfUnicode) {
Lines 913-925 Link Here
913
				} else {
912
				} else {
914
					offset = this.currentPosition - offset;
913
					offset = this.currentPosition - offset;
915
					if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
914
					if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
916
						if (this.currentLine != null) {
915
						if (this.currentLine != null && this.currentLine.size() != 0) {
917
							parseTags(false);
916
							parseTags(false);
918
						}
917
						}
919
						if (this.recordLineSeparator) {
918
						if (this.recordLineSeparator) {
920
							pushLineSeparator();
919
							pushLineSeparator();
921
						} else if (this.currentLine != null) {
922
							this.currentLine.clear();
923
						}
920
						}
924
					}
921
					}
925
					// inline version of:
922
					// inline version of:
Lines 1355-1362 Link Here
1355
										} else {
1352
										} else {
1356
											pushLineSeparator();
1353
											pushLineSeparator();
1357
										}
1354
										}
1358
									} else if (this.currentLine != null) {
1359
										this.currentLine.clear();
1360
									}
1355
									}
1361
								}
1356
								}
1362
								if (this.tokenizeComments) {
1357
								if (this.tokenizeComments) {
Lines 1400-1406 Link Here
1400
									star = true;
1395
									star = true;
1401
								}
1396
								}
1402
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1397
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1403
									if (this.currentLine != null) {
1398
									if (this.currentLine != null && this.currentLine.size() != 0) {
1404
										parseTags(false);
1399
										parseTags(false);
1405
									}
1400
									}
1406
									if (this.recordLineSeparator) {
1401
									if (this.recordLineSeparator) {
Lines 1409-1416 Link Here
1409
										} else {
1404
										} else {
1410
											pushLineSeparator();
1405
											pushLineSeparator();
1411
										}
1406
										}
1412
									} else if (currentLine != null){
1413
										this.currentLine.clear();
1414
									}
1407
									}
1415
								}
1408
								}
1416
								isUnicode = false;
1409
								isUnicode = false;
Lines 1436-1442 Link Here
1436
								int firstTag = 0;
1429
								int firstTag = 0;
1437
								while ((this.currentCharacter != '/') || (!star)) {
1430
								while ((this.currentCharacter != '/') || (!star)) {
1438
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1431
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1439
										if (this.currentLine != null) {
1432
										if (this.currentLine != null && this.currentLine.size() != 0) {
1440
											parseTags(false);
1433
											parseTags(false);
1441
										}
1434
										}
1442
										if (this.recordLineSeparator) {
1435
										if (this.recordLineSeparator) {
Lines 1445-1452 Link Here
1445
											} else {
1438
											} else {
1446
												pushLineSeparator();
1439
												pushLineSeparator();
1447
											}
1440
											}
1448
										} else if (this.currentLine != null) {
1449
											this.currentLine.clear();
1450
										}
1441
										}
1451
									}
1442
									}
1452
									switch (this.currentCharacter) {
1443
									switch (this.currentCharacter) {
Lines 1638-1644 Link Here
1638
				} else {
1629
				} else {
1639
					if (this.recordLineSeparator
1630
					if (this.recordLineSeparator
1640
							&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1631
							&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1641
						if (this.currentLine != null) {
1632
						if (this.currentLine != null && this.currentLine.size() != 0) {
1642
							parseTags(false);
1633
							parseTags(false);
1643
						}
1634
						}
1644
						pushLineSeparator();
1635
						pushLineSeparator();
Lines 1863-1869 Link Here
1863
									star = true;
1854
									star = true;
1864
								}
1855
								}
1865
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1856
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1866
									if (this.currentLine != null) {
1857
									if (this.currentLine != null && this.currentLine.size() != 0) {
1867
										parseTags(false);
1858
										parseTags(false);
1868
									}
1859
									}
1869
									if (this.recordLineSeparator) {
1860
									if (this.recordLineSeparator) {
Lines 1872-1879 Link Here
1872
										} else {
1863
										} else {
1873
											pushLineSeparator();
1864
											pushLineSeparator();
1874
										}
1865
										}
1875
									} else if (this.currentLine != null) {
1876
										this.currentLine.clear();
1877
									}
1866
									}
1878
								}
1867
								}
1879
								isUnicode = false;
1868
								isUnicode = false;
Lines 1898-1904 Link Here
1898
								int firstTag = 0;
1887
								int firstTag = 0;
1899
								while ((this.currentCharacter != '/') || (!star)) {
1888
								while ((this.currentCharacter != '/') || (!star)) {
1900
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1889
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1901
										if (this.currentLine != null) {
1890
										if (this.currentLine != null && this.currentLine.size() != 0) {
1902
											parseTags(false);
1891
											parseTags(false);
1903
										}
1892
										}
1904
										if (this.recordLineSeparator) {
1893
										if (this.recordLineSeparator) {
Lines 1907-1914 Link Here
1907
											} else {
1896
											} else {
1908
												pushLineSeparator();
1897
												pushLineSeparator();
1909
											}
1898
											}
1910
										} else if (this.currentLine != null) {
1911
											this.currentLine.clear();
1912
										}
1899
										}
1913
									}
1900
									}
1914
									switch (this.currentCharacter) {
1901
									switch (this.currentCharacter) {
Lines 2257-2302 Link Here
2257
}
2244
}
2258
2245
2259
protected void parseTags(boolean hasLineComment) {
2246
protected void parseTags(boolean hasLineComment) {
2260
	final NLSLine line = this.currentLine;
2261
	if (!hasLineComment) {
2247
	if (!hasLineComment) {
2262
		if (line.size() == 0) return; // nothing to do
2263
		if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2248
		if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2264
		this.nonNLSStrings.addAll(line.elements);
2249
		this.nonNLSStrings.addAll(this.currentLine.elements);
2265
	} else {
2250
	} else {
2266
		char[] s = getCurrentTokenSource();
2251
		int position = 0;
2267
		int pos = CharOperation.indexOf(TAG_PREFIX, s, true);
2252
		if (this.linePtr >= 0) {
2253
			position = this.lineEnds[this.linePtr] + 1; 
2254
		}
2255
		while (Character.isWhitespace(this.source[position])) {
2256
			position++;
2257
		}
2258
		if (getCurrentTokenStartPosition() == position) {
2259
			// the whole line is commented out
2260
			return;
2261
		}
2262
		final NLSLine line = this.currentLine;
2263
		char[] s = null;
2264
		int sourceEnd = this.currentPosition;
2265
		int sourceStart = this.startPosition;
2266
		int sourceDelta = 0;
2267
		if (this.withoutUnicodePtr != 0) {
2268
			// 0 is used as a fast test flag so the real first char is in position 1
2269
			System.arraycopy(
2270
				this.withoutUnicodeBuffer, 
2271
				1, 
2272
				s = new char[this.withoutUnicodePtr], 
2273
				0, 
2274
				this.withoutUnicodePtr);
2275
			sourceEnd = this.withoutUnicodePtr;
2276
			sourceStart = 1;
2277
			sourceDelta = this.getCurrentTokenStartPosition();
2278
		} else {
2279
			s = this.source;
2280
		}
2281
		int pos = CharOperation.indexOf(TAG_PREFIX, s, true, sourceStart, sourceEnd);
2282
		final int lineSize = line.size();
2268
		if (pos != -1) {
2283
		if (pos != -1) {
2269
			if (this.unnecessaryNONNLSTags == null) this.unnecessaryNONNLSTags = new HashSet();
2284
			if (this.unnecessaryNLSTags == null) this.unnecessaryNLSTags = new HashSet();
2270
			while (pos != -1) {
2285
			while (pos != -1) {
2271
				int start = pos + TAG_PREFIX_LENGTH;
2286
				int start = pos + TAG_PREFIX_LENGTH;
2272
				int end = CharOperation.indexOf(TAG_POSTFIX, s, start);
2287
				int end = CharOperation.indexOf(TAG_POSTFIX, s, start, sourceEnd);
2273
				if (end != -1) {
2288
				if (end != -1) {
2274
					String index = new String(CharOperation.subarray(s, start, end));
2289
					String index = new String(CharOperation.subarray(s, start, end));
2275
					int i = 0;
2276
					try {
2290
					try {
2277
						i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
2291
						final int i = Integer.parseInt(index) - 1; // Tags are one based not zero based.
2278
					} catch (NumberFormatException e) {
2292
						if (i >= 0 && i < lineSize) {
2279
						i = -1; // we don't want to consider this as a valid NLS tag
2293
							if (line.get(i) == null) {
2280
					}
2294
								this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
2281
					if (line != null && line.exists(i)) {
2295
							} else {
2282
						line.set(i, null);
2296
								line.set(i, null);
2283
						final NLSTag tag = new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end, NLSTag.USED);
2297
								final NLSTag tag = new NLSTag(pos + sourceDelta , end + sourceDelta, NLSTag.USED);
2284
						if (!this.unnecessaryNONNLSTags.add(tag)) {
2298
								if (!this.unnecessaryNLSTags.add(tag)) {
2285
							this.unnecessaryNONNLSTags.remove(tag);
2299
									this.unnecessaryNLSTags.remove(tag);
2286
							this.unnecessaryNONNLSTags.add(tag);
2300
									this.unnecessaryNLSTags.add(tag);
2301
								}
2302
							}
2303
						} else {
2304
							this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta));
2287
						}
2305
						}
2288
					} else {
2306
					} catch (NumberFormatException e) {
2289
						this.unnecessaryNONNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
2307
						this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end));
2290
					}
2308
					}
2291
				}
2309
				}
2292
				pos = CharOperation.indexOf(TAG_PREFIX, s, true, start);
2310
				pos = CharOperation.indexOf(TAG_PREFIX, s, true, start);
2293
			}
2311
			}
2294
		}
2312
		}
2295
	
2313
	
2296
		if (line.size() != 0) {
2314
		if (line.remainingElementsSize != 0) {
2297
			if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2315
			if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet();
2298
			for (Iterator iterator = line.iterator(); iterator.hasNext(); ) {
2316
			for (Iterator iterator = line.iterator(); iterator.hasNext(); ) {
2299
				StringLiteral literal = (StringLiteral) iterator.next();
2317
				final StringLiteral literal = (StringLiteral) iterator.next();
2300
				if (literal != null) {
2318
				if (literal != null) {
2301
					this.nonNLSStrings.add(literal);
2319
					this.nonNLSStrings.add(literal);
2302
				}
2320
				}
Lines 2309-2321 Link Here
2309
public final void pushLineSeparator() {
2327
public final void pushLineSeparator() {
2310
	//see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2328
	//see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2311
	final int INCREMENT = 250;
2329
	final int INCREMENT = 250;
2312
	
2313
	if (this.currentLine != null) {
2314
		// reinitialize the current line for non externalize strings purpose
2315
		this.currentLine.clear();
2316
	}
2317
	//currentCharacter is at position currentPosition-1
2330
	//currentCharacter is at position currentPosition-1
2318
2319
	// cr 000D
2331
	// cr 000D
2320
	if (this.currentCharacter == '\r') {
2332
	if (this.currentCharacter == '\r') {
2321
		int separatorPos = this.currentPosition - 1;
2333
		int separatorPos = this.currentPosition - 1;
Lines 2356-2366 Link Here
2356
	}
2368
	}
2357
}
2369
}
2358
public final void pushUnicodeLineSeparator() {
2370
public final void pushUnicodeLineSeparator() {
2359
	if (this.currentLine != null) {
2360
		// reinitialize the current line for non externalize strings purpose
2361
		this.currentLine.clear();
2362
	}
2363
	
2364
	// cr 000D
2371
	// cr 000D
2365
	if (this.currentCharacter == '\r') {
2372
	if (this.currentCharacter == '\r') {
2366
		if (this.source[this.currentPosition] == '\n') {
2373
		if (this.source[this.currentPosition] == '\n') {

Return to bug 110082