update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / scope / processor / FilterScopeProcessor.java
blobff6aedebdb473ca43134796284a312fb6904445e
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.psi.scope.processor;
18 import com.intellij.openapi.util.Key;
19 import com.intellij.psi.PsiElement;
20 import com.intellij.psi.PsiSubstitutor;
21 import com.intellij.psi.ResolveState;
22 import com.intellij.psi.filters.ElementFilter;
23 import com.intellij.psi.scope.BaseScopeProcessor;
24 import com.intellij.psi.scope.PsiScopeProcessor;
25 import com.intellij.util.SmartList;
27 import java.util.List;
29 /**
30 * Created by IntelliJ IDEA.
31 * User: ik
32 * Date: 13.02.2003
33 * Time: 15:21:27
34 * To change this template use Options | File Templates.
36 public class FilterScopeProcessor<T> extends BaseScopeProcessor{
37 protected final List<T> myResults;
38 private PsiElement myCurrentDeclarationHolder;
39 private final ElementFilter myFilter;
40 private final PsiScopeProcessor myProcessor;
42 public FilterScopeProcessor(ElementFilter filter, PsiScopeProcessor processor, List<T> container){
43 myFilter = filter;
44 myProcessor = processor;
45 myResults = container;
48 public FilterScopeProcessor(ElementFilter filter, List<T> container){
49 this(filter, null, container);
52 public FilterScopeProcessor(ElementFilter filter, PsiScopeProcessor proc){
53 this(filter, proc, new SmartList<T>());
56 public FilterScopeProcessor(ElementFilter filter){
57 this(filter, null, new SmartList<T>());
60 public void handleEvent(Event event, Object associated){
61 if(myProcessor != null){
62 myProcessor.handleEvent(event, associated);
64 if(event == Event.SET_DECLARATION_HOLDER && associated instanceof PsiElement){
65 myCurrentDeclarationHolder = (PsiElement)associated;
69 public boolean execute(PsiElement element, ResolveState state){
70 if (myFilter.isAcceptable(element, myCurrentDeclarationHolder)){
71 if(myProcessor != null){
72 return myProcessor.execute(element, state);
74 add(element, state.get(PsiSubstitutor.KEY));
76 return true;
79 protected void add(PsiElement element, PsiSubstitutor substitutor){
80 myResults.add((T)element);
83 @Override
84 public <T> T getHint(Key<T> hintKey) {
85 if (myProcessor != null) {
86 return myProcessor.getHint(hintKey);
88 return null;
91 public List<T> getResults(){
92 return myResults;