mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diamonds with anonymous: ensure base type calculated over tree cause too much context should be created otherwise (IDEA-166600)
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
|
||||
import com.intellij.psi.impl.java.stubs.PsiClassStub;
|
||||
import com.intellij.psi.impl.source.tree.ChildRole;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.reference.SoftReference;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -74,7 +75,7 @@ public class PsiAnonymousClassImpl extends PsiClassImpl implements PsiAnonymousC
|
||||
PsiClassType type = SoftReference.dereference(myCachedBaseType);
|
||||
if (type != null) return type;
|
||||
|
||||
if (!isInQualifiedNew()) {
|
||||
if (!isInQualifiedNew() && !isDiamond()) {
|
||||
final String refText = stub.getBaseClassReferenceText();
|
||||
assert refText != null : stub;
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
@@ -96,6 +97,19 @@ public class PsiAnonymousClassImpl extends PsiClassImpl implements PsiAnonymousC
|
||||
return getTypeByTree();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDiamond() {
|
||||
if (PsiUtil.isLanguageLevel9OrHigher(this)) {
|
||||
final PsiReferenceParameterList parameterList = getBaseClassReference().getParameterList();
|
||||
if (parameterList != null) {
|
||||
final PsiTypeElement[] parameterElements = parameterList.getTypeParameterElements();
|
||||
if (parameterElements.length == 1) {
|
||||
return parameterElements[0].getType() instanceof PsiDiamondType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private PsiClassType getTypeByTree() {
|
||||
return JavaPsiFacade.getInstance(getProject()).getElementFactory().createType(getBaseClassReference());
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
class Outer {
|
||||
Comparable<String> f() {
|
||||
return new Comparable<>() {
|
||||
@Override
|
||||
public int compareTo(String o) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
@@ -47,6 +47,7 @@ public class LightAdvHighlightingJdk9Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testDiamondsWithAnonymousRejectNotAccessibleType() { doTest(false, false);}
|
||||
public void testDiamondsWithAnonymousRejectIntersectionType() { doTest(false, false);}
|
||||
public void testDiamondsWithAnonymousInsideCallToInfer() { doTest(false, false);}
|
||||
public void testDiamondsWithAnonymousDiamond() { doTest(false, false);}
|
||||
|
||||
public void testValueTypes() { setLanguageLevel(LanguageLevel.JDK_X); doTest(false, false); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user