9696import org .eclipse .jdt .core .dom .IfStatement ;
9797import org .eclipse .jdt .core .dom .ImportDeclaration ;
9898import org .eclipse .jdt .core .dom .InfixExpression ;
99+ import org .eclipse .jdt .core .dom .InfixExpression .Operator ;
99100import org .eclipse .jdt .core .dom .Initializer ;
100101import org .eclipse .jdt .core .dom .InstanceofExpression ;
101102import org .eclipse .jdt .core .dom .Javadoc ;
107108import org .eclipse .jdt .core .dom .MethodInvocation ;
108109import org .eclipse .jdt .core .dom .MethodRef ;
109110import org .eclipse .jdt .core .dom .Modifier ;
111+ import org .eclipse .jdt .core .dom .Modifier .ModifierKeyword ;
110112import org .eclipse .jdt .core .dom .ModuleDeclaration ;
111113import org .eclipse .jdt .core .dom .Name ;
112114import org .eclipse .jdt .core .dom .NodeFinder ;
147149import org .eclipse .jdt .core .dom .VariableDeclarationFragment ;
148150import org .eclipse .jdt .core .dom .VariableDeclarationStatement ;
149151import org .eclipse .jdt .core .dom .WhileStatement ;
150- import org .eclipse .jdt .core .dom .InfixExpression .Operator ;
151- import org .eclipse .jdt .core .dom .Modifier .ModifierKeyword ;
152152import org .eclipse .jdt .core .formatter .DefaultCodeFormatterConstants ;
153153import org .eclipse .jdt .core .search .IJavaSearchConstants ;
154154import org .eclipse .jdt .core .search .IJavaSearchScope ;
@@ -1335,6 +1335,21 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour
13351335 suggestDefaultCompletions = false ;
13361336 }
13371337 if (context instanceof MethodDeclaration methodDeclaration ) {
1338+ int closingParenLocation = methodDeclaration .getName ().getStartPosition () + methodDeclaration .getName ().getLength ();
1339+ boolean afterComma = true ;
1340+ while (closingParenLocation < this .textContent .length () && this .textContent .charAt (closingParenLocation ) != ')' ) {
1341+ if (afterComma ) {
1342+ if (!Character .isWhitespace (this .textContent .charAt (closingParenLocation ))) {
1343+ afterComma = false ;
1344+ }
1345+ } else {
1346+ // TODO: handle \u002C
1347+ if (this .textContent .charAt (closingParenLocation ) == ',' ) {
1348+ afterComma = true ;
1349+ }
1350+ }
1351+ closingParenLocation ++;
1352+ }
13381353 if (this .offset < methodDeclaration .getName ().getStartPosition ()) {
13391354 completeMethodModifiers (methodDeclaration );
13401355 // return type: suggest types from current CU
@@ -1347,9 +1362,22 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour
13471362 publishFromScope (specificCompletionBindings );
13481363 }
13491364 suggestDefaultCompletions = false ;
1350- } else if (methodDeclaration .getBody () == null || (methodDeclaration .getBody () != null && this .offset <= methodDeclaration .getBody ().getStartPosition ())) {
1365+ } else if (methodDeclaration .getBody () == null || (methodDeclaration .getBody () != null && this .offset <= methodDeclaration .getBody ().getStartPosition ()) && closingParenLocation < this . offset ) {
13511366 completeThrowsClause (methodDeclaration , specificCompletionBindings );
13521367 suggestDefaultCompletions = false ;
1368+ } else if (methodDeclaration .getName ().getStartPosition () + methodDeclaration .getName ().getLength () < this .offset && this .offset <= closingParenLocation && !afterComma ) {
1369+ // void myMethod(Integer a, Boolean |) { ...
1370+ SingleVariableDeclaration svd = (SingleVariableDeclaration )methodDeclaration .parameters ().get (methodDeclaration .parameters ().size () - 1 );
1371+ ITypeBinding typeBinding = svd .getType ().resolveBinding ();
1372+ Block block = methodDeclaration .getBody ();
1373+ Set <String > alreadySuggestedNames = new HashSet <>();
1374+ if (block != null ) {
1375+ suggestUndeclaredVariableNames (block , typeBinding , alreadySuggestedNames );
1376+ } else {
1377+ suggestUndeclaredVariableNames (typeBinding , alreadySuggestedNames );
1378+ }
1379+ suggestVariableNamesForType (typeBinding , alreadySuggestedNames );
1380+ suggestDefaultCompletions = false ;
13531381 } else if (this .offset > methodDeclaration .getStartPosition () + methodDeclaration .getLength ()) {
13541382 suggestModifierKeywords (0 );
13551383 }
@@ -2705,7 +2733,9 @@ private boolean filterTypeBasedOnAccess(IType type, String currentPackage, IType
27052733 }
27062734
27072735 private boolean isParameterInNonParameterizedType (ASTNode context ) {
2708- if (DOMCompletionUtil .findParent (context , new int [] { ASTNode .PARAMETERIZED_TYPE }) != null ) {
2736+ if (context instanceof ParameterizedType ) {
2737+ return true ;
2738+ } else if (DOMCompletionUtil .findParent (context , new int [] { ASTNode .PARAMETERIZED_TYPE }) != null ) {
27092739 ASTNode cursor1 = context ;
27102740 ASTNode cursor2 = context .getParent ();
27112741 while (!(cursor2 instanceof ParameterizedType paramType )) {
@@ -3137,9 +3167,13 @@ private void completeJavadocInlineTags(TagElement tagNode) {
31373167
31383168 private void completeThrowsClause (MethodDeclaration methodDeclaration , Bindings scope ) {
31393169 if (methodDeclaration .thrownExceptionTypes ().size () == 0 ) {
3140- int startScanIndex = Math .max (
3141- methodDeclaration .getName ().getStartPosition () + methodDeclaration .getName ().getLength (),
3142- methodDeclaration .getReturnType2 ().getStartPosition () + methodDeclaration .getReturnType2 ().getLength ());
3170+ int startScanIndex = -1 ;
3171+ if (methodDeclaration .getReturnType2 () != null ) {
3172+ startScanIndex = methodDeclaration .getReturnType2 ().getStartPosition () + methodDeclaration .getReturnType2 ().getLength ();
3173+ }
3174+ if (methodDeclaration .getName () != null ) {
3175+ startScanIndex = methodDeclaration .getName ().getStartPosition () + methodDeclaration .getName ().getLength ();
3176+ }
31433177 if (!methodDeclaration .parameters ().isEmpty ()) {
31443178 SingleVariableDeclaration lastParam = (SingleVariableDeclaration )methodDeclaration .parameters ().get (methodDeclaration .parameters ().size () - 1 );
31453179 startScanIndex = lastParam .getName ().getStartPosition () + lastParam .getName ().getLength ();
@@ -3470,9 +3504,9 @@ private void findOverridableMethods0(ITypeBinding currentType, ITypeBinding type
34703504 continue next ;
34713505 }
34723506 if (method .isSynthetic () || method .isConstructor ()
3507+ || Modifier .isPrivate (method .getModifiers ())
34733508 || (this .assistOptions .checkDeprecation && isDeprecated (method .getJavaElement ()))
34743509 || Modifier .isStatic (method .getModifiers ())
3475- || Modifier .isPrivate (method .getModifiers ())
34763510 || ((method .getModifiers () & (Modifier .PUBLIC | Modifier .PRIVATE | Modifier .PROTECTED )) == 0 ) && !typeBinding .getPackage ().getKey ().equals (originalPackageKey )) {
34773511 continue next ;
34783512 }
0 commit comments