Example #1
0
 public static boolean checkWhenExpressionHasSingleElse(
     @NotNull JetWhenExpression whenExpression) {
   int elseCount = 0;
   for (JetWhenEntry entry : whenExpression.getEntries()) {
     if (entry.isElse()) {
       elseCount++;
     }
   }
   return (elseCount == 1);
 }
Example #2
0
 @Nullable
 public static <T extends PsiElement> T getDirectParentOfTypeForBlock(
     @NotNull JetBlockExpression block, @NotNull Class<T> aClass) {
   T parent = PsiTreeUtil.getParentOfType(block, aClass);
   if (parent instanceof JetIfExpression) {
     JetIfExpression ifExpression = (JetIfExpression) parent;
     if (ifExpression.getElse() == block || ifExpression.getThen() == block) {
       return parent;
     }
   }
   if (parent instanceof JetWhenExpression) {
     JetWhenExpression whenExpression = (JetWhenExpression) parent;
     for (JetWhenEntry whenEntry : whenExpression.getEntries()) {
       if (whenEntry.getExpression() == block) {
         return parent;
       }
     }
   }
   if (parent instanceof JetFunctionLiteral) {
     JetFunctionLiteral functionLiteral = (JetFunctionLiteral) parent;
     if (functionLiteral.getBodyExpression() == block) {
       return parent;
     }
   }
   if (parent instanceof JetTryExpression) {
     JetTryExpression tryExpression = (JetTryExpression) parent;
     if (tryExpression.getTryBlock() == block) {
       return parent;
     }
     for (JetCatchClause clause : tryExpression.getCatchClauses()) {
       if (clause.getCatchBody() == block) {
         return parent;
       }
     }
   }
   return null;
 }