IDEADEV-31824 (Incorrect "manual array copy" warning)
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / psiutils / VariablePassedAsArgumentVisitor.java
blob27e28f497cdb4a953d14c4c125663058efeaa1dd
1 /*
2 * Copyright 2003-2006 Dave Griffith, Bas Leijdekkers
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.siyeh.ig.psiutils;
18 import com.intellij.psi.*;
19 import org.jetbrains.annotations.NotNull;
21 public class VariablePassedAsArgumentVisitor extends JavaRecursiveElementVisitor{
23 @NotNull
24 private final PsiVariable variable;
25 private boolean passed = false;
27 public VariablePassedAsArgumentVisitor(@NotNull PsiVariable variable){
28 super();
29 this.variable = variable;
32 @Override public void visitElement(@NotNull PsiElement element){
33 if(!passed){
34 super.visitElement(element);
38 @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call){
39 if(passed){
40 return;
42 super.visitMethodCallExpression(call);
43 final PsiExpressionList argumentList = call.getArgumentList();
44 final PsiExpression[] arguments = argumentList.getExpressions();
45 for(final PsiExpression argument : arguments){
46 if(VariableAccessUtils.mayEvaluateToVariable(argument, variable)){
47 passed = true;
52 @Override public void visitNewExpression(@NotNull PsiNewExpression newExpression){
53 if(passed){
54 return;
56 super.visitNewExpression(newExpression);
57 final PsiExpressionList argumentList = newExpression.getArgumentList();
58 if(argumentList == null){
59 return;
61 final PsiExpression[] arguments = argumentList.getExpressions();
62 for(final PsiExpression argument : arguments){
63 if(VariableAccessUtils.mayEvaluateToVariable(argument, variable)){
64 passed = true;
69 public boolean isPassed(){
70 return passed;