mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix reference to inner class of generic outer in static context (IDEA-215061)
GitOrigin-RevId: b969c41b3282bf89c4b44da598c7ec408ea8fec5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e0cd053939
commit
4b9293e63f
@@ -631,6 +631,16 @@ public class JavaCompletionUtil {
|
||||
return endOffset;
|
||||
}
|
||||
|
||||
if (reference != null && !psiClass.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiClass containingClass = psiClass.getContainingClass();
|
||||
if (containingClass != null && containingClass.hasTypeParameters()) {
|
||||
PsiModifierListOwner enclosingStaticElement = PsiUtil.getEnclosingStaticElement(reference.getElement(), null);
|
||||
if (enclosingStaticElement != null && !PsiTreeUtil.isAncestor(enclosingStaticElement, psiClass, false)) {
|
||||
return endOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert document != null;
|
||||
document.replaceString(startOffset, endOffset, name);
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ public class PsiTypeLookupItem extends LookupItem implements TypedLookupItem {
|
||||
if (name != null) {
|
||||
PsiClass resolved = JavaPsiFacade.getInstance(psiClass.getProject()).getResolveHelper().resolveReferencedClass(name, context);
|
||||
String[] allStrings;
|
||||
if (!psiClass.getManager().areElementsEquivalent(resolved, psiClass) && !PsiUtil.isInnerClass(psiClass)) {
|
||||
if (!psiClass.getManager().areElementsEquivalent(resolved, psiClass)) {
|
||||
// inner class name should be shown qualified if its not accessible by single name
|
||||
allStrings = ArrayUtil.toStringArray(JavaCompletionUtil.getAllLookupStrings(psiClass));
|
||||
} else {
|
||||
|
||||
+11
-3
@@ -31,6 +31,7 @@ import com.intellij.psi.impl.source.tree.*;
|
||||
import com.intellij.psi.jsp.JspFile;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ImportUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -275,11 +276,18 @@ public class JavaReferenceAdjuster implements ReferenceAdjuster {
|
||||
PsiElement parent = psiReference.getParent();
|
||||
if (parent instanceof PsiNewExpression || parent.getParent() instanceof PsiNewExpression) return true;
|
||||
|
||||
if (parent instanceof PsiTypeElement &&
|
||||
parent.getParent() instanceof PsiInstanceOfExpression) {
|
||||
if (parent instanceof PsiTypeElement) {
|
||||
final PsiClass containingClass = refClass.getContainingClass();
|
||||
if (containingClass != null && containingClass.hasTypeParameters()) {
|
||||
return false;
|
||||
if (parent.getParent() instanceof PsiInstanceOfExpression) {
|
||||
return false;
|
||||
}
|
||||
if (!refClass.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiModifierListOwner enclosingStaticElement = PsiUtil.getEnclosingStaticElement(psiReference, null);
|
||||
if (enclosingStaticElement != null && !PsiTreeUtil.isAncestor(enclosingStaticElement, refClass, false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create local variable 'inner'" "true"
|
||||
class OuterGeneric<T> {
|
||||
class Inner {
|
||||
}
|
||||
static OuterGeneric<Object>.Inner create() {
|
||||
return null;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
OuterGeneric.Inner inner = create();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create local variable 'inner'" "true"
|
||||
class OuterGeneric<T> {
|
||||
class Inner {
|
||||
}
|
||||
static OuterGeneric<Object>.Inner create() {
|
||||
return null;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
i<caret>nner = create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user