mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
select from type parameter error processing (IDEA-62453)
This commit is contained in:
+17
@@ -29,6 +29,8 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.JavaVersionService;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
@@ -906,6 +908,21 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myRefCountHolder.registerReference(ref, result);
|
||||
}
|
||||
myHolder.add(HighlightUtil.checkReference(ref, result));
|
||||
if (!myHolder.hasErrorResults() && resolved instanceof PsiTypeParameter) {
|
||||
boolean cannotSelectFromTypeParameter = !JavaVersionService.getInstance().isAtLeast(ref, JavaSdkVersion.JDK_1_7);
|
||||
if (!cannotSelectFromTypeParameter) {
|
||||
final PsiClass containingClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class);
|
||||
if (containingClass != null) {
|
||||
if (PsiTreeUtil.isAncestor(containingClass.getExtendsList(), ref, false) ||
|
||||
PsiTreeUtil.isAncestor(containingClass.getImplementsList(), ref, false)) {
|
||||
cannotSelectFromTypeParameter = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cannotSelectFromTypeParameter) {
|
||||
myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).descriptionAndTooltip("Cannot select from a type parameter").range(ref).create());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkAbstractInstantiation(ref, resolved));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkExtendsDuplicate(ref, resolved));
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import java.util.List;
|
||||
interface Builder<T> {
|
||||
T build();
|
||||
}
|
||||
|
||||
interface Test<D extends Test<D, X>, X> {
|
||||
static interface TestBuilder<D extends Test<D, X>, X> extends Builder<D> {}
|
||||
}
|
||||
|
||||
interface Algorithm<T, B extends Builder<T>> {}
|
||||
|
||||
class SelectFromVariableType<X, T extends Test<T, X>>
|
||||
implements Algorithm<T,<error descr="Cannot select from a type parameter">T</error>.TestBuilder<T, X>> {
|
||||
List<<error descr="Cannot select from a type parameter">T</error>.TestBuilder<T, X>> b;
|
||||
<error descr="Cannot select from a type parameter">T</error>.TestBuilder<T, X> b1;
|
||||
}
|
||||
+19
-1
@@ -1,3 +1,4 @@
|
||||
import java.util.List;
|
||||
class A<D> {
|
||||
abstract class C<S> {
|
||||
<T extends A> void foo(T.C<Integer> x) {
|
||||
@@ -28,4 +29,21 @@ class A1 {
|
||||
|
||||
abstract S bar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Builder<T> {
|
||||
T build();
|
||||
}
|
||||
|
||||
interface Test<D extends Test<D, X>, X> {
|
||||
static interface TestBuilder<D extends Test<D, X>, X> extends Builder<D> {}
|
||||
}
|
||||
|
||||
interface Algorithm<T, B extends Builder<T>> {}
|
||||
|
||||
class SelectFromVariableType<X, T extends Test<T, X>>
|
||||
implements Algorithm<T, <error descr="Cannot select from a type parameter">T</error>.TestBuilder<T, X>> {
|
||||
|
||||
List<T.TestBuilder<T, X>> b;
|
||||
T.TestBuilder<T, X> b1;
|
||||
}
|
||||
|
||||
+2
-1
@@ -177,7 +177,8 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testContinueInferenceAfterFirstRawResult() { doTest5(false); }
|
||||
public void testDoNotAcceptLowerBoundIfRaw() { doTest5(false); }
|
||||
public void testStaticOverride() { doTest5(false); }
|
||||
public void testTypeArgumentsGivenOnRawType() { doTest5(false); }
|
||||
public void testTypeArgumentsGivenOnRawType() { doTest7Incompatibility(false); }
|
||||
public void testSelectFromTypeParameter() { doTest5(false); }
|
||||
public void testTypeArgumentsGivenOnAnonymousClassCreation() { doTest5(false); }
|
||||
//public void testIDEA94011() { doTest5(false); }
|
||||
public void testDifferentTypeParamsInOverloadedMethods() { doTest5(true); }
|
||||
|
||||
Reference in New Issue
Block a user