8223782: jshell parser should handle Text Blocks

Completion analysis should detect text blocks properly.

Reviewed-by: jlaskey, rfield
This commit is contained in:
Jan Lahoda 2019-06-07 10:09:41 +02:00
parent b156396481
commit 1d050ec2e9
3 changed files with 42 additions and 33 deletions

View File

@ -139,10 +139,36 @@ class MaskCommentsAndModifiers {
}
}
@SuppressWarnings("fallthrough")
private void next() {
switch (c) {
case '\'':
case '"': {
int pos = next - 1;
maskModifiers = false;
if (str.startsWith("\"\"\"", next - 1)) {
//text block/multi-line string literal:
int searchPoint = next + 2;
int end;
while ((end = str.indexOf("\"\"\"", searchPoint)) != (-1)) {
if (str.charAt(end - 1) != '\\')
break;
searchPoint = end + 1;
}
if (end == (-1)) {
openToken = true;
end = str.length();
} else {
end += 3;
}
write(c);
while (next < end) {
write(read());
}
break;
}
}
//intentional fall-through:
case '\'': {
maskModifiers = false;
write(c);
int match = c;
@ -155,37 +181,6 @@ class MaskCommentsAndModifiers {
write(c); // write match // line-end
break;
}
case '`': { // RawString
maskModifiers = false;
int backtickCount = 0;
do {
write(c);
++backtickCount;
read();
} while (c == '`');
while (true) {
if (c == '`') {
int cnt = 0;
do {
write(c);
++cnt;
read();
} while (c == '`');
if (cnt == backtickCount) {
unread();
break;
}
} else {
write(c);
if (c < 0) {
openToken = true;
break;
}
read();
}
}
break;
}
case '/':
read();
switch (c) {

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8149524 8131024 8165211 8080071 8130454 8167343 8129559 8114842 8182268
* @bug 8149524 8131024 8165211 8080071 8130454 8167343 8129559 8114842 8182268 8223782
* @summary Test SourceCodeAnalysis
* @build KullaTesting TestingInputStream
* @run testng CompletenessTest
@ -328,6 +328,18 @@ public class CompletenessTest extends KullaTesting {
assertStatus("/** test", DEFINITELY_INCOMPLETE, null);
}
public void testTextBlocks() {
assertStatus("\"\"\"", DEFINITELY_INCOMPLETE, null);
assertStatus("\"\"\"broken", DEFINITELY_INCOMPLETE, null);
assertStatus("\"\"\"\ntext", DEFINITELY_INCOMPLETE, null);
assertStatus("\"\"\"\ntext\"\"", DEFINITELY_INCOMPLETE, "\"\"\"\ntext\"\"\"");
assertStatus("\"\"\"\ntext\"\"\"", COMPLETE, "\"\"\"\ntext\"\"\"");
assertStatus("\"\"\"\ntext\\\"\"\"\"", COMPLETE, "\"\"\"\ntext\\\"\"\"\"");
assertStatus("\"\"\"\ntext\\\"\"\"", DEFINITELY_INCOMPLETE, null);
assertStatus("\"\"\"\ntext\\\"\"\"\\\"\"\"", DEFINITELY_INCOMPLETE, null);
assertStatus("\"\"\"\ntext\\\"\"\"\\\"\"\"\"\"\"", COMPLETE, "\"\"\"\ntext\\\"\"\"\\\"\"\"\"\"\"");
}
public void testMiscSource() {
assertStatus("if (t) if ", DEFINITELY_INCOMPLETE, "if (t) if"); //Bug
assertStatus("int m() {} dfd", COMPLETE, "int m() {}");

View File

@ -107,6 +107,8 @@ public class CompletionSuggestionTest extends KullaTesting {
assertCompletionIncludesExcludes("new C() {}.|",
new HashSet<>(Arrays.asList("method()", "number")),
new HashSet<>(Arrays.asList("D", "E", "F", "H", "class")));
assertCompletion("\"\".leng|", "length()");
assertCompletion("\"\"\"\n\"\"\".leng|", "length()");
}
public void testStartOfExpression() {