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
.naming
;
18 import com
.intellij
.psi
.PsiClass
;
19 import com
.intellij
.psi
.PsiMethod
;
20 import com
.siyeh
.InspectionGadgetsBundle
;
21 import com
.siyeh
.ig
.BaseInspection
;
22 import com
.siyeh
.ig
.BaseInspectionVisitor
;
23 import com
.siyeh
.ig
.InspectionGadgetsFix
;
24 import com
.siyeh
.ig
.fixes
.RenameFix
;
25 import org
.jetbrains
.annotations
.NotNull
;
27 public class MethodNameSameAsParentNameInspection
extends BaseInspection
{
30 public String
getDisplayName() {
31 return InspectionGadgetsBundle
.message(
32 "method.name.same.as.parent.name.display.name");
36 protected String
buildErrorString(Object
... infos
) {
37 return InspectionGadgetsBundle
.message(
38 "method.name.same.as.parent.name.problem.descriptor");
41 protected InspectionGadgetsFix
buildFix(Object
... infos
) {
42 return new RenameFix();
45 protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
49 public BaseInspectionVisitor
buildVisitor() {
50 return new MethodNameSameAsParentClassNameVisitor();
53 private static class MethodNameSameAsParentClassNameVisitor
54 extends BaseInspectionVisitor
{
56 @Override public void visitMethod(@NotNull PsiMethod method
) {
57 // no call to super, so it doesn't drill down into inner classes
58 if (method
.isConstructor()) {
61 if (method
.getNameIdentifier() == null) {
64 final PsiClass containingClass
= method
.getContainingClass();
65 if (containingClass
== null) {
68 final PsiClass parent
= containingClass
.getSuperClass();
72 final String parentName
= parent
.getName();
73 if (parentName
== null) {
76 final String methodName
= method
.getName();
77 if (!methodName
.equals(parentName
)) {
80 registerMethodError(method
);