mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-28 03:43:21 +00:00
8359497: IllegalArgumentException thrown by SourceCodeAnalysisImpl.highlights()
Reviewed-by: vromero
This commit is contained in:
parent
1f0dfdbcca
commit
d99fb09a20
@ -66,6 +66,7 @@ import com.sun.tools.javac.parser.Tokens.Token;
|
||||
import com.sun.tools.javac.parser.Tokens.TokenKind;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Log;
|
||||
import jdk.internal.shellsupport.doc.JavadocHelper;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
import com.sun.tools.javac.util.Names;
|
||||
@ -139,6 +140,7 @@ import javax.lang.model.type.ExecutableType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.lang.model.util.Types;
|
||||
import javax.tools.DiagnosticListener;
|
||||
import javax.tools.JavaFileManager.Location;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
@ -654,7 +656,10 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
Trees trees = task.trees();
|
||||
SourcePositions sp = trees.getSourcePositions();
|
||||
List<Token> tokens = new ArrayList<>();
|
||||
Scanner scanner = ScannerFactory.instance(new Context()).newScanner(wrappedCode, false);
|
||||
Context ctx = new Context();
|
||||
ctx.put(DiagnosticListener.class, (DiagnosticListener) d -> {});
|
||||
Scanner scanner = ScannerFactory.instance(ctx).newScanner(wrappedCode, false);
|
||||
Log.instance(ctx).useSource(cut.getSourceFile());
|
||||
scanner.nextToken();
|
||||
BiConsumer<Integer, Integer> addKeywordForSpan = (spanStart, spanEnd) -> {
|
||||
int start = codeWrap.wrapIndexToSnippetIndex(spanStart);
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8274148 8301580
|
||||
* @bug 8274148 8301580 8359497
|
||||
* @summary Check snippet highlighting
|
||||
* @library /tools/lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
@ -114,6 +114,12 @@ public class SnippetHighlightTest extends KullaTesting {
|
||||
"Highlight[start=32, end=38, attributes=[KEYWORD]]");
|
||||
}
|
||||
|
||||
public void testNoCrashOnLexicalErrors() { //JDK-8359497
|
||||
assertHighlights("""
|
||||
"
|
||||
""");
|
||||
}
|
||||
|
||||
private void assertHighlights(String code, String... expected) {
|
||||
List<String> completions = computeHighlights(code);
|
||||
assertEquals(completions, Arrays.asList(expected), "Input: " + code + ", " + completions.toString());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user