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 RecursionVisitor
extends JavaRecursiveElementVisitor
{
23 private boolean recursive
= false;
24 private final PsiMethod method
;
25 private final String methodName
;
27 public RecursionVisitor(@NotNull PsiMethod method
){
30 methodName
= method
.getName();
33 @Override public void visitElement(@NotNull PsiElement element
){
35 super.visitElement(element
);
39 @Override public void visitMethodCallExpression(
40 @NotNull PsiMethodCallExpression call
){
44 super.visitMethodCallExpression(call
);
45 final PsiReferenceExpression methodExpression
=
46 call
.getMethodExpression();
47 final String calledMethodName
= methodExpression
.getReferenceName();
48 if(calledMethodName
== null){
51 if(!calledMethodName
.equals(methodName
)){
54 final PsiMethod calledMethod
= call
.resolveMethod();
55 if(!method
.equals(calledMethod
)){
58 if(method
.hasModifierProperty(PsiModifier
.STATIC
) ||
59 method
.hasModifierProperty(PsiModifier
.PRIVATE
)){
63 final PsiExpression qualifier
= methodExpression
.getQualifierExpression();
64 if(qualifier
== null || qualifier
instanceof PsiThisExpression
){
69 public boolean isRecursive(){