2 * Copyright 2003-2010 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.classlayout;
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;
25 public class SingletonInspection extends BaseInspection {
29 public String getDisplayName() {
30 return InspectionGadgetsBundle.message("singleton.display.name");
35 protected String buildErrorString(Object... infos) {
36 return InspectionGadgetsBundle.message("singleton.problem.descriptor");
40 public boolean runForWholeFile() {
45 public BaseInspectionVisitor buildVisitor() {
46 return new SingletonVisitor();
49 private static class SingletonVisitor extends BaseInspectionVisitor {
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)) {
56 registerClassError(aClass);