private static boolean containsAllCases(GrSwitchStatement statement) {
    final GrCaseSection[] sections = statement.getCaseSections();
    for (GrCaseSection section : sections) {
      if (section.isDefault()) return true;
    }

    final GrExpression condition = statement.getCondition();
    if (!(condition instanceof GrReferenceExpression)) return false;

    PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(getNominalTypeNoRecursion(condition));
    if (type == null) return false;

    if (type instanceof PsiPrimitiveType) {
      if (type == PsiType.BOOLEAN) return sections.length == 2;
      if (type == PsiType.BYTE || type == PsiType.CHAR) return sections.length == 128;
      return false;
    }

    if (type instanceof PsiClassType) {
      final PsiClass resolved = ((PsiClassType) type).resolve();
      if (resolved != null && resolved.isEnum()) {
        int enumConstantCount = 0;
        final PsiField[] fields = resolved.getFields();
        for (PsiField field : fields) {
          if (field instanceof PsiEnumConstant) enumConstantCount++;
        }

        if (sections.length == enumConstantCount) return true;
      }
    }

    return false;
  }
 private static boolean switchStatementsAreEquivalent(
     @NotNull GrSwitchStatement statement1, @NotNull GrSwitchStatement statement2) {
   final GrExpression switchExpression1 = statement1.getCondition();
   final GrExpression switchExpression2 = statement2.getCondition();
   if (!expressionsAreEquivalent(switchExpression1, switchExpression2)) {
     return false;
   }
   final GrCaseSection[] clauses1 = statement1.getCaseSections();
   final GrCaseSection[] clauses2 = statement2.getCaseSections();
   if (clauses1.length != clauses2.length) {
     return false;
   }
   for (int i = 0; i < clauses1.length; i++) {
     final GrCaseSection clause1 = clauses1[i];
     final GrCaseSection clause2 = clauses2[i];
     if (!caseClausesAreEquivalent(clause1, clause2)) {
       return false;
     }
   }
   return true;
 }
 public void visitSwitchStatement(GrSwitchStatement switchStatement) {
   final GrCondition condition = switchStatement.getCondition();
   if (condition != null) {
     condition.accept(this);
   }
   final InstructionImpl instruction = startNode(switchStatement);
   final GrCaseSection[] sections = switchStatement.getCaseSections();
   if (!containsAllCases(switchStatement)) {
     addPendingEdge(switchStatement, instruction);
   }
   for (GrCaseSection section : sections) {
     myHead = instruction;
     section.accept(this);
   }
   finishNode(instruction);
 }
    @Override
    public void visitSwitchStatement(GrSwitchStatement switchStatement) {
      final GrCaseSection[] sections = switchStatement.getCaseSections();
      List<PsiType> types = new ArrayList<PsiType>(sections.length);
      for (GrCaseSection section : sections) {
        final GrExpression value = section.getCaseLabel().getValue();
        final PsiType type = value != null ? value.getType() : null;
        if (type != null) types.add(type);
      }

      final PsiType upperBoundNullable =
          TypesUtil.getLeastUpperBoundNullable(types, switchStatement.getManager());
      if (upperBoundNullable == null) return;

      myResult = new TypeConstraint[] {SubtypeConstraint.create(upperBoundNullable)};
    }
  private static boolean isLastStatementInCaseSection(
      GrCaseSection caseSection, GrSwitchStatement switchStatement) {
    final GrCaseSection[] sections = switchStatement.getCaseSections();
    final int i = ArrayUtilRt.find(sections, caseSection);
    if (i == sections.length - 1) {
      return true;
    }

    for (int j = i + 1; j < sections.length; j++) {
      GrCaseSection section = sections[j];
      for (GrStatement statement : section.getStatements()) {
        if (!(statement instanceof GrBreakStatement)) {
          return false;
        }
      }
    }
    return true;
  }