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

(-)compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java (-10 / +34 lines)
Lines 1379-1384 Link Here
1379
						}
1379
						}
1380
1380
1381
						while (this.currentCharacter != '"') {
1381
						while (this.currentCharacter != '"') {
1382
							if (this.currentPosition >= this.eofPosition) {
1383
								throw new InvalidInputException(UNTERMINATED_STRING);
1384
							}
1382
							/**** \r and \n are not valid in string literals ****/
1385
							/**** \r and \n are not valid in string literals ****/
1383
							if ((this.currentCharacter == '\n') || (this.currentCharacter == '\r')) {
1386
							if ((this.currentCharacter == '\n') || (this.currentCharacter == '\r')) {
1384
								// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed
1387
								// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed
Lines 1486-1491 Link Here
1486
								} //jump over the \\
1489
								} //jump over the \\
1487
								boolean isUnicode = false;
1490
								boolean isUnicode = false;
1488
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1491
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1492
									if (this.currentPosition >= this.eofPosition) {
1493
										this.lastCommentLinePosition = this.currentPosition;
1494
										this.currentPosition ++;
1495
										// this avoids duplicating the code in the catch(IndexOutOfBoundsException e)
1496
										throw new IndexOutOfBoundsException();
1497
									}
1489
									this.lastCommentLinePosition = this.currentPosition;
1498
									this.lastCommentLinePosition = this.currentPosition;
1490
									//get the next char
1499
									//get the next char
1491
									isUnicode = false;
1500
									isUnicode = false;
Lines 1504-1519 Link Here
1504
								 * We need to completely consume the line break
1513
								 * We need to completely consume the line break
1505
								 */
1514
								 */
1506
								if (this.currentCharacter == '\r'
1515
								if (this.currentCharacter == '\r'
1507
								   && this.eofPosition > this.currentPosition) {
1516
										&& this.eofPosition > this.currentPosition) {
1508
								   	if (this.source[this.currentPosition] == '\n') {
1517
									if (this.source[this.currentPosition] == '\n') {
1509
										this.currentPosition++;
1518
										this.currentPosition++;
1510
										this.currentCharacter = '\n';
1519
										this.currentCharacter = '\n';
1511
								   	} else if ((this.source[this.currentPosition] == '\\')
1520
									} else if ((this.source[this.currentPosition] == '\\')
1512
										&& (this.source[this.currentPosition + 1] == 'u')) {
1521
										&& (this.source[this.currentPosition + 1] == 'u')) {
1513
										getNextUnicodeChar();
1522
										getNextUnicodeChar();
1514
										isUnicode = true;
1523
										isUnicode = true;
1515
									}
1524
									}
1516
							   	}
1525
								}
1517
								recordComment(TokenNameCOMMENT_LINE);
1526
								recordComment(TokenNameCOMMENT_LINE);
1518
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1527
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1519
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1528
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
Lines 1601-1606 Link Here
1601
								//loop until end of comment */
1610
								//loop until end of comment */
1602
								int firstTag = 0;
1611
								int firstTag = 0;
1603
								while ((this.currentCharacter != '/') || (!star)) {
1612
								while ((this.currentCharacter != '/') || (!star)) {
1613
									if (this.currentPosition >= this.eofPosition) {
1614
										throw new InvalidInputException(UNTERMINATED_COMMENT);
1615
									}
1604
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1616
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1605
										if (this.recordLineSeparator) {
1617
										if (this.recordLineSeparator) {
1606
											if (isUnicode) {
1618
											if (isUnicode) {
Lines 1865-1877 Link Here
1865
								getNextUnicodeChar();
1877
								getNextUnicodeChar();
1866
							} else {
1878
							} else {
1867
								if (this.withoutUnicodePtr != 0) {
1879
								if (this.withoutUnicodePtr != 0) {
1868
								    unicodeStore();
1880
									unicodeStore();
1869
								}
1881
								}
1870
							}
1882
							}
1871
						} catch (InvalidInputException ex) {
1883
						} catch (InvalidInputException ex) {
1872
								// ignore
1884
								// ignore
1873
						}
1885
						}
1874
						while (this.currentCharacter != '"') {
1886
						while (this.currentCharacter != '"') {
1887
							if (this.currentPosition >= this.eofPosition) {
1888
								return;
1889
							}
1875
							if (this.currentCharacter == '\r'){
1890
							if (this.currentCharacter == '\r'){
1876
								if (this.source[this.currentPosition] == '\n') this.currentPosition++;
1891
								if (this.source[this.currentPosition] == '\n') this.currentPosition++;
1877
								break NextToken; // the string cannot go further that the line
1892
								break NextToken; // the string cannot go further that the line
Lines 1935-1940 Link Here
1935
								} //jump over the \\
1950
								} //jump over the \\
1936
								boolean isUnicode = false;
1951
								boolean isUnicode = false;
1937
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1952
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1953
									if (this.currentPosition >= this.eofPosition) {
1954
										this.lastCommentLinePosition = this.currentPosition;
1955
										this.currentPosition ++;
1956
										// this avoids duplicating the code inside the catch(IndexOutOfBoundsException e) below
1957
										throw new IndexOutOfBoundsException();
1958
									}
1938
									this.lastCommentLinePosition = this.currentPosition;
1959
									this.lastCommentLinePosition = this.currentPosition;
1939
									//get the next char
1960
									//get the next char
1940
									isUnicode = false;
1961
									isUnicode = false;
Lines 1953-1968 Link Here
1953
								 * We need to completely consume the line break
1974
								 * We need to completely consume the line break
1954
								 */
1975
								 */
1955
								if (this.currentCharacter == '\r'
1976
								if (this.currentCharacter == '\r'
1956
								   && this.eofPosition > this.currentPosition) {
1977
										&& this.eofPosition > this.currentPosition) {
1957
								   	if (this.source[this.currentPosition] == '\n') {
1978
									if (this.source[this.currentPosition] == '\n') {
1958
										this.currentPosition++;
1979
										this.currentPosition++;
1959
										this.currentCharacter = '\n';
1980
										this.currentCharacter = '\n';
1960
								   	} else if ((this.source[this.currentPosition] == '\\')
1981
									} else if ((this.source[this.currentPosition] == '\\')
1961
											&& (this.source[this.currentPosition + 1] == 'u')) {
1982
											&& (this.source[this.currentPosition + 1] == 'u')) {
1962
										isUnicode = true;
1983
										isUnicode = true;
1963
										getNextUnicodeChar();
1984
										getNextUnicodeChar();
1964
									}
1985
									}
1965
							   	}
1986
								}
1966
								recordComment(TokenNameCOMMENT_LINE);
1987
								recordComment(TokenNameCOMMENT_LINE);
1967
								if (this.recordLineSeparator
1988
								if (this.recordLineSeparator
1968
									&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1989
									&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
Lines 2007-2013 Link Here
2007
								} else {
2028
								} else {
2008
									isUnicode = false;
2029
									isUnicode = false;
2009
									if (this.withoutUnicodePtr != 0) {
2030
									if (this.withoutUnicodePtr != 0) {
2010
    								    unicodeStore();
2031
										unicodeStore();
2011
									}
2032
									}
2012
								}
2033
								}
2013
2034
Lines 2045-2050 Link Here
2045
								//loop until end of comment */
2066
								//loop until end of comment */
2046
								int firstTag = 0;
2067
								int firstTag = 0;
2047
								while ((this.currentCharacter != '/') || (!star)) {
2068
								while ((this.currentCharacter != '/') || (!star)) {
2069
									if (this.currentPosition >= this.eofPosition) {
2070
										return;
2071
									}
2048
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
2072
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
2049
										if (this.recordLineSeparator) {
2073
										if (this.recordLineSeparator) {
2050
											if (isUnicode) {
2074
											if (isUnicode) {
(-)model/org/eclipse/jdt/internal/core/util/PublicScanner.java (-10 / +32 lines)
Lines 1376-1381 Link Here
1376
						}
1376
						}
1377
1377
1378
						while (this.currentCharacter != '"') {
1378
						while (this.currentCharacter != '"') {
1379
							if (this.currentPosition >= this.eofPosition) {
1380
								throw new InvalidInputException(UNTERMINATED_STRING);
1381
							}
1379
							/**** \r and \n are not valid in string literals ****/
1382
							/**** \r and \n are not valid in string literals ****/
1380
							if ((this.currentCharacter == '\n') || (this.currentCharacter == '\r')) {
1383
							if ((this.currentCharacter == '\n') || (this.currentCharacter == '\r')) {
1381
								// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed
1384
								// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed
Lines 1483-1488 Link Here
1483
								} //jump over the \\
1486
								} //jump over the \\
1484
								boolean isUnicode = false;
1487
								boolean isUnicode = false;
1485
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1488
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1489
									if (this.currentPosition >= this.eofPosition) {
1490
										this.currentPosition++;
1491
										// this avoids duplicating the code in the catch(IndexOutOfBoundsException e)
1492
										throw new IndexOutOfBoundsException();
1493
									}
1486
									this.lastCommentLinePosition = this.currentPosition;
1494
									this.lastCommentLinePosition = this.currentPosition;
1487
									//get the next char
1495
									//get the next char
1488
									isUnicode = false;
1496
									isUnicode = false;
Lines 1501-1516 Link Here
1501
								 * We need to completely consume the line break
1509
								 * We need to completely consume the line break
1502
								 */
1510
								 */
1503
								if (this.currentCharacter == '\r'
1511
								if (this.currentCharacter == '\r'
1504
								   && this.eofPosition > this.currentPosition) {
1512
										&& this.eofPosition > this.currentPosition) {
1505
								   	if (this.source[this.currentPosition] == '\n') {
1513
									if (this.source[this.currentPosition] == '\n') {
1506
										this.currentPosition++;
1514
										this.currentPosition++;
1507
										this.currentCharacter = '\n';
1515
										this.currentCharacter = '\n';
1508
								   	} else if ((this.source[this.currentPosition] == '\\')
1516
									} else if ((this.source[this.currentPosition] == '\\')
1509
										&& (this.source[this.currentPosition + 1] == 'u')) {
1517
										&& (this.source[this.currentPosition + 1] == 'u')) {
1510
										getNextUnicodeChar();
1518
										getNextUnicodeChar();
1511
										isUnicode = true;
1519
										isUnicode = true;
1512
									}
1520
									}
1513
							   	}
1521
								}
1514
								recordComment(TokenNameCOMMENT_LINE);
1522
								recordComment(TokenNameCOMMENT_LINE);
1515
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1523
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1516
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1524
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
Lines 1598-1603 Link Here
1598
								//loop until end of comment */
1606
								//loop until end of comment */
1599
								int firstTag = 0;
1607
								int firstTag = 0;
1600
								while ((this.currentCharacter != '/') || (!star)) {
1608
								while ((this.currentCharacter != '/') || (!star)) {
1609
									if (this.currentPosition >= this.eofPosition) {
1610
										throw new InvalidInputException(UNTERMINATED_COMMENT);
1611
									}
1601
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1612
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1602
										if (this.recordLineSeparator) {
1613
										if (this.recordLineSeparator) {
1603
											if (isUnicode) {
1614
											if (isUnicode) {
Lines 1862-1874 Link Here
1862
								getNextUnicodeChar();
1873
								getNextUnicodeChar();
1863
							} else {
1874
							} else {
1864
								if (this.withoutUnicodePtr != 0) {
1875
								if (this.withoutUnicodePtr != 0) {
1865
								    unicodeStore();
1876
									unicodeStore();
1866
								}
1877
								}
1867
							}
1878
							}
1868
						} catch (InvalidInputException ex) {
1879
						} catch (InvalidInputException ex) {
1869
								// ignore
1880
								// ignore
1870
						}
1881
						}
1871
						while (this.currentCharacter != '"') {
1882
						while (this.currentCharacter != '"') {
1883
							if (this.currentPosition >= this.eofPosition) {
1884
								return;
1885
							}
1872
							if (this.currentCharacter == '\r'){
1886
							if (this.currentCharacter == '\r'){
1873
								if (this.source[this.currentPosition] == '\n') this.currentPosition++;
1887
								if (this.source[this.currentPosition] == '\n') this.currentPosition++;
1874
								break NextToken; // the string cannot go further that the line
1888
								break NextToken; // the string cannot go further that the line
Lines 1932-1937 Link Here
1932
								} //jump over the \\
1946
								} //jump over the \\
1933
								boolean isUnicode = false;
1947
								boolean isUnicode = false;
1934
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1948
								while (this.currentCharacter != '\r' && this.currentCharacter != '\n') {
1949
									if (this.currentPosition >= this.eofPosition) {
1950
										this.currentPosition++;
1951
										// this avoids duplicating the code inside the catch(IndexOutOfBoundsException e) below
1952
										throw new IndexOutOfBoundsException();
1953
									}
1935
									this.lastCommentLinePosition = this.currentPosition;
1954
									this.lastCommentLinePosition = this.currentPosition;
1936
									//get the next char
1955
									//get the next char
1937
									isUnicode = false;
1956
									isUnicode = false;
Lines 1950-1965 Link Here
1950
								 * We need to completely consume the line break
1969
								 * We need to completely consume the line break
1951
								 */
1970
								 */
1952
								if (this.currentCharacter == '\r'
1971
								if (this.currentCharacter == '\r'
1953
								   && this.eofPosition > this.currentPosition) {
1972
										&& this.eofPosition > this.currentPosition) {
1954
								   	if (this.source[this.currentPosition] == '\n') {
1973
									if (this.source[this.currentPosition] == '\n') {
1955
										this.currentPosition++;
1974
										this.currentPosition++;
1956
										this.currentCharacter = '\n';
1975
										this.currentCharacter = '\n';
1957
								   	} else if ((this.source[this.currentPosition] == '\\')
1976
									} else if ((this.source[this.currentPosition] == '\\')
1958
											&& (this.source[this.currentPosition + 1] == 'u')) {
1977
											&& (this.source[this.currentPosition + 1] == 'u')) {
1959
										isUnicode = true;
1978
										isUnicode = true;
1960
										getNextUnicodeChar();
1979
										getNextUnicodeChar();
1961
									}
1980
									}
1962
							   	}
1981
								}
1963
								recordComment(TokenNameCOMMENT_LINE);
1982
								recordComment(TokenNameCOMMENT_LINE);
1964
								if (this.recordLineSeparator
1983
								if (this.recordLineSeparator
1965
									&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1984
									&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
Lines 2004-2010 Link Here
2004
								} else {
2023
								} else {
2005
									isUnicode = false;
2024
									isUnicode = false;
2006
									if (this.withoutUnicodePtr != 0) {
2025
									if (this.withoutUnicodePtr != 0) {
2007
    								    unicodeStore();
2026
										unicodeStore();
2008
									}
2027
									}
2009
								}
2028
								}
2010
2029
Lines 2042-2047 Link Here
2042
								//loop until end of comment */
2061
								//loop until end of comment */
2043
								int firstTag = 0;
2062
								int firstTag = 0;
2044
								while ((this.currentCharacter != '/') || (!star)) {
2063
								while ((this.currentCharacter != '/') || (!star)) {
2064
									if (this.currentPosition >= this.eofPosition) {
2065
										return;
2066
									}
2045
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
2067
									if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
2046
										if (this.recordLineSeparator) {
2068
										if (this.recordLineSeparator) {
2047
											if (isUnicode) {
2069
											if (isUnicode) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java (-1 / +111 lines)
Lines 31-37 Link Here
31
	// All specified tests which does not belong to the class are skipped...
31
	// All specified tests which does not belong to the class are skipped...
32
	static {
32
	static {
33
//		TESTS_NAMES = new String[] { "test000" };
33
//		TESTS_NAMES = new String[] { "test000" };
34
//		TESTS_NUMBERS = new int[] { 46 };
34
//		TESTS_NUMBERS = new int[] { 52 };
35
//		TESTS_RANGE = new int[] { 11, -1 };
35
//		TESTS_RANGE = new int[] { 11, -1 };
36
	}
36
	}
37
37
Lines 1017-1020 Link Here
1017
			assertTrue("Wrong exception", false);
1017
			assertTrue("Wrong exception", false);
1018
		}
1018
		}
1019
	}
1019
	}
1020
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529
1021
	public void test047() {
1022
		IScanner scanner = ToolFactory.createScanner(
1023
				true,
1024
				true,
1025
				true,
1026
				JavaCore.getOption(JavaCore.COMPILER_SOURCE),
1027
				JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
1028
		final char[] source = "// a comment, longer than the offset".toCharArray();
1029
		scanner.setSource(source);
1030
		scanner.resetTo(0, 5);
1031
		try {
1032
			assertEquals("Wrong token", ITerminalSymbols.TokenNameCOMMENT_LINE, scanner.getNextToken());
1033
			assertEquals("Wrong source", "// a c", new String(scanner.getCurrentTokenSource()));
1034
			assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, scanner.getNextToken());
1035
		} catch (InvalidInputException e) {
1036
			assertTrue("Wrong exception", false);
1037
		}
1038
	}
1039
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529
1040
	public void test048() {
1041
		IScanner scanner = ToolFactory.createScanner(
1042
				true,
1043
				true,
1044
				true,
1045
				JavaCore.getOption(JavaCore.COMPILER_SOURCE),
1046
				JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
1047
		final char[] source = "/*a comment, longer\n than the\noffset*/".toCharArray();
1048
		scanner.setSource(source);
1049
		scanner.resetTo(0, 5);
1050
		try {
1051
			assertEquals("Wrong token", ITerminalSymbols.TokenNameCOMMENT_BLOCK, scanner.getNextToken());
1052
			assertTrue("Should fail with InvalidInputException", false);
1053
		} catch (InvalidInputException e) {
1054
			assertEquals("Wrong source", "/*a co", new String(scanner.getCurrentTokenSource()));
1055
		}
1056
	}
1057
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529
1058
	public void test049() {
1059
		IScanner scanner = ToolFactory.createScanner(
1060
				true,
1061
				true,
1062
				true,
1063
				JavaCore.getOption(JavaCore.COMPILER_SOURCE),
1064
				JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
1065
		final char[] source = "/*a coabstract, longer\n than the\noffset*/".toCharArray();
1066
		scanner.setSource(source);
1067
		scanner.resetTo(6, 13);
1068
		try {
1069
			assertEquals("Wrong token", ITerminalSymbols.TokenNameabstract, scanner.getNextToken());
1070
			assertEquals("Wrong source", "abstract", new String(scanner.getCurrentTokenSource()));
1071
			assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, scanner.getNextToken());
1072
		} catch (InvalidInputException e) {
1073
			assertTrue("Wrong exception", false);
1074
		}
1075
	}
1076
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529
1077
	public void test050() {
1078
		IScanner scanner = ToolFactory.createScanner(
1079
				true,
1080
				true,
1081
				true,
1082
				JavaCore.getOption(JavaCore.COMPILER_SOURCE),
1083
				JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
1084
		final char[] source = "\"a comment, longer\\n than the\\noffset \"".toCharArray();
1085
		scanner.setSource(source);
1086
		scanner.resetTo(0, 5);
1087
		try {
1088
			assertEquals("Wrong token", ITerminalSymbols.TokenNameStringLiteral, scanner.getNextToken());
1089
			assertTrue("Should fail with InvalidInputException", false);
1090
		} catch (InvalidInputException e) {
1091
			assertEquals("Wrong source", "\"a com", new String(scanner.getCurrentTokenSource()));
1092
		}
1093
	}
1094
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529
1095
	public void test051() {
1096
		IScanner scanner = ToolFactory.createScanner(
1097
				true,
1098
				true,
1099
				true,
1100
				JavaCore.getOption(JavaCore.COMPILER_SOURCE),
1101
				JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
1102
		final char[] source = "\"a co\\u00E9mment, longer\\n than the\\noffset \"".toCharArray();
1103
		scanner.setSource(source);
1104
		scanner.resetTo(0, 5);
1105
		try {
1106
			assertEquals("Wrong token", ITerminalSymbols.TokenNameStringLiteral, scanner.getNextToken());
1107
			assertTrue("Should fail with InvalidInputException", false);
1108
		} catch (InvalidInputException e) {
1109
			assertEquals("Wrong source", "\"a co\\", new String(scanner.getCurrentTokenSource()));
1110
		}
1111
	}
1112
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529
1113
	public void test052() {
1114
		IScanner scanner = ToolFactory.createScanner(
1115
				true,
1116
				true,
1117
				true,
1118
				JavaCore.getOption(JavaCore.COMPILER_SOURCE),
1119
				JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
1120
		final char[] source = "\"\\u00E9mment, longer\\n than the\\noffset \"".toCharArray();
1121
		scanner.setSource(source);
1122
		scanner.resetTo(0, 5);
1123
		try {
1124
			assertEquals("Wrong token", ITerminalSymbols.TokenNameStringLiteral, scanner.getNextToken());
1125
			assertTrue("Should fail with InvalidInputException", false);
1126
		} catch (InvalidInputException e) {
1127
			assertEquals("Wrong source", "\"\\u00E", new String(scanner.getCurrentTokenSource()));
1128
		}
1129
	}
1020
}
1130
}

Return to bug 294529