Java: create correct field from parameter with unbounded type parameter (IDEA-365468)

GitOrigin-RevId: 218b864c95d25b6ff47e9360e0eeef47308f0ae8
This commit is contained in:
Bas Leijdekkers
2025-01-07 16:42:41 +01:00
committed by intellij-monorepo-bot
parent 135bd98b37
commit 3c99de56be
3 changed files with 7 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.intention.impl;
import com.intellij.codeInsight.NullableNotNullManager;
@@ -61,7 +61,9 @@ public final class FieldFromParameterUtils {
for (PsiTypeParameter usedTypeParameter : usedTypeParameters) {
PsiType bound = TypeConversionUtil.typeParameterErasure(usedTypeParameter);
PsiManager manager = usedTypeParameter.getManager();
subst = subst.put(usedTypeParameter, bound == null ? PsiWildcardType.createUnbounded(manager) : bound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) ? bound : PsiWildcardType.createExtends(manager, bound));
subst = subst.put(usedTypeParameter, bound == null || bound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)
? PsiWildcardType.createUnbounded(manager)
: PsiWildcardType.createExtends(manager, bound));
}
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;

View File

@@ -2,9 +2,11 @@
class Bar {
private Class<?> myA;
private int myB;
<T> void get(Class<T> a, int b) {
myA = a;
myB = b;
}
}

View File

@@ -2,7 +2,7 @@
import java.util.*;
class Test{
private List<Object> myP1;
private List<?> myP1;
<T> void f(List<T> p1){
myP1 = p1;