ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / naming / MethodNameSameAsParentNameInspection.java
blob958bb20a375b6ac4018f0307fc284a583b3f95d0
1 /*
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 {
29 @NotNull
30 public String getDisplayName() {
31 return InspectionGadgetsBundle.message(
32 "method.name.same.as.parent.name.display.name");
35 @NotNull
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() {
46 return true;
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()) {
59 return;
61 if (method.getNameIdentifier() == null) {
62 return;
64 final PsiClass containingClass = method.getContainingClass();
65 if (containingClass == null) {
66 return;
68 final PsiClass parent = containingClass.getSuperClass();
69 if (parent == null) {
70 return;
72 final String parentName = parent.getName();
73 if (parentName == null) {
74 return;
76 final String methodName = method.getName();
77 if (!methodName.equals(parentName)) {
78 return;
80 registerMethodError(method);