run highlight visitors for injected fragments
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInsight / daemon / impl / analysis / HighlightInfoHolder.java
bloba227ab81edb1c0f56df2e597d947bfe590df6991
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 /**
18 * @author Alexey
20 package com.intellij.codeInsight.daemon.impl.analysis;
22 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
23 import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter;
24 import com.intellij.lang.annotation.HighlightSeverity;
25 import com.intellij.openapi.diagnostic.Logger;
26 import com.intellij.psi.PsiFile;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.List;
34 public class HighlightInfoHolder {
35 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder");
37 private final PsiFile myContextFile;
38 private final HighlightInfoFilter[] myFilters;
39 private int myErrorCount;
40 private int myWarningCount;
41 private int myInfoCount;
42 private final List<HighlightInfo> myInfos = new ArrayList<HighlightInfo>(5);
44 public HighlightInfoHolder(@NotNull PsiFile contextFile, @NotNull HighlightInfoFilter... filters) {
45 myContextFile = contextFile;
46 myFilters = filters;
49 public boolean add(@Nullable HighlightInfo info) {
50 if (info == null || !accepted(info)) return false;
52 HighlightSeverity severity = info.getSeverity();
53 if (severity == HighlightSeverity.ERROR) {
54 myErrorCount++;
56 else if (severity == HighlightSeverity.WARNING) {
57 myWarningCount++;
59 else if (severity == HighlightSeverity.INFORMATION) {
60 myInfoCount++;
63 return myInfos.add(info);
66 private boolean accepted(HighlightInfo info) {
67 for (HighlightInfoFilter filter : myFilters) {
68 if (!filter.accept(info, myContextFile)) return false;
70 return true;
73 public void clear() {
74 myErrorCount = 0;
75 myWarningCount = 0;
76 myInfoCount = 0;
77 myInfos.clear();
80 public boolean hasErrorResults() {
81 return myErrorCount != 0;
84 public boolean hasInfoResults() {
85 return myInfoCount != 0;
88 public boolean hasWarningResults() {
89 return myWarningCount != 0;
92 public int getErrorCount() {
93 return myErrorCount;
96 public boolean addAll(Collection<? extends HighlightInfo> highlightInfos) {
97 if (highlightInfos == null) return false;
98 LOG.assertTrue(highlightInfos != this);
99 boolean added = false;
100 for (final HighlightInfo highlightInfo : highlightInfos) {
101 added |= add(highlightInfo);
103 return added;
106 public int size() {
107 return myInfos.size();
110 public HighlightInfo get(final int i) {
111 return myInfos.get(i);