Skip to content

Commit

Permalink
8296789: <TAB>-completion in jshell fails to expose synthetic bridge …
Browse files Browse the repository at this point in the history
…methods

Reviewed-by: jlahoda
  • Loading branch information
asotona committed Jan 11, 2023
1 parent 030e88d commit 257f667
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Expand Up @@ -52,6 +52,7 @@
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacScope;
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.VarSymbol;
import com.sun.tools.javac.code.Symtab;
Expand Down Expand Up @@ -1031,7 +1032,14 @@ private List<? extends Element> membersOf(AnalyzeTask at, TypeMirror site, boole
case DECLARED: {
TypeElement element = (TypeElement) at.getTypes().asElement(site);
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) {
result.add(createDotClassSymbol(at, site));
}
Expand Down Expand Up @@ -1680,6 +1688,11 @@ private List<Path> findSources() {
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) {
switch (el.getKind()) {
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE, RECORD: {
Expand Down Expand Up @@ -1730,9 +1743,9 @@ private String elementHeader(AnalyzeTask at, Element el, boolean includeParamete
.collect(joining(" & "));
}
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:
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:
return el.getSimpleName() + ":" + el.asType();
case CONSTRUCTOR: case METHOD: {
Expand All @@ -1753,7 +1766,7 @@ private String elementHeader(AnalyzeTask at, Element el, boolean includeParamete
}

// receiver type
String clazz = elementHeader(at, el.getEnclosingElement(), includeParameterNames, false);
String clazz = elementHeader(at, getOriginalEnclosingElement(el), includeParameterNames, false);
header.append(clazz);

if (isMethod) {
Expand Down
8 changes: 7 additions & 1 deletion test/langtools/jdk/jshell/CompletionSuggestionTest.java
Expand Up @@ -23,7 +23,7 @@

/*
* @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
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
Expand Down Expand Up @@ -791,4 +791,10 @@ public void testStatements() {
public void testRecord() {
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"));
}
}

1 comment on commit 257f667

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.