update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInspection / miscGenerics / GenericsInspectionToolBase.java
blob1af783871799ec3b7c2c8c9b23d09807348395f3
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
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.intellij.codeInspection.miscGenerics;
18 import com.intellij.codeInspection.InspectionManager;
19 import com.intellij.codeInspection.ProblemDescriptor;
20 import com.intellij.codeInspection.ex.BaseLocalInspectionTool;
21 import com.intellij.psi.*;
22 import org.jetbrains.annotations.NotNull;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
28 /**
29 * @author ven
31 public abstract class GenericsInspectionToolBase extends BaseLocalInspectionTool {
32 public ProblemDescriptor[] checkClass(@NotNull PsiClass aClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
33 final PsiClassInitializer[] initializers = aClass.getInitializers();
34 if (initializers.length == 0) return null;
35 List<ProblemDescriptor> descriptors = new ArrayList<ProblemDescriptor>();
36 for (PsiClassInitializer initializer : initializers) {
37 final ProblemDescriptor[] localDescriptions = getDescriptions(initializer, manager);
38 if (localDescriptions != null) {
39 descriptors.addAll(Arrays.asList(localDescriptions));
42 if (descriptors.isEmpty()) return null;
43 return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
46 public ProblemDescriptor[] checkField(@NotNull PsiField field, @NotNull InspectionManager manager, boolean isOnTheFly) {
47 final PsiExpression initializer = field.getInitializer();
48 if (initializer != null) {
49 return getDescriptions(initializer, manager);
51 return null;
54 public ProblemDescriptor[] checkMethod(@NotNull PsiMethod psiMethod, @NotNull InspectionManager manager, boolean isOnTheFly) {
55 final PsiCodeBlock body = psiMethod.getBody();
56 if (body != null) {
57 return getDescriptions(body, manager);
59 return null;
62 public abstract ProblemDescriptor[] getDescriptions(PsiElement place, InspectionManager manager);