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 org
.jetbrains
.annotations
.NotNull
;
24 public class ParametersPerConstructorInspection
extends MethodMetricInspection
{
27 public String
getID() {
28 return "ConstructorWithTooManyParameters";
32 public String
getDisplayName() {
33 return InspectionGadgetsBundle
.message(
34 "parameters.per.constructor.display.name");
38 public String
buildErrorString(Object
... infos
) {
39 final Integer parameterCount
= (Integer
)infos
[0];
40 return InspectionGadgetsBundle
.message(
41 "parameters.per.constructor.problem.descriptor", parameterCount
);
44 protected int getDefaultLimit() {
48 protected String
getConfigurationLabel() {
49 return InspectionGadgetsBundle
.message("parameter.limit.option");
52 public BaseInspectionVisitor
buildVisitor() {
53 return new ParametersPerMethodVisitor();
56 private class ParametersPerMethodVisitor
extends BaseInspectionVisitor
{
58 @Override public void visitMethod(@NotNull PsiMethod method
) {
59 // note: no call to super
60 if (method
.getNameIdentifier() == null) {
63 if (!method
.isConstructor()) {
66 final PsiParameterList parameterList
= method
.getParameterList();
67 final int parametersCount
= parameterList
.getParametersCount();
68 if (parametersCount
<= getLimit()) {
71 registerMethodError(method
, Integer
.valueOf(parametersCount
));