mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
check extends/implements list for nested classes of super type (IDEA-108287)
This commit is contained in:
@@ -1261,5 +1261,27 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkCannotPassInner(PsiJavaCodeReferenceElement ref) {
|
||||
if (ref.getParent() instanceof PsiTypeElement) {
|
||||
final PsiClass psiClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class);
|
||||
if (psiClass != null) {
|
||||
if (PsiTreeUtil.isAncestor(psiClass.getExtendsList(), ref, false) ||
|
||||
PsiTreeUtil.isAncestor(psiClass.getImplementsList(), ref, false)) {
|
||||
final PsiElement qualifier = ref.getQualifier();
|
||||
if (qualifier instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)qualifier).resolve() == psiClass) {
|
||||
final PsiElement resolve = ref.resolve();
|
||||
if (resolve instanceof PsiClass) {
|
||||
final PsiClass containingClass = ((PsiClass)resolve).getContainingClass();
|
||||
if (containingClass != null && psiClass.isInheritor(containingClass, true)) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).descriptionAndTooltip(((PsiClass)resolve).getName() + " is not accessible in current context").range(ref).create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -929,6 +929,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkSelectStaticClassFromParameterizedType(resolved, ref));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkParameterizedReferenceTypeArguments(resolved, ref,
|
||||
result.getSubstitutor()));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkCannotPassInner(ref));
|
||||
|
||||
if (resolved != null && parent instanceof PsiReferenceList) {
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkElementInReferenceList(ref, (PsiReferenceList)parent, result));
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo<T> {
|
||||
static class Nested {};
|
||||
}
|
||||
class Bar extends Foo<<error descr="Nested is not accessible in current context">Bar.Nested</error>> {}
|
||||
|
||||
interface FooI<T> {
|
||||
interface Nested {};
|
||||
}
|
||||
interface BarI extends FooI<<error descr="Nested is not accessible in current context">BarI.Nested</error>> {}
|
||||
@@ -257,6 +257,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
|
||||
}
|
||||
|
||||
public void testIDEA108287() throws Exception {
|
||||
doTest5(false);
|
||||
}
|
||||
|
||||
public void testDisableCastingToNestedWildcards() throws Exception {
|
||||
doTest5(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user