2 * Copyright 2003-2008 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
.PsiClassInitializer
;
19 import com
.intellij
.psi
.PsiModifier
;
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
.ChangeModifierFix
;
25 import org
.jetbrains
.annotations
.NotNull
;
26 import org
.jetbrains
.annotations
.Nullable
;
28 public class ClassInitializerInspection
extends BaseInspection
{
31 public String
getID() {
32 return "NonStaticInitializer";
36 public String
getDisplayName() {
37 return InspectionGadgetsBundle
.message(
38 "class.initializer.display.name");
42 protected String
buildErrorString(Object
... infos
) {
43 return InspectionGadgetsBundle
.message(
44 "class.initializer.problem.descriptor");
49 protected InspectionGadgetsFix
buildFix(Object
... infos
) {
50 return new ChangeModifierFix(PsiModifier
.STATIC
);
53 public BaseInspectionVisitor
buildVisitor() {
54 return new ClassInitializerVisitor();
57 private static class ClassInitializerVisitor
extends BaseInspectionVisitor
{
60 public void visitClassInitializer(PsiClassInitializer initializer
) {
61 super.visitClassInitializer(initializer
);
62 if (initializer
.hasModifierProperty(PsiModifier
.STATIC
)) {
65 registerClassInitializerError(initializer
);