mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
shorten outer class ref in instanceof check fixed (IDEA-154823)
This commit is contained in:
@@ -265,6 +265,14 @@ public class JavaReferenceAdjuster implements ReferenceAdjuster {
|
||||
if (psiReference instanceof PsiJavaCodeReferenceElement) {
|
||||
PsiElement parent = psiReference.getParent();
|
||||
if (parent instanceof PsiNewExpression || parent.getParent() instanceof PsiNewExpression) return true;
|
||||
|
||||
if (parent instanceof PsiTypeElement &&
|
||||
parent.getParent() instanceof PsiInstanceOfExpression) {
|
||||
final PsiClass containingClass = refClass.getContainingClass();
|
||||
if (containingClass != null && containingClass.hasTypeParameters()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return helper.resolveReferencedVariable(referenceText, psiReference) == null;
|
||||
}
|
||||
|
||||
+17
-13
@@ -73,21 +73,25 @@ public class ShortenClassReferencesTest extends LightCodeInsightFixtureTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testOuterClassReferenceInInstanceof() throws Exception {
|
||||
myFixture.configureByText("a.java", "class Outer<T> {class Inner {} {boolean b = new Inner() instanceof Outer.Inner;}}\n" +
|
||||
"class Outer1 {class Inner {} {boolean b = new Inner() instanceof Outer1.Inner;}}");
|
||||
doShortenRefs();
|
||||
myFixture.checkResult("class Outer<T> {class Inner {} {boolean b = new Inner() instanceof Outer.Inner;}}\n" +
|
||||
"class Outer1 {class Inner {} {boolean b = new Inner() instanceof Inner;}}");
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(myFixture.getFile());
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "", "");
|
||||
doShortenRefs();
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
private void doShortenRefs() {
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), () -> WriteCommandAction.runWriteCommandAction(null, () -> {
|
||||
JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(myFixture.getFile());
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}), "", "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user