mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-163989 IDEA reports Object.getClass() with wrong return type for generic parameters
This commit is contained in:
@@ -20,9 +20,13 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -89,12 +93,25 @@ public class MemberLookupHelper {
|
||||
presentation.appendTailText(location, true);
|
||||
}
|
||||
|
||||
final PsiType type = myMember instanceof PsiMethod ? ((PsiMethod)myMember).getReturnType() : ((PsiField) myMember).getType();
|
||||
PsiType declaredType = myMember instanceof PsiMethod ? ((PsiMethod)myMember).getReturnType() : ((PsiField)myMember).getType();
|
||||
PsiType type = patchGetClass(substitutor.substitute(declaredType));
|
||||
if (type != null) {
|
||||
presentation.setTypeText(substitutor.substitute(type).getPresentableText());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiType patchGetClass(@Nullable PsiType type) {
|
||||
if (myMember instanceof PsiMethod && PsiTypesUtil.isGetClass((PsiMethod)myMember) && type instanceof PsiClassType) {
|
||||
PsiType arg = ContainerUtil.getFirstItem(Arrays.asList(((PsiClassType)type).getParameters()));
|
||||
PsiType bound = arg instanceof PsiWildcardType ? TypeConversionUtil.erasure(((PsiWildcardType)arg).getExtendsBound()) : null;
|
||||
if (bound != null) {
|
||||
return PsiTypesUtil.createJavaLangClassType(myMember, bound, false);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static String getMethodParameterString(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor) {
|
||||
return PsiFormatUtil.formatMethod(method, substitutor,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class F {
|
||||
<R extends Number> void foo(R r) {
|
||||
r.getCl<caret>a
|
||||
}
|
||||
}
|
||||
+5
@@ -1730,4 +1730,9 @@ class Bar {
|
||||
|
||||
void testCopyConstructor() { doTest('\n') }
|
||||
|
||||
void testGetClassType() {
|
||||
configure()
|
||||
assert 'Class<? extends Number>' == LookupElementPresentation.renderElement(myFixture.lookupElements[0]).typeText
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user