2 * Copyright 2003-2007 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
.methodmetrics
;
18 import com
.intellij
.psi
.PsiMethod
;
19 import com
.siyeh
.InspectionGadgetsBundle
;
20 import com
.siyeh
.ig
.BaseInspection
;
21 import com
.siyeh
.ig
.BaseInspectionVisitor
;
22 import org
.jetbrains
.annotations
.NotNull
;
24 public class MethodWithMultipleLoopsInspection
extends BaseInspection
{
27 public String
getDisplayName() {
28 return InspectionGadgetsBundle
.message(
29 "method.with.multiple.loops.display.name");
33 public String
buildErrorString(Object
... infos
) {
34 final Integer negationCount
= (Integer
)infos
[0];
35 return InspectionGadgetsBundle
.message(
36 "method.with.multiple.loops.problem.descriptor", negationCount
);
39 public BaseInspectionVisitor
buildVisitor() {
40 return new MethodWithMultipleLoopsVisitor();
43 private static class MethodWithMultipleLoopsVisitor
44 extends BaseInspectionVisitor
{
46 @Override public void visitMethod(@NotNull PsiMethod method
) {
47 // note: no call to super
48 if (method
.getNameIdentifier() == null) {
51 final LoopCountVisitor visitor
= new LoopCountVisitor();
52 method
.accept(visitor
);
53 final int negationCount
= visitor
.getCount();
54 if (negationCount
<= 1) {
57 registerMethodError(method
, Integer
.valueOf(negationCount
));