IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / psiutils / VariableUsedInArrayInitializerVisitor.java
blob3ada0b0aa68fb14f3b2f37243ad8007fe34ac0fd
1 /*
2 * Copyright 2003-2005 Dave Griffith
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 VariableUsedInArrayInitializerVisitor
22 extends JavaRecursiveElementVisitor{
24 @NotNull
25 private final PsiVariable variable;
26 private boolean passed = false;
28 public VariableUsedInArrayInitializerVisitor(@NotNull PsiVariable variable){
29 super();
30 this.variable = variable;
33 @Override public void visitElement(@NotNull PsiElement element){
34 if(!passed){
35 super.visitElement(element);
39 @Override public void visitArrayInitializerExpression(
40 PsiArrayInitializerExpression expression){
41 if(passed){
42 return;
44 super.visitArrayInitializerExpression(expression);
46 final PsiExpression[] args = expression.getInitializers();
47 for(final PsiExpression arg : args){
49 if(VariableAccessUtils.mayEvaluateToVariable(arg, variable)){
50 passed = true;
55 public boolean isPassed(){
56 return passed;