Inspections - pass onTheFly into ProblemDescriptors & use it to create LAZY refs...
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInspection / GlobalInspectionUtil.java
blobb5b0a077e8edc69214bee52485b9bbdc887aa076
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.
17 package com.intellij.codeInspection;
19 import com.intellij.codeInspection.reference.RefElement;
20 import com.intellij.openapi.util.TextRange;
21 import com.intellij.psi.PsiElement;
22 import com.intellij.psi.PsiFile;
24 /**
25 * User: Maxim.Mossienko
26 * Date: 16.09.2009
27 * Time: 20:35:06
29 public class GlobalInspectionUtil {
30 private static final String LOC_MARKER = " #loc";
32 static RefElement retrieveRefElement(PsiElement element, GlobalInspectionContext globalContext) {
33 PsiFile elementFile = element.getContainingFile();
34 RefElement refElement = globalContext.getRefManager().getReference(elementFile);
35 if (refElement == null) {
36 PsiElement context = elementFile.getContext();
37 if (context != null) refElement = globalContext.getRefManager().getReference(context.getContainingFile());
39 return refElement;
42 public static String createInspectionMessage(String message) {
43 return message + LOC_MARKER;
46 public static void createProblem(PsiElement elt, String message, ProblemHighlightType problemHighlightType, TextRange range,
47 InspectionManager manager, ProblemDescriptionsProcessor problemDescriptionsProcessor,
48 GlobalInspectionContext globalContext) {
49 ProblemDescriptor descriptor = manager.createProblemDescriptor(
50 elt,
51 range,
52 createInspectionMessage(message),
53 problemHighlightType, false);
54 problemDescriptionsProcessor.addProblemElement(
55 retrieveRefElement(elt, globalContext),
56 descriptor