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
.cloneable
;
18 import com
.intellij
.psi
.PsiClass
;
19 import com
.intellij
.psi
.PsiMethod
;
20 import com
.intellij
.psi
.PsiModifier
;
21 import com
.siyeh
.InspectionGadgetsBundle
;
22 import com
.siyeh
.ig
.BaseInspection
;
23 import com
.siyeh
.ig
.BaseInspectionVisitor
;
24 import com
.siyeh
.ig
.psiutils
.CloneUtils
;
25 import org
.jetbrains
.annotations
.NotNull
;
27 public class CloneCallsSuperCloneInspection
extends BaseInspection
{
30 public String
getID() {
31 return "CloneDoesntCallSuperClone";
35 public String
getDisplayName() {
36 return InspectionGadgetsBundle
.message(
37 "clone.doesnt.call.super.clone.display.name");
41 public String
buildErrorString(Object
... infos
) {
42 return InspectionGadgetsBundle
.message(
43 "clone.doesnt.call.super.clone.problem.descriptor");
46 public boolean isEnabledByDefault() {
50 public BaseInspectionVisitor
buildVisitor() {
51 return new NoExplicitCloneCallsVisitor();
54 private static class NoExplicitCloneCallsVisitor
55 extends BaseInspectionVisitor
{
57 @Override public void visitMethod(@NotNull PsiMethod method
) {
58 //note: no call to super;
59 if (!CloneUtils
.isClone(method
)) {
62 if(method
.hasModifierProperty(PsiModifier
.ABSTRACT
) ||
63 method
.hasModifierProperty(PsiModifier
.NATIVE
)) {
66 final PsiClass containingClass
= method
.getContainingClass();
67 if(containingClass
== null) {
70 if (containingClass
.isInterface() ||
71 containingClass
.isAnnotationType()) {
74 if (CloneUtils
.onlyThrowsCloneNotSupportedException(method
)) {
75 if (method
.hasModifierProperty(PsiModifier
.FINAL
) ||
76 containingClass
.hasModifierProperty(
81 final CallToSuperCloneVisitor visitor
=
82 new CallToSuperCloneVisitor();
83 method
.accept(visitor
);
84 if (visitor
.isCallToSuperCloneFound()) {
87 registerMethodError(method
);