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.execution.filters;
18 import com.intellij.openapi.editor.colors.CodeInsightColors;
19 import com.intellij.openapi.editor.colors.EditorColorsManager;
20 import com.intellij.openapi.editor.markup.TextAttributes;
21 import com.intellij.util.ui.UIUtil;
22 import org.jetbrains.annotations.NotNull;
23 import org.jetbrains.annotations.Nullable;
25 import java.util.Collections;
26 import java.util.List;
32 public interface Filter {
34 Filter[] EMPTY_ARRAY = new Filter[0];
36 class Result extends ResultItem {
38 private static final TextAttributes INACTIVE_HYPERLINK_ATTRIBUTES;
40 TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES);
41 if (attributes != null) {
42 attributes = attributes.clone();
43 attributes.setForegroundColor(UIUtil.getInactiveTextColor());
44 attributes.setEffectColor(UIUtil.getInactiveTextColor());
46 INACTIVE_HYPERLINK_ATTRIBUTES = attributes;
49 protected NextAction myNextAction = NextAction.EXIT;
50 protected final List<ResultItem> myResultItems;
52 public Result(final int highlightStartOffset, final int highlightEndOffset, @Nullable final HyperlinkInfo hyperlinkInfo) {
53 this(highlightStartOffset, highlightEndOffset, hyperlinkInfo, null);
56 public Result(final int highlightStartOffset,
57 final int highlightEndOffset,
58 @Nullable final HyperlinkInfo hyperlinkInfo,
59 @Nullable final TextAttributes highlightAttributes) {
60 super(highlightStartOffset, highlightEndOffset, hyperlinkInfo, highlightAttributes);
64 public Result(final int highlightStartOffset,
65 final int highlightEndOffset,
66 @Nullable final HyperlinkInfo hyperlinkInfo,
67 boolean inactiveHyperlink) {
68 super(highlightStartOffset, highlightEndOffset, hyperlinkInfo, inactiveHyperlink ? INACTIVE_HYPERLINK_ATTRIBUTES : null);
72 public Result(@NotNull List<ResultItem> resultItems) {
73 super(-1, -1, null, null);
74 myResultItems = resultItems;
77 public List<ResultItem> getResultItems() {
78 List<ResultItem> resultItems = myResultItems;
79 if (resultItems == null) {
80 resultItems = Collections.singletonList((ResultItem)this);
86 * @deprecated This method will be removed. Result may be constructed using ResultItems, in that case this method will return incorrect value. Use {@link #getResultItems()} instead.
90 public int getHighlightStartOffset() {
91 return super.getHighlightStartOffset();
95 * @deprecated This method will be removed. Result may be constructed using ResultItems, in that case this method will return incorrect value. Use {@link #getResultItems()} instead.
99 public int getHighlightEndOffset() {
100 return super.getHighlightEndOffset();
104 * @deprecated This method will be removed. Result may be constructed using ResultItems, in that case this method will return incorrect value. Use {@link #getResultItems()} instead.
109 public TextAttributes getHighlightAttributes() {
110 return super.getHighlightAttributes();
114 * @deprecated This method will be removed. Result may be constructed using ResultItems, in that case this method will return incorrect value. Use {@link #getResultItems()} or {@link #getFirstHyperlinkInfo()} instead.
119 public HyperlinkInfo getHyperlinkInfo() {
120 return super.getHyperlinkInfo();
124 public HyperlinkInfo getFirstHyperlinkInfo() {
125 HyperlinkInfo info = super.getHyperlinkInfo();
126 if (info == null && myResultItems != null) {
127 //noinspection ForLoopReplaceableByForEach
128 for (int i = 0; i < myResultItems.size(); i++) {
129 ResultItem resultItem = myResultItems.get(i);
130 if (resultItem.getHyperlinkInfo() != null) {
131 return resultItem.getHyperlinkInfo();
138 public NextAction getNextAction() {
142 public void setNextAction(NextAction nextAction) {
143 myNextAction = nextAction;
148 EXIT, CONTINUE_FILTERING,
153 * @deprecated use getter, the visibility of this field will be decreased.
156 public final int highlightStartOffset;
158 * @deprecated use getter, the visibility of this field will be decreased.
161 public final int highlightEndOffset;
163 * @deprecated use getter, the visibility of this field will be decreased.
165 @Deprecated @Nullable
166 public final TextAttributes highlightAttributes;
168 * @deprecated use getter, the visibility of this field will be decreased.
170 @Deprecated @Nullable
171 public final HyperlinkInfo hyperlinkInfo;
173 @SuppressWarnings("deprecation")
174 public ResultItem(final int highlightStartOffset, final int highlightEndOffset, @Nullable final HyperlinkInfo hyperlinkInfo) {
175 this(highlightStartOffset, highlightEndOffset, hyperlinkInfo, null);
178 @SuppressWarnings("deprecation")
179 public ResultItem(final int highlightStartOffset,
180 final int highlightEndOffset,
181 @Nullable final HyperlinkInfo hyperlinkInfo,
182 @Nullable final TextAttributes highlightAttributes) {
183 this.highlightStartOffset = highlightStartOffset;
184 this.highlightEndOffset = highlightEndOffset;
185 this.hyperlinkInfo = hyperlinkInfo;
186 this.highlightAttributes = highlightAttributes;
189 public int getHighlightStartOffset() {
190 //noinspection deprecation
191 return highlightStartOffset;
194 public int getHighlightEndOffset() {
195 //noinspection deprecation
196 return highlightEndOffset;
200 public TextAttributes getHighlightAttributes() {
201 //noinspection deprecation
202 return highlightAttributes;
206 public HyperlinkInfo getHyperlinkInfo() {
207 //noinspection deprecation
208 return hyperlinkInfo;
213 * Filters line by creating an instance of {@link Result}.
215 * @param line The line to be filtered. Note that the line must contain a line
216 * separator at the end.
217 * @param entireLength The length of the entire text including the line passed for filtration.
218 * @return <tt>null</tt>, if there was no match, otherwise, an instance of {@link Result}
221 Result applyFilter(String line, int entireLength);