8296789: <TAB>-completion in jshell fails to expose synthetic bridge methods
Reviewed-by: jlahoda
This commit is contained in:
parent
030e88d638
commit
257f667afb
@ -52,6 +52,7 @@ import com.sun.source.util.TreePathScanner;
|
|||||||
import com.sun.source.util.Trees;
|
import com.sun.source.util.Trees;
|
||||||
import com.sun.tools.javac.api.JavacScope;
|
import com.sun.tools.javac.api.JavacScope;
|
||||||
import com.sun.tools.javac.code.Flags;
|
import com.sun.tools.javac.code.Flags;
|
||||||
|
import com.sun.tools.javac.code.Symbol;
|
||||||
import com.sun.tools.javac.code.Symbol.CompletionFailure;
|
import com.sun.tools.javac.code.Symbol.CompletionFailure;
|
||||||
import com.sun.tools.javac.code.Symbol.VarSymbol;
|
import com.sun.tools.javac.code.Symbol.VarSymbol;
|
||||||
import com.sun.tools.javac.code.Symtab;
|
import com.sun.tools.javac.code.Symtab;
|
||||||
@ -1031,7 +1032,14 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
|||||||
case DECLARED: {
|
case DECLARED: {
|
||||||
TypeElement element = (TypeElement) at.getTypes().asElement(site);
|
TypeElement element = (TypeElement) at.getTypes().asElement(site);
|
||||||
List<Element> result = new ArrayList<>();
|
List<Element> result = new ArrayList<>();
|
||||||
result.addAll(at.getElements().getAllMembers(element));
|
at.getElements().getAllMembers(element).forEach(m -> result.add(
|
||||||
|
element.equals(m.getEnclosingElement())
|
||||||
|
? m
|
||||||
|
: (m instanceof Symbol.MethodSymbol ms)
|
||||||
|
? ms.clone((Symbol)element)
|
||||||
|
: (m instanceof Symbol.VarSymbol vs)
|
||||||
|
? vs.clone((Symbol)element)
|
||||||
|
: m));
|
||||||
if (shouldGenerateDotClassItem) {
|
if (shouldGenerateDotClassItem) {
|
||||||
result.add(createDotClassSymbol(at, site));
|
result.add(createDotClassSymbol(at, site));
|
||||||
}
|
}
|
||||||
@ -1680,6 +1688,11 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
|||||||
return availableSources = result;
|
return availableSources = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Element getOriginalEnclosingElement(Element el) {
|
||||||
|
if (el instanceof Symbol s) el = s.baseSymbol();
|
||||||
|
return el.getEnclosingElement();
|
||||||
|
}
|
||||||
|
|
||||||
private String elementHeader(AnalyzeTask at, Element el, boolean includeParameterNames, boolean useFQN) {
|
private String elementHeader(AnalyzeTask at, Element el, boolean includeParameterNames, boolean useFQN) {
|
||||||
switch (el.getKind()) {
|
switch (el.getKind()) {
|
||||||
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE, RECORD: {
|
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE, RECORD: {
|
||||||
@ -1730,9 +1743,9 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
|||||||
.collect(joining(" & "));
|
.collect(joining(" & "));
|
||||||
}
|
}
|
||||||
case FIELD:
|
case FIELD:
|
||||||
return appendDot(elementHeader(at, el.getEnclosingElement(), includeParameterNames, false)) + el.getSimpleName() + ":" + el.asType();
|
return appendDot(elementHeader(at, getOriginalEnclosingElement(el), includeParameterNames, false)) + el.getSimpleName() + ":" + el.asType();
|
||||||
case ENUM_CONSTANT:
|
case ENUM_CONSTANT:
|
||||||
return appendDot(elementHeader(at, el.getEnclosingElement(), includeParameterNames, false)) + el.getSimpleName();
|
return appendDot(elementHeader(at, getOriginalEnclosingElement(el), includeParameterNames, false)) + el.getSimpleName();
|
||||||
case EXCEPTION_PARAMETER: case LOCAL_VARIABLE: case PARAMETER: case RESOURCE_VARIABLE:
|
case EXCEPTION_PARAMETER: case LOCAL_VARIABLE: case PARAMETER: case RESOURCE_VARIABLE:
|
||||||
return el.getSimpleName() + ":" + el.asType();
|
return el.getSimpleName() + ":" + el.asType();
|
||||||
case CONSTRUCTOR: case METHOD: {
|
case CONSTRUCTOR: case METHOD: {
|
||||||
@ -1753,7 +1766,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// receiver type
|
// receiver type
|
||||||
String clazz = elementHeader(at, el.getEnclosingElement(), includeParameterNames, false);
|
String clazz = elementHeader(at, getOriginalEnclosingElement(el), includeParameterNames, false);
|
||||||
header.append(clazz);
|
header.append(clazz);
|
||||||
|
|
||||||
if (isMethod) {
|
if (isMethod) {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439 8221759 8234896 8240658 8278039 8286206
|
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439 8221759 8234896 8240658 8278039 8286206 8296789
|
||||||
* @summary Test Completion and Documentation
|
* @summary Test Completion and Documentation
|
||||||
* @library /tools/lib
|
* @library /tools/lib
|
||||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
@ -791,4 +791,10 @@ public class CompletionSuggestionTest extends KullaTesting {
|
|||||||
public void testRecord() {
|
public void testRecord() {
|
||||||
assertCompletion("record R() implements Ru|", true, "Runnable");
|
assertCompletion("record R() implements Ru|", true, "Runnable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//JDK-8296789
|
||||||
|
public void testParentMembers() {
|
||||||
|
assertEval("var sb=new StringBuilder();");
|
||||||
|
assertCompletionIncludesExcludes("sb.|", true, Set.of("capacity()", "setLength("), Set.of("maybeLatin1"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user