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
.intellij
.psi
.PsiParameterList
;
20 import com
.siyeh
.InspectionGadgetsBundle
;
21 import com
.siyeh
.ig
.BaseInspectionVisitor
;
22 import com
.siyeh
.ig
.psiutils
.LibraryUtil
;
23 import org
.jetbrains
.annotations
.NotNull
;
25 public class ParametersPerMethodInspection
extends MethodMetricInspection
{
28 public String
getID() {
29 return "MethodWithTooManyParameters";
33 public String
getDisplayName() {
34 return InspectionGadgetsBundle
.message(
35 "parameters.per.method.display.name");
39 public String
buildErrorString(Object
... infos
) {
40 final Integer parameterCount
= (Integer
)infos
[0];
41 return InspectionGadgetsBundle
.message(
42 "parameters.per.method.problem.descriptor", parameterCount
);
45 protected int getDefaultLimit() {
49 protected String
getConfigurationLabel() {
50 return InspectionGadgetsBundle
.message("parameter.limit.option");
53 public BaseInspectionVisitor
buildVisitor() {
54 return new ParametersPerMethodVisitor();
57 private class ParametersPerMethodVisitor
extends BaseInspectionVisitor
{
59 @Override public void visitMethod(@NotNull PsiMethod method
) {
60 // note: no call to super
61 if (method
.getNameIdentifier() == null) {
64 if (method
.isConstructor()) {
67 final PsiParameterList parameterList
= method
.getParameterList();
68 final int parametersCount
= parameterList
.getParametersCount();
69 if (parametersCount
<= getLimit()) {
72 if (LibraryUtil
.isOverrideOfLibraryMethod(method
)) {
75 registerMethodError(method
, Integer
.valueOf(parametersCount
));