update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / codeInsight / daemon / impl / analysis / XmlHighlightVisitorBasedInspection.java
blob2a753b9e42c985a6a3a50d8a977905a669bd7a92
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 myHolder.setWritable(true);
77 super.visitFile(file);
80 @Override
81 public void visitElement(PsiElement element) {
82 highlightVisitor.visit(element, myHolder);
83 super.visitElement(element);
85 });
88 @Nls
89 @NotNull
90 @Override
91 public String getGroupDisplayName() {
92 return "General";
95 @Nls
96 @NotNull
97 @Override
98 public String getDisplayName() {
99 return "Xml Highlighting";
102 @NotNull
103 @Override
104 public String getShortName() {
105 return "XmlHighlighting";