2020import java .util .Deque ;
2121import java .util .HashMap ;
2222import java .util .HashSet ;
23+ import java .util .LinkedHashSet ;
2324import java .util .LinkedList ;
2425import java .util .List ;
2526import java .util .Map ;
@@ -1786,7 +1787,8 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour
17861787 }
17871788 }
17881789 if (context instanceof VariableDeclarationFragment vdf ) {
1789- if (this .toComplete .equals (vdf .getName ())) {
1790+ if (this .toComplete .equals (vdf .getName ())
1791+ || this .toComplete .getLength () == 0 /* recovered */ ) {
17901792 ITypeBinding typeBinding = null ;
17911793 if (vdf .getParent () instanceof VariableDeclarationStatement vds ) {
17921794 typeBinding = vds .getType ().resolveBinding ();
@@ -2211,16 +2213,35 @@ private void suggestUndeclaredVariableNames(Block block, ITypeBinding typeBindin
22112213 }
22122214 }
22132215
2216+ private static boolean isCollection (ITypeBinding type ) {
2217+ if (type == null ) {
2218+ return false ;
2219+ }
2220+ if (Collection .class .getName ().equals (type .getErasure ().getQualifiedName ())) {
2221+ return true ;
2222+ }
2223+ return isCollection (type .getSuperclass ()) || Arrays .stream (type .getInterfaces ()).anyMatch (DOMCompletionEngine ::isCollection );
2224+ }
2225+
22142226 private void suggestVariableNamesForType (ITypeBinding typeBinding , Set <String > alreadySuggestedNames ) {
22152227 if (typeBinding .isPrimitive () || typeBinding .isRecovered ()) {
22162228 return ;
22172229 }
2230+ Set <String > possibleNames = new LinkedHashSet <>();
22182231
2219- String simpleName ;
2232+ String simpleName = "" ;
2233+ boolean multiple = false ;
22202234 if (typeBinding .isArray ()) {
22212235 simpleName = typeBinding .getElementType ().getName ();
2236+ multiple = true ;
2237+ } else if (typeBinding .isParameterizedType () && isCollection (typeBinding )) {
2238+ possibleNames .add (typeBinding .getErasure ().getName ().toLowerCase ());
2239+ multiple = true ;
2240+ if (typeBinding .getTypeArguments ().length > 0 ) {
2241+ simpleName = typeBinding .getTypeArguments ()[0 ].getErasure ().getName ();
2242+ }
22222243 } else {
2223- simpleName = typeBinding .getName ();
2244+ simpleName = typeBinding .getErasure (). getName ();
22242245 }
22252246
22262247 List <String > nameSegments = Stream .of (simpleName .split ("(?=_)|(?<=_)" )).flatMap (nameSegment -> Stream .of (nameSegment .split ("(?<=[a-z0-9])(?=[A-Z])" ))).filter (str -> !str .isEmpty ()).toList ();
@@ -2241,7 +2262,7 @@ private void suggestVariableNamesForType(ITypeBinding typeBinding, Set<String> a
22412262 for (int j = i + 1 ; j < nameSegments .size (); j ++) {
22422263 variablePortionOfName .append (nameSegments .get (j ));
22432264 }
2244- if (typeBinding . isArray () ) {
2265+ if (multiple ) {
22452266 if (variablePortionOfName .toString ().endsWith ("s" )) {
22462267 variablePortionOfName .append ("es" );
22472268 } else {
@@ -2265,7 +2286,6 @@ private void suggestVariableNamesForType(ITypeBinding typeBinding, Set<String> a
22652286 }
22662287 // there is always the implicit suffix of ""
22672288 suffixes .add ("" );
2268- Set <String > possibleNames = new HashSet <>();
22692289 Map <String , Integer > additionalRelevances = new HashMap <>();
22702290 boolean firstPrefix = true ;
22712291 boolean firstSuffix = true ;
@@ -2374,7 +2394,7 @@ private void suggestVariableNamesForType(ITypeBinding typeBinding, Set<String> a
23742394 alreadySuggestedNames .add (possibleName );
23752395 CompletionProposal res = createProposal (CompletionProposal .VARIABLE_DECLARATION );
23762396
2377- int additionalRelevance = additionalRelevances .get (possibleName );
2397+ int additionalRelevance = additionalRelevances .getOrDefault (possibleName , 0 );
23782398 if (SourceVersion .isKeyword (possibleName )) {
23792399 possibleName += "1" ;
23802400 }
@@ -4075,14 +4095,6 @@ private boolean staticOnly() {
40754095 return false ;
40764096 }
40774097
4078- private String qualifiedTypeName (ITypeBinding typeBinding ) {
4079- if (typeBinding .isTypeVariable ()) {
4080- return typeBinding .getName ();
4081- } else {
4082- return typeBinding .getQualifiedName ();
4083- }
4084- }
4085-
40864098 private CompletionProposal toProposal (TypeNameMatch typeNameMatch ) {
40874099 return toProposal (typeNameMatch .getType (), typeNameMatch .getAccessibility ());
40884100 }
0 commit comments