mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Substitution for PsiDisjunctionType
This commit is contained in:
@@ -18,6 +18,8 @@ package com.intellij.psi.impl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
@@ -25,10 +27,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author ik, dsl
|
||||
@@ -99,11 +98,13 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
}
|
||||
|
||||
private abstract static class SubstitutionVisitorBase extends PsiTypeVisitorEx<PsiType> {
|
||||
@Override
|
||||
public PsiType visitType(PsiType type) {
|
||||
LOG.assertTrue(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType visitWildcardType(PsiWildcardType wildcardType) {
|
||||
final PsiType bound = wildcardType.getBound();
|
||||
if (bound == null) {
|
||||
@@ -135,10 +136,12 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
return PsiWildcardType.createUnbounded(wildcardType.getManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType visitPrimitiveType(PsiPrimitiveType primitiveType) {
|
||||
return primitiveType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType visitArrayType(PsiArrayType arrayType) {
|
||||
final PsiType componentType = arrayType.getComponentType();
|
||||
final PsiType substitutedComponentType = componentType.accept(this);
|
||||
@@ -147,6 +150,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
return new PsiArrayType(substitutedComponentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType visitEllipsisType(PsiEllipsisType ellipsisType) {
|
||||
final PsiType componentType = ellipsisType.getComponentType();
|
||||
final PsiType substitutedComponentType = componentType.accept(this);
|
||||
@@ -155,15 +159,26 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
return new PsiEllipsisType(substitutedComponentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType visitTypeVariable(final PsiTypeVariable var) {
|
||||
return var;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType visitBottom(final Bottom bottom) {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract PsiType visitClassType(PsiClassType classType);
|
||||
|
||||
@Override
|
||||
public PsiType visitDisjunctionType(PsiDisjunctionType disjunctionType) {
|
||||
final List<PsiType> substituted = ContainerUtil.map(disjunctionType.getDisjunctions(), new Function<PsiType, PsiType>() {
|
||||
@Override public PsiType fun(PsiType psiType) { return psiType.accept(SubstitutionVisitorBase.this); }
|
||||
});
|
||||
return new PsiDisjunctionType(substituted, disjunctionType.getManager());
|
||||
}
|
||||
}
|
||||
|
||||
private final SubstitutionVisitor myAddingBoundsSubstitutionVisitor = new SubstitutionVisitor(SubstituteKind.ADD_BOUNDS);
|
||||
|
||||
+6
-3
@@ -5,9 +5,10 @@ abstract class C {
|
||||
private static class E2 extends E { }
|
||||
private static class E3 extends E { }
|
||||
private static class RE extends RuntimeException { }
|
||||
private interface I { }
|
||||
private static class IE1 extends E implements I { }
|
||||
private static class IE2 extends E implements I { }
|
||||
private interface I<T> { }
|
||||
private static class IE1 extends E implements I<Integer> { }
|
||||
private static class IE2 extends E implements I<Long> { }
|
||||
private static class F<X> { F(X x) { } }
|
||||
|
||||
abstract void f() throws E1, E2;
|
||||
abstract void g() throws IE1, IE2;
|
||||
@@ -18,6 +19,8 @@ abstract class C {
|
||||
try { f(); } catch (E2 | E1 e) { } catch (E e) { } catch (RE e) { }
|
||||
try { f(); } catch (E1 | E e) { E ee = e; }
|
||||
try { g(); } catch (IE1 | IE2 e) { E ee = e; I ii = e; }
|
||||
try { g(); } catch (IE1 | IE2 e) { F<?> f = new F<>(e); }
|
||||
try { g(); } catch (IE1 | IE2 e) { new F<I<? extends Number>>(e); }
|
||||
|
||||
try { f(); } catch (E1 | E2 | <error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> e) { }
|
||||
try { f(); } catch (<error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> | E e) { }
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.infos.ClassCandidateInfo;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
@@ -1166,11 +1167,9 @@ public class TypeConversionUtil {
|
||||
|
||||
@Override
|
||||
public PsiType visitDisjunctionType(PsiDisjunctionType disjunctionType) {
|
||||
final List<PsiType> original = disjunctionType.getDisjunctions();
|
||||
final List<PsiType> erased = new ArrayList<PsiType>(original.size());
|
||||
for (PsiType psiType : original) {
|
||||
erased.add(erasure(psiType, beforeSubstitutor));
|
||||
}
|
||||
final List<PsiType> erased = ContainerUtil.map(disjunctionType.getDisjunctions(), new Function<PsiType, PsiType>() {
|
||||
@Override public PsiType fun(PsiType psiType) { return erasure(psiType, beforeSubstitutor); }
|
||||
});
|
||||
return new PsiDisjunctionType(erased, disjunctionType.getManager());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user