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
.BaseInspectionVisitor
;
21 import org
.jetbrains
.annotations
.NotNull
;
23 public class NestingDepthInspection
extends MethodMetricInspection
{
26 public String
getID() {
27 return "OverlyNestedMethod";
31 public String
getDisplayName() {
32 return InspectionGadgetsBundle
.message("nesting.depth.display.name");
35 protected int getDefaultLimit() {
39 protected String
getConfigurationLabel() {
40 return InspectionGadgetsBundle
.message("nesting.depth.limit.option");
44 public String
buildErrorString(Object
... infos
) {
45 final Integer nestingDepth
= (Integer
)infos
[0];
46 return InspectionGadgetsBundle
.message(
47 "nesting.depth.problem.descriptor", nestingDepth
);
50 public BaseInspectionVisitor
buildVisitor() {
51 return new NestingDepthMethodVisitor();
54 private class NestingDepthMethodVisitor
extends BaseInspectionVisitor
{
56 @Override public void visitMethod(@NotNull PsiMethod method
) {
57 // note: no call to super
58 if (method
.getNameIdentifier() == null) {
61 final NestingDepthVisitor visitor
= new NestingDepthVisitor();
62 method
.accept(visitor
);
63 final int count
= visitor
.getMaximumDepth();
64 if (count
<= getLimit()) {
67 registerMethodError(method
, Integer
.valueOf(count
));