2 * Copyright 2007-2008 Dave Griffith
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 org
.jetbrains
.plugins
.groovy
.codeInspection
;
18 import com
.intellij
.codeInspection
.InspectionManager
;
19 import com
.intellij
.codeInspection
.ProblemDescriptor
;
20 import com
.intellij
.codeInspection
.ProblemsHolder
;
21 import com
.intellij
.psi
.PsiElement
;
22 import com
.intellij
.psi
.PsiFile
;
23 import org
.jetbrains
.annotations
.NonNls
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.annotations
.Nullable
;
26 import org
.jetbrains
.plugins
.groovy
.lang
.psi
.GroovyFile
;
28 import java
.lang
.reflect
.Method
;
29 import java
.util
.List
;
32 public abstract class BaseInspection
extends GroovySuppressableInspectionTool
{
34 private final String m_shortName
= null;
35 protected static final String ASSIGNMENT_ISSUES
= "Assignment issues";
36 protected static final String CONFUSING_CODE_CONSTRUCTS
= "Potentially confusing code constructs";
37 protected static final String CONTROL_FLOW
= "Control Flow";
38 protected static final String PROBABLE_BUGS
= "Probable bugs";
39 protected static final String ERROR_HANDLING
= "Error handling";
40 protected static final String GPATH
= "GPath inspections";
41 protected static final String METHOD_METRICS
= "Method Metrics";
42 protected static final String THREADING_ISSUES
= "Threading issues";
43 protected static final String VALIDITY_ISSUES
= "Validity issues";
44 protected static final String ANNOTATIONS_ISSUES
= "Annotations verifying";
48 public String
[] getGroupPath() {
49 return new String
[]{"Groovy", getGroupDisplayName()};
53 public String
getShortName() {
54 if (m_shortName
== null) {
55 final Class
<?
extends BaseInspection
> aClass
= getClass();
56 @NonNls final String name
= aClass
.getName();
57 return name
.substring(name
.lastIndexOf((int) '.') + 1,
58 name
.length() - "Inspection".length());
63 @Nullable BaseInspectionVisitor
buildGroovyVisitor(@NotNull ProblemsHolder problemsHolder
, boolean onTheFly
) {
64 final BaseInspectionVisitor visitor
= buildVisitor();
65 visitor
.setProblemsHolder(problemsHolder
);
66 visitor
.setOnTheFly(onTheFly
);
67 visitor
.setInspection(this);
73 protected String
buildErrorString(Object
... args
) {
77 protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
82 protected GroovyFix
buildFix(PsiElement location
) {
87 protected GroovyFix
[] buildFixes(PsiElement location
) {
92 public ProblemDescriptor
[] checkFile(@NotNull PsiFile psiFile
, @NotNull InspectionManager inspectionManager
, boolean isOnTheFly
) {
93 if (!(psiFile
instanceof GroovyFile
)) {
94 return super.checkFile(psiFile
, inspectionManager
, isOnTheFly
);
96 final GroovyFile groovyFile
= (GroovyFile
) psiFile
;
98 final ProblemsHolder problemsHolder
= new ProblemsHolder(inspectionManager
, psiFile
, isOnTheFly
);
99 final BaseInspectionVisitor visitor
= buildGroovyVisitor(problemsHolder
, isOnTheFly
);
100 groovyFile
.accept(visitor
);
101 final List
<ProblemDescriptor
> problems
= problemsHolder
.getResults();
102 if (problems
== null) {
105 return problems
.toArray(new ProblemDescriptor
[problems
.size()]);
109 public boolean hasQuickFix() {
110 final Method
[] methods
= getClass().getDeclaredMethods();
111 for (final Method method
: methods
) {
112 @NonNls final String methodName
= method
.getName();
113 if ("buildFix".equals(methodName
)) {
120 protected abstract BaseInspectionVisitor
buildVisitor();