Skip to content

Commit cfbbcd7

Browse files
committed
8350595: jshell <TAB> completion on arrays does not work for clone()
Reviewed-by: asotona
1 parent 4c3c2b3 commit cfbbcd7

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@
5454
import com.sun.tools.javac.code.Flags;
5555
import com.sun.tools.javac.code.Symbol;
5656
import com.sun.tools.javac.code.Symbol.CompletionFailure;
57+
import com.sun.tools.javac.code.Symbol.MethodSymbol;
5758
import com.sun.tools.javac.code.Symbol.VarSymbol;
5859
import com.sun.tools.javac.code.Symtab;
5960
import com.sun.tools.javac.code.Type;
6061
import com.sun.tools.javac.code.Type.ClassType;
62+
import com.sun.tools.javac.code.Type.MethodType;
6163
import com.sun.tools.javac.parser.Scanner;
6264
import com.sun.tools.javac.parser.ScannerFactory;
6365
import com.sun.tools.javac.parser.Tokens.Token;
@@ -1073,7 +1075,7 @@ private List<? extends Element> membersOf(AnalyzeTask at, TypeMirror site, boole
10731075
if (jlObject != null) {
10741076
result.addAll(membersOf(at, jlObject));
10751077
}
1076-
result.add(createArrayLengthSymbol(at, site));
1078+
result.addAll(createArraySymbols(at, site));
10771079
if (shouldGenerateDotClassItem)
10781080
result.add(createDotClassSymbol(at, site));
10791081
return result;
@@ -1161,11 +1163,21 @@ private PackageElement createPackageElement(AnalyzeTask at, String packageName)
11611163
return existing;
11621164
}
11631165

1164-
private Element createArrayLengthSymbol(AnalyzeTask at, TypeMirror site) {
1165-
Name length = Names.instance(at.getContext()).length;
1166-
Type intType = Symtab.instance(at.getContext()).intType;
1167-
1168-
return new VarSymbol(Flags.PUBLIC | Flags.FINAL, length, intType, ((Type) site).tsym);
1166+
private List<Element> createArraySymbols(AnalyzeTask at, TypeMirror site) {
1167+
Symtab syms = Symtab.instance(at.getContext());
1168+
Names names = Names.instance(at.getContext());
1169+
Name length = names.length;
1170+
Name clone = names.clone;
1171+
Type lengthType = syms.intType;
1172+
Type cloneType = new MethodType(com.sun.tools.javac.util.List.<Type>nil(),
1173+
(Type) site,
1174+
com.sun.tools.javac.util.List.<Type>nil(),
1175+
syms.methodClass);
1176+
1177+
return List.of(
1178+
new VarSymbol(Flags.PUBLIC | Flags.FINAL, length, lengthType, ((Type) site).tsym),
1179+
new MethodSymbol(Flags.PUBLIC | Flags.FINAL, clone, cloneType, ((Type) site).tsym)
1180+
);
11691181
}
11701182

11711183
private Element createDotClassSymbol(AnalyzeTask at, TypeMirror site) {

test/langtools/jdk/jshell/CompletionSuggestionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439 8221759 8234896 8240658 8278039 8286206 8296789 8314662 8326333
26+
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439 8221759 8234896 8240658 8278039 8286206 8296789 8314662 8326333 8326333
2727
* @summary Test Completion and Documentation
2828
* @library /tools/lib
2929
* @modules jdk.compiler/com.sun.tools.javac.api
@@ -812,13 +812,16 @@ public void testDuplicateImport() {
812812
}
813813

814814
//JDK-8326333: verify completion returns sensible output for arrays:
815+
//JDK-8326333: jshell <TAB> completion on arrays is incomplete
815816
public void testArray() {
816817
assertEval("String[] strs = null;");
817818
assertCompletion("strs.to|", "toString()");
818819
assertCompletion("strs.le|", "length");
820+
assertCompletion("strs.cl|", "clone()");
819821
assertEval("int[] ints = null;");
820822
assertCompletion("ints.no|", "notify()", "notifyAll()");
821823
assertCompletion("ints.le|", "length");
824+
assertCompletion("ints.cl|", "clone()");
822825
assertCompletion("String[].|", "class");
823826
}
824827
}

0 commit comments

Comments
 (0)