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
;
30 * Created by IntelliJ IDEA.
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
){
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
));
79 protected void add(PsiElement element
, PsiSubstitutor substitutor
){
80 myResults
.add((T
)element
);
84 public <T
> T
getHint(Key
<T
> hintKey
) {
85 if (myProcessor
!= null) {
86 return myProcessor
.getHint(hintKey
);
91 public List
<T
> getResults(){