debugger evaluator: support multiple exceptions catch syntax
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Thu, 10 Mar 2016 09:08:16 +0000 (12:08 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Thu, 10 Mar 2016 09:09:08 +0000 (12:09 +0300)
java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java
java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/TryEvaluator.java

index 9b8643e2f91fb2568108aa24e986ac64a834c732..2362332463e87c37124ee529a431f44125fb9204 100644 (file)
@@ -193,19 +193,25 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder {
       Evaluator bodyEvaluator = accept(statement.getTryBlock());
       if (bodyEvaluator != null) {
         PsiCatchSection[] catchSections = statement.getCatchSections();
-        CatchEvaluator[] evaluators = new CatchEvaluator[catchSections.length];
-        for (int i = 0; i < catchSections.length; i++) {
-          CodeFragmentEvaluator oldFragmentEvaluator = setNewCodeFragmentEvaluator();
-          try {
-            PsiCatchSection section = catchSections[i];
-            PsiParameter parameter = section.getParameter();
-            if (parameter != null) {
+        List<CatchEvaluator> evaluators = new ArrayList<>();
+        for (PsiCatchSection catchSection : catchSections) {
+          PsiParameter parameter = catchSection.getParameter();
+          PsiCodeBlock catchBlock = catchSection.getCatchBlock();
+          if (parameter != null && catchBlock != null) {
+            CodeFragmentEvaluator oldFragmentEvaluator = setNewCodeFragmentEvaluator();
+            try {
               myCurrentFragmentEvaluator.setInitialValue(parameter.getName(), null);
-              myCurrentFragmentEvaluator.setStatements(visitStatements(section.getCatchBlock().getStatements()));
-              evaluators[i] = new CatchEvaluator(parameter.getType().getCanonicalText(), parameter.getName(), myCurrentFragmentEvaluator);
+              myCurrentFragmentEvaluator.setStatements(visitStatements(catchBlock.getStatements()));
+              PsiType type = parameter.getType();
+              List<PsiType> types =
+                type instanceof PsiDisjunctionType ? ((PsiDisjunctionType)type).getDisjunctions() : Collections.singletonList(type);
+              for (PsiType psiType : types) {
+                evaluators.add(new CatchEvaluator(psiType.getCanonicalText(), parameter.getName(), myCurrentFragmentEvaluator));
+              }
+            }
+            finally{
+              myCurrentFragmentEvaluator = oldFragmentEvaluator;
             }
-          } finally {
-            myCurrentFragmentEvaluator = oldFragmentEvaluator;
           }
         }
         myResult = new TryEvaluator(bodyEvaluator, evaluators, accept(statement.getFinallyBlock()));
index 14448e58dd10386e9e600c260892ed808f5e0e54..d3267e6f2ab611593b9d44f747d867ec2398ac58 100644 (file)
@@ -22,16 +22,18 @@ import com.sun.jdi.ObjectReference;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.util.List;
+
 /**
  * @author egor
  */
 public class TryEvaluator implements Evaluator {
   @NotNull private final Evaluator myBodyEvaluator;
-  private final CatchEvaluator[] myCatchBlockEvaluators;
+  private final List<CatchEvaluator> myCatchBlockEvaluators;
   @Nullable private final Evaluator myFinallyEvaluator;
 
   public TryEvaluator(@NotNull Evaluator bodyEvaluator,
-                      CatchEvaluator[] catchBlockEvaluators,
+                      List<CatchEvaluator> catchBlockEvaluators,
                       @Nullable Evaluator finallyEvaluator) {
     myBodyEvaluator = bodyEvaluator;
     myCatchBlockEvaluators = catchBlockEvaluators;