mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] [highlighting] improved cannot inherit from raw & generics messages (IDEA-274330)
GitOrigin-RevId: 711578354a7ceeec0528e9ba85d23e4f4eeda45c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b579929e06
commit
e3bf1c11ce
+15
-6
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.daemon.JavaErrorBundle;
|
||||
@@ -359,8 +359,9 @@ public final class GenericsHighlightUtil {
|
||||
final PsiClass superClass = result.getElement();
|
||||
if (superClass == null || visited.contains(superClass)) continue;
|
||||
PsiSubstitutor superTypeSubstitutor = result.getSubstitutor();
|
||||
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(aClass.getProject());
|
||||
//JLS 4.8 The superclasses (respectively, superinterfaces) of a raw type are the erasures of the superclasses (superinterfaces) of any of the parameterizations of the generic type.
|
||||
superTypeSubstitutor = PsiUtil.isRawSubstitutor(aClass, derivedSubstitutor) ? JavaPsiFacade.getElementFactory(aClass.getProject()).createRawSubstitutor(superClass)
|
||||
superTypeSubstitutor = PsiUtil.isRawSubstitutor(aClass, derivedSubstitutor) ? elementFactory.createRawSubstitutor(superClass)
|
||||
: MethodSignatureUtil.combineSubstitutors(superTypeSubstitutor, derivedSubstitutor);
|
||||
|
||||
final PsiSubstitutor inheritedSubstitutor = inheritedClasses.get(superClass);
|
||||
@@ -371,10 +372,18 @@ public final class GenericsHighlightUtil {
|
||||
PsiType type2 = superTypeSubstitutor.substitute(typeParameter);
|
||||
|
||||
if (!Comparing.equal(type1, type2)) {
|
||||
String description = JavaErrorBundle.message("generics.cannot.be.inherited.with.different.type.arguments",
|
||||
HighlightUtil.formatClass(superClass),
|
||||
JavaHighlightUtil.formatType(type1),
|
||||
JavaHighlightUtil.formatType(type2));
|
||||
String description;
|
||||
if (type1 != null && type2 != null) {
|
||||
description = JavaErrorBundle.message("generics.cannot.be.inherited.with.different.type.arguments",
|
||||
HighlightUtil.formatClass(superClass),
|
||||
JavaHighlightUtil.formatType(type1),
|
||||
JavaHighlightUtil.formatType(type2));
|
||||
}
|
||||
else {
|
||||
description = JavaErrorBundle.message("generics.cannot.be.inherited.as.raw.and.generic",
|
||||
HighlightUtil.formatClass(superClass),
|
||||
JavaHighlightUtil.formatType(type1 != null ? type1 : type2));
|
||||
}
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ generics.type.parameter.is.not.within.its.bound.implement=Type parameter ''{0}''
|
||||
generics.type.or.method.does.not.have.type.parameters={0} ''{1}'' does not have type parameters
|
||||
generics.wrong.number.of.type.arguments=Wrong number of type arguments: {0}; required: {1}
|
||||
generics.cannot.be.inherited.with.different.type.arguments=''{0}'' cannot be inherited with different type arguments: ''{1}'' and ''{2}''
|
||||
generics.cannot.be.inherited.as.raw.and.generic=''{0}'' cannot be inherited as a raw type and with generic type arguments ''{1}''
|
||||
generics.select.static.class.from.parameterized.type=Cannot select static class ''{0}'' from parameterized type
|
||||
generics.methods.have.same.erasure={0}; both methods have same erasure
|
||||
generics.methods.have.same.erasure.override={0}; both methods have same erasure, yet neither overrides the other
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ interface Z1 extends X1, Y1 { }
|
||||
|
||||
interface X2 extends A<String> {}
|
||||
interface Y2<T> extends A<Integer> {}
|
||||
<error descr="'A' cannot be inherited with different type arguments: 'java.lang.String' and 'null'">interface Z2 extends X2, Y2</error> { }
|
||||
<error descr="'A' cannot be inherited as a raw type and with generic type arguments 'java.lang.String'">interface Z2 extends X2, Y2</error> { }
|
||||
|
||||
interface X3 extends A<String> {}
|
||||
interface Y3 extends A<Integer> {}
|
||||
|
||||
Reference in New Issue
Block a user