This is an automated email from the ASF dual-hosted git repository. matthiasblaesing pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 5b55a370fb Fix: Java completion parameter tooltip is not shown if previous parameter is type variable new 1a29d61d4c Merge pull request #6268 from matthiasblaesing/parameter_tooltip 5b55a370fb is described below commit 5b55a370fb1c2dc79c9af614e0c7a2629f182b86 Author: Matthias Bläsing <mblaes...@doppel-helix.eu> AuthorDate: Fri Jul 28 22:46:41 2023 +0200 Fix: Java completion parameter tooltip is not shown if previous parameter is type variable Testsetup: public class TestParamResolution { public static void main(String[] args) { List.of("Hallo", "World"); testMethod("Hello", "World", "Test"); testMethod(1, "Hello", "World"); } public static <S extends String & Comparable<String> & Serializable> void testMethod(S genericParam, String dummy1_1, String dummy1_2) {} public static <S extends Integer> void testMethod(S genericParam, String dummy2_1, String dummy2_2) {} public static <T extends Integer & Externalizable> void testArgumentTypeVariableParameter(T genericParam, List<? super String> x) { testMethod(genericParam, "x", "dfd"); } } Inside main the problem can be demonstrated with all demonstrated calls. When the caret is placed in the first argument (before first comma), the parameter popup (CTRL+P) can be opened for all case. If the caret is placed in the second argument (after first comma), it does not work anymore. Investigation shows that javax.lang.model.util.Types#isAssignable returns false if the target type is a TypeVariable. To fix this the upper bound of the TypeMirror is unwrapped and the check is repeated. This also works if the argument is a TypeVariable itself. With this fix applied all places (main and testArgumentTypeVariableParameter) allow to invoke the parameter popup. --- .../netbeans/modules/java/completion/JavaTooltipTask.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/java/java.completion/src/org/netbeans/modules/java/completion/JavaTooltipTask.java b/java/java.completion/src/org/netbeans/modules/java/completion/JavaTooltipTask.java index 81a9308ced..10149c3d09 100644 --- a/java/java.completion/src/org/netbeans/modules/java/completion/JavaTooltipTask.java +++ b/java/java.completion/src/org/netbeans/modules/java/completion/JavaTooltipTask.java @@ -275,7 +275,7 @@ public final class JavaTooltipTask extends BaseTask { ret.add(paramStrings); break; } - if (argTypes[i] == null || argTypes[i].getKind() != TypeKind.ERROR && !types.isAssignable(argTypes[i], param)) { + if (argTypes[i] == null || argTypes[i].getKind() != TypeKind.ERROR && !isAssignable(types, argTypes[i], param)) { break; } } @@ -284,4 +284,14 @@ public final class JavaTooltipTask extends BaseTask { } return ret.isEmpty() ? null : ret; } + + private static boolean isAssignable(Types types, TypeMirror arg, TypeMirror parameter) { + if(types.isAssignable(arg, parameter)) { + return true; + } else if (parameter instanceof TypeVariable) { + TypeMirror requiredTypes = ((TypeVariable) parameter).getUpperBound(); + return types.isAssignable(arg, requiredTypes); + } + return false; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists