Ejemplo n.º 1
0
  @NotNull
  protected DfaInstructionState[] acceptInstruction(
      @NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState) {
    Instruction instruction = instructionState.getInstruction();
    PsiElement closure = DfaUtil.getClosureInside(instruction);
    if (closure instanceof PsiClass) {
      registerNestedClosures(instructionState, (PsiClass) closure);
    } else if (closure instanceof PsiLambdaExpression) {
      registerNestedClosures(instructionState, (PsiLambdaExpression) closure);
    }

    return instruction.accept(this, instructionState.getMemoryState(), visitor);
  }
  private DfaInstructionState[] acceptInstruction(
      InstructionVisitor visitor, DfaInstructionState instructionState) {
    Instruction instruction = instructionState.getInstruction();
    if (instruction instanceof MethodCallInstruction) {
      PsiCallExpression anchor = ((MethodCallInstruction) instruction).getCallExpression();
      if (anchor instanceof PsiNewExpression) {
        PsiAnonymousClass anonymousClass = ((PsiNewExpression) anchor).getAnonymousClass();
        if (anonymousClass != null) {
          registerNestedClosures(instructionState, anonymousClass);
        }
      }
    } else if (instruction instanceof EmptyInstruction) {
      PsiElement anchor = ((EmptyInstruction) instruction).getAnchor();
      if (anchor instanceof PsiDeclarationStatement) {
        for (PsiElement element : ((PsiDeclarationStatement) anchor).getDeclaredElements()) {
          if (element instanceof PsiClass) {
            registerNestedClosures(instructionState, (PsiClass) element);
          }
        }
      }
    }

    return instruction.accept(this, instructionState.getMemoryState(), visitor);
  }