@Override
 public void visitListOrMap(GrListOrMap listOrMap) {
   if (listOrMap.isMap()) return;
   final TypeConstraint[] constraints = calculateTypeConstraints(listOrMap);
   List<PsiType> result = new ArrayList<PsiType>(constraints.length);
   for (TypeConstraint constraint : constraints) {
     if (constraint instanceof SubtypeConstraint) {
       final PsiType type = constraint.getType();
       final PsiType iterable =
           com.intellij.psi.util.PsiUtil.extractIterableTypeParameter(type, true);
       if (iterable != null) {
         result.add(iterable);
       }
     }
   }
   if (result.size() == 0) {
     myResult = TypeConstraint.EMPTY_ARRAY;
   } else {
     myResult = new TypeConstraint[result.size()];
     for (int i = 0; i < result.size(); i++) {
       final PsiType type = result.get(i);
       if (type != null) {
         myResult[i] = SubtypeConstraint.create(type);
       }
     }
   }
 }
 @Nullable
 private InstructionImpl reduceAllNegationsIntoInstruction(
     GroovyPsiElement currentScope, List<? extends GotoInstruction> negations) {
   if (negations.size() > 1) {
     InstructionImpl instruction = addNode(new InstructionImpl(currentScope));
     for (GotoInstruction negation : negations) {
       addEdge(negation, instruction);
     }
     return instruction;
   } else if (negations.size() == 1) {
     GotoInstruction instruction = negations.get(0);
     myHead = instruction;
     return instruction;
   }
   return null;
 }
 public void visitArgumentList(GrArgumentList list) {
   List<TypeConstraint> constraints = new ArrayList<TypeConstraint>();
   for (GroovyResolveResult variant : ResolveUtil.getCallVariants(list)) {
     final Map<GrExpression, Pair<PsiParameter, PsiType>> map =
         GrClosureSignatureUtil.mapArgumentsToParameters(
             variant,
             list,
             true,
             true,
             list.getNamedArguments(),
             list.getExpressionArguments(),
             GrClosableBlock.EMPTY_ARRAY);
     addConstraintsFromMap(constraints, map);
   }
   if (!constraints.isEmpty()) {
     myResult = constraints.toArray(new TypeConstraint[constraints.size()]);
   }
 }
    public void visitMethodCallExpression(GrMethodCallExpression methodCall) {
      final GrExpression invokedExpression = methodCall.getInvokedExpression();
      if (myExpression.equals(invokedExpression)) {
        myResult =
            new TypeConstraint[] {
              SubtypeConstraint.create(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, methodCall)
            };
        return;
      }

      final GrClosableBlock[] closureArgs = methodCall.getClosureArguments();
      //noinspection SuspiciousMethodCalls
      final int closureIndex = Arrays.asList(closureArgs).indexOf(myExpression);
      if (closureIndex >= 0) {
        List<TypeConstraint> constraints = new ArrayList<TypeConstraint>();
        for (GroovyResolveResult variant : ResolveUtil.getCallVariants(myExpression)) {
          final GrArgumentList argumentList = methodCall.getArgumentList();
          final GrNamedArgument[] namedArgs =
              argumentList == null ? GrNamedArgument.EMPTY_ARRAY : argumentList.getNamedArguments();
          final GrExpression[] expressionArgs =
              argumentList == null
                  ? GrExpression.EMPTY_ARRAY
                  : argumentList.getExpressionArguments();
          try {
            final Map<GrExpression, Pair<PsiParameter, PsiType>> map =
                GrClosureSignatureUtil.mapArgumentsToParameters(
                    variant, methodCall, true, true, namedArgs, expressionArgs, closureArgs);
            addConstraintsFromMap(constraints, map);
          } catch (RuntimeException e) {
            LOG.error(
                "call: " + methodCall.getText() + "\nsymbol: " + variant.getElement().getText(), e);
          }
        }
        if (!constraints.isEmpty()) {
          myResult = constraints.toArray(new TypeConstraint[constraints.size()]);
        }
      }
    }
  public Instruction[] buildControlFlow(GroovyPsiElement scope) {
    myInstructions = new ArrayList<InstructionImpl>();
    myProcessingStack = new ArrayDeque<InstructionImpl>();
    myCaughtExceptionInfos = new ArrayDeque<ExceptionInfo>();
    myConditions = new ArrayDeque<ConditionInstruction>();

    myFinallyCount = 0;
    myPending = new ArrayList<Pair<InstructionImpl, GroovyPsiElement>>();
    myInstructionNumber = 0;

    myScope = scope;

    startNode(null);
    if (scope instanceof GrClosableBlock) {
      buildFlowForClosure((GrClosableBlock) scope);
    } else {
      scope.accept(this);
    }

    final InstructionImpl end = startNode(null);
    checkPending(end); // collect return edges

    return assertValidPsi(myInstructions.toArray(new Instruction[myInstructions.size()]));
  }