resolve on nested captures (IDEA-156170)

This commit is contained in:
Anna Kozlova
2016-05-26 18:48:46 +03:00
parent 4585214187
commit 49816aeded
3 changed files with 30 additions and 4 deletions

View File

@@ -28,6 +28,7 @@ import com.intellij.psi.scope.JavaScopeProcessorEvent;
import com.intellij.psi.scope.MethodProcessorSetupFailedException;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.scope.processor.MethodsProcessor;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.IncorrectOperationException;
@@ -127,8 +128,7 @@ public class PsiScopesUtil {
processTypeDeclarations(lub, place, processor);
}
else if (type instanceof PsiCapturedWildcardType) {
final PsiType upperBound =
PsiClassImplUtil.correctType(((PsiCapturedWildcardType)type).getUpperBound(), place.getResolveScope());
final PsiType upperBound = getUpperBound((PsiCapturedWildcardType)type, place);
if (upperBound != null) {
processTypeDeclarations(PsiUtil.captureToplevelWildcards(upperBound, place), place, processor);
}
@@ -142,6 +142,15 @@ public class PsiScopesUtil {
}
}
private static PsiType getUpperBound(PsiCapturedWildcardType type, PsiElement place) {
GlobalSearchScope placeResolveScope = place.getResolveScope();
PsiType upperBound = PsiClassImplUtil.correctType(type.getUpperBound(), placeResolveScope);
while (upperBound instanceof PsiCapturedWildcardType) {
upperBound = PsiClassImplUtil.correctType(((PsiCapturedWildcardType)upperBound).getUpperBound(), placeResolveScope);
}
return upperBound;
}
public static boolean resolveAndWalk(@NotNull PsiScopeProcessor processor,
@NotNull PsiJavaCodeReferenceElement ref,
@Nullable PsiElement maxScope) {
@@ -355,8 +364,7 @@ public class PsiScopesUtil {
processQualifierType(((PsiDisjunctionType)type).getLeastUpperBound(), processor, manager, methodCall);
}
else if (type instanceof PsiCapturedWildcardType) {
final PsiType upperBound =
PsiClassImplUtil.correctType(((PsiCapturedWildcardType)type).getUpperBound(), methodCall.getResolveScope());
final PsiType upperBound = getUpperBound((PsiCapturedWildcardType)type, methodCall);
if (upperBound != null) {
processQualifierType(PsiUtil.captureToplevelWildcards(upperBound, methodCall), processor, manager, methodCall);
}

View File

@@ -0,0 +1,14 @@
import java.util.Collection;
class Test {
public void entitySetChanged(EntitySetEvent<? extends Number> event) {
event.getUpdatedEntities().forEach(entity -> {
entity.intValue();
});
}
}
interface EntitySetEvent<V> {
Collection<? extends V> getUpdatedEntities();
}

View File

@@ -990,4 +990,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testUnifiedSubstitutorUpInTheHierarchy() throws Exception {
doTest();
}
public void testNestedCaptures() throws Exception {
doTest();
}
}