/*
 * Copyright 2003-2015 Dave Griffith, Bas Leijdekkers
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.siyeh.ig.psiutils;

import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;

class VariableAssignedFromVisitor extends JavaRecursiveElementWalkingVisitor {

  private boolean assignedFrom = false;

  @NotNull
  private final PsiVariable variable;

  public VariableAssignedFromVisitor(@NotNull PsiVariable variable) {
    super();
    this.variable = variable;
  }

  @Override
  public void visitElement(@NotNull PsiElement element) {
    if (!assignedFrom) {
      super.visitElement(element);
    }
  }

  @Override
  public void visitAssignmentExpression(
    @NotNull PsiAssignmentExpression assignment) {
    if (assignedFrom) {
      return;
    }
    super.visitAssignmentExpression(assignment);
    final PsiExpression arg = assignment.getRExpression();
    if (VariableAccessUtils.mayEvaluateToVariable(arg, variable)) {
      assignedFrom = true;
    }
  }

  @Override
  public void visitDeclarationStatement(
    @NotNull PsiDeclarationStatement statement) {
    if (assignedFrom) {
      return;
    }
    super.visitDeclarationStatement(statement);
    final PsiElement[] declaredElements = statement.getDeclaredElements();
    for (PsiElement declaredElement : declaredElements) {
      if (declaredElement instanceof PsiVariable) {
        final PsiVariable declaredVariable =
          (PsiVariable)declaredElement;
        final PsiExpression initializer =
          declaredVariable.getInitializer();
        if (initializer != null &&
            VariableAccessUtils.mayEvaluateToVariable(initializer,
                                                      variable)) {
          assignedFrom = true;
          return;
        }
      }
    }
  }

  @Override
  public void visitVariable(@NotNull PsiVariable var) {
    if (assignedFrom) {
      return;
    }
    super.visitVariable(var);
    final PsiExpression arg = var.getInitializer();
    if (VariableAccessUtils.mayEvaluateToVariable(arg, variable)) {
      assignedFrom = true;
    }
  }

  public boolean isAssignedFrom() {
    return assignedFrom;
  }
}
@@ -21,9 +21,9 @@
 -201
-5
+6
  Dav
@@ -1192,21 +1192,16 @@
 ression(
-%0A    
 @NotNull
@@ -1501,807 +1501,8 @@
  %7D%0A%0A
-  @Override%0A  public void visitDeclarationStatement(%0A    @NotNull PsiDeclarationStatement statement) %7B%0A    if (assignedFrom) %7B%0A      return;%0A    %7D%0A    super.visitDeclarationStatement(statement);%0A    final PsiElement%5B%5D declaredElements = statement.getDeclaredElements();%0A    for (PsiElement declaredElement : declaredElements) %7B%0A      if (declaredElement instanceof PsiVariable) %7B%0A        final PsiVariable declaredVariable =%0A          (PsiVariable)declaredElement;%0A        final PsiExpression initializer =%0A          declaredVariable.getInitializer();%0A        if (initializer != null &&%0A            VariableAccessUtils.mayEvaluateToVariable(initializer,%0A                                                      variable)) %7B%0A          assignedFrom = true;%0A          return;%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A%0A
   @O
@@ -1663,19 +1663,27 @@
 ression 
-arg
+initializer
  = var.g
@@ -1741,35 +1741,43 @@
 luateToVariable(
-arg
+initializer
 , variable)) %7B%0A 

remove unnecessary method