2 * Copyright 2006-2009 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
.junit
;
18 import com
.intellij
.psi
.*;
19 import com
.siyeh
.InspectionGadgetsBundle
;
20 import com
.siyeh
.ig
.BaseInspection
;
21 import com
.siyeh
.ig
.BaseInspectionVisitor
;
22 import com
.siyeh
.ig
.psiutils
.TestUtils
;
23 import org
.jetbrains
.annotations
.NotNull
;
25 public class BeforeOrAfterIsPublicVoidNoArgInspection
extends BaseInspection
{
28 public String
getID() {
29 return "BeforeOrAfterWithIncorrectSignature";
34 public String
getDisplayName() {
35 return InspectionGadgetsBundle
.message(
36 "before.or.after.is.public.void.no.arg.display.name");
41 protected String
buildErrorString(Object
... infos
) {
42 return InspectionGadgetsBundle
.message(
43 "before.or.after.is.public.void.no.arg.problem.descriptor");
47 public BaseInspectionVisitor
buildVisitor() {
48 return new BeforeOrAfterIsPublicVoidNoArgVisitor();
51 private static class BeforeOrAfterIsPublicVoidNoArgVisitor
52 extends BaseInspectionVisitor
{
54 @Override public void visitMethod(@NotNull PsiMethod method
) {
55 //note: no call to super;
56 if (!TestUtils
.isJUnit4BeforeOrAfterMethod(method
)) {
59 final PsiType returnType
= method
.getReturnType();
60 if (returnType
== null) {
63 final PsiClass targetClass
= method
.getContainingClass();
64 if (targetClass
== null) {
67 final PsiParameterList parameterList
= method
.getParameterList();
68 if (parameterList
.getParametersCount() != 0) {
69 registerMethodError(method
);
70 } else if (!returnType
.equals(PsiType
.VOID
)) {
71 registerMethodError(method
);
72 } else if (!method
.hasModifierProperty(PsiModifier
.PUBLIC
)) {
73 registerMethodError(method
);
74 } else if (method
.hasModifierProperty(PsiModifier
.STATIC
)) {
75 registerMethodError(method
);