IDEA-61662 (Inspection "Class is a singleton" - false positive)
[idea/community.git] / plugins / InspectionGadgets / src / com / siyeh / ig / classlayout / SingletonInspection.java
1 /*
2  * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.siyeh.ig.classlayout;
17
18 import com.intellij.psi.PsiClass;
19 import com.siyeh.InspectionGadgetsBundle;
20 import com.siyeh.ig.BaseInspection;
21 import com.siyeh.ig.BaseInspectionVisitor;
22 import com.siyeh.ig.psiutils.SingletonUtil;
23 import org.jetbrains.annotations.NotNull;
24
25 public class SingletonInspection extends BaseInspection {
26
27     @Override
28     @NotNull
29     public String getDisplayName() {
30         return InspectionGadgetsBundle.message("singleton.display.name");
31     }
32
33     @Override
34     @NotNull
35     protected String buildErrorString(Object... infos) {
36         return InspectionGadgetsBundle.message("singleton.problem.descriptor");
37     }
38
39     @Override
40     public boolean runForWholeFile() {
41         return true;
42     }
43
44     @Override
45     public BaseInspectionVisitor buildVisitor() {
46         return new SingletonVisitor();
47     }
48
49     private static class SingletonVisitor extends BaseInspectionVisitor {
50
51         @Override public void visitClass(@NotNull PsiClass aClass) {
52             // no call to super, so that it doesn't drill down to inner classes
53             if (!SingletonUtil.isSingleton(aClass)) {
54                 return;
55             }
56             registerClassError(aClass);
57         }
58     }
59 }