From 537ee9cfcb5094087e9a4066c01f74bff9deac79 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 17 Feb 2011 18:21:19 +0100 Subject: [PATCH] Substitution for PsiDisjunctionType --- .../intellij/psi/impl/PsiSubstitutorImpl.java | 23 +++++++++++++++---- .../advHighlighting7/MultiCatch.java | 9 +++++--- .../intellij/psi/util/TypeConversionUtil.java | 9 ++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java index a7676dc247f2..14527352e906 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java @@ -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 { + @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 substituted = ContainerUtil.map(disjunctionType.getDisjunctions(), new Function() { + @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); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/MultiCatch.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/MultiCatch.java index 69cf037ebaae..705ecd8a6550 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/MultiCatch.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/MultiCatch.java @@ -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 { } + private static class IE1 extends E implements I { } + private static class IE2 extends E implements I { } + private static class F { 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>(e); } try { f(); } catch (E1 | E2 | E3 e) { } try { f(); } catch (E3 | E e) { } diff --git a/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java b/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java index feb7c854bd8e..bbe345501d62 100644 --- a/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java +++ b/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java @@ -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 original = disjunctionType.getDisjunctions(); - final List erased = new ArrayList(original.size()); - for (PsiType psiType : original) { - erased.add(erasure(psiType, beforeSubstitutor)); - } + final List erased = ContainerUtil.map(disjunctionType.getDisjunctions(), new Function() { + @Override public PsiType fun(PsiType psiType) { return erasure(psiType, beforeSubstitutor); } + }); return new PsiDisjunctionType(erased, disjunctionType.getManager()); } });