run highlight visitors for injected fragments
[fedora-idea.git] / xml / impl / src / com / intellij / codeInsight / daemon / impl / analysis / XmlHighlightVisitorBasedInspection.java
blob6bba6ffb293dff3e5e59c814d010326bcbf3c1ac
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.codeInsight.daemon.impl.analysis;
18 import com.intellij.analysis.AnalysisScope;
19 import com.intellij.codeHighlighting.HighlightDisplayLevel;
20 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
21 import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter;
22 import com.intellij.codeInspection.*;
23 import com.intellij.openapi.util.TextRange;
24 import com.intellij.psi.PsiElement;
25 import com.intellij.psi.PsiFile;
26 import com.intellij.psi.XmlRecursiveElementVisitor;
27 import org.jetbrains.annotations.Nls;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
31 /**
32 * @author yole
34 public class XmlHighlightVisitorBasedInspection extends GlobalInspectionTool {
35 @Override
36 public boolean isGraphNeeded() {
37 return false;
40 @NotNull
41 @Override
42 public HighlightDisplayLevel getDefaultLevel() {
43 return HighlightDisplayLevel.ERROR;
46 @Override
47 public void runInspection(AnalysisScope scope,
48 final InspectionManager manager,
49 final GlobalInspectionContext globalContext,
50 final ProblemDescriptionsProcessor problemDescriptionsProcessor) {
51 scope.accept(new XmlRecursiveElementVisitor() {
52 final XmlHighlightVisitor highlightVisitor = new XmlHighlightVisitor();
54 HighlightInfoHolder myHolder;
56 @Override
57 public void visitFile(final PsiFile file) {
58 myHolder = new HighlightInfoHolder(file, HighlightInfoFilter.EMPTY_ARRAY) {
59 @Override
60 public boolean add(@Nullable HighlightInfo info) {
61 if (info != null) {
62 ProblemHighlightType problemHighlightType = HighlightInfo.convertType(info.type);
63 GlobalInspectionUtil.createProblem(
64 file,
65 info.description,
66 problemHighlightType,
67 new TextRange(info.startOffset, info.endOffset),
68 manager,
69 problemDescriptionsProcessor,
70 globalContext
73 return true;
76 super.visitFile(file);
79 @Override
80 public void visitElement(PsiElement element) {
81 highlightVisitor.visit(element, myHolder);
82 super.visitElement(element);
84 });
87 @Nls
88 @NotNull
89 @Override
90 public String getGroupDisplayName() {
91 return "General";
94 @Nls
95 @NotNull
96 @Override
97 public String getDisplayName() {
98 return "Xml Highlighting";
101 @NotNull
102 @Override
103 public String getShortName() {
104 return "XmlHighlighting";