update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / completion / proc / VariablesProcessor.java
blob5fd16d1e427c3d9c83e639f115cf82f1685193a3
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 * Created by IntelliJ IDEA.
19 * User: igork
20 * Date: Nov 25, 2002
21 * Time: 1:44:25 PM
22 * To change this template use Options | File Templates.
24 package com.intellij.codeInsight.completion.proc;
26 import com.intellij.openapi.util.Key;
27 import com.intellij.psi.PsiElement;
28 import com.intellij.psi.PsiModifier;
29 import com.intellij.psi.PsiVariable;
30 import com.intellij.psi.ResolveState;
31 import com.intellij.psi.scope.BaseScopeProcessor;
32 import com.intellij.psi.scope.ElementClassHint;
33 import com.intellij.psi.scope.JavaScopeProcessorEvent;
35 import java.util.ArrayList;
36 import java.util.List;
39 /** Simple processor to get all visible variables
40 * @see com.intellij.psi.scope.util.PsiScopesUtil
42 public class VariablesProcessor
43 extends BaseScopeProcessor implements ElementClassHint{
44 private final String myPrefix;
45 private boolean myStaticScopeFlag = false;
46 private final boolean myStaticSensitiveFlag;
47 private final List<PsiVariable> myResultList;
49 /** Collecting _all_ variables in scope */
50 public VariablesProcessor(String _prefix, boolean staticSensitiveFlag){
51 this(_prefix, staticSensitiveFlag, new ArrayList<PsiVariable>());
54 /** Collecting _all_ variables in scope */
55 public VariablesProcessor(String _prefix, boolean staticSensitiveFlag, List<PsiVariable> lst){
56 myPrefix = _prefix;
57 myStaticSensitiveFlag = staticSensitiveFlag;
58 myResultList = lst;
61 public boolean shouldProcess(DeclaractionKind kind) {
62 return kind == DeclaractionKind.VARIABLE || kind == DeclaractionKind.FIELD || kind == DeclaractionKind.ENUM_CONST;
65 /** Always return true since we wanna get all vars in scope */
66 public boolean execute(PsiElement pe, ResolveState state){
67 if(pe instanceof PsiVariable){
68 final PsiVariable pvar = (PsiVariable)pe;
69 final String pvar_name = pvar.getName();
70 if(pvar_name.startsWith(myPrefix)){
71 if(!myStaticSensitiveFlag || (!myStaticScopeFlag || pvar.hasModifierProperty(PsiModifier.STATIC))){
72 myResultList.add(pvar);
77 return true;
80 public final void handleEvent(Event event, Object associated){
81 if(event == JavaScopeProcessorEvent.START_STATIC)
82 myStaticScopeFlag = true;
85 /** sometimes it is important to get results as array */
86 public PsiVariable[] getResultsAsArray(){
87 PsiVariable[] ret = new PsiVariable[myResultList.size()];
88 myResultList.toArray(ret);
89 return ret;
92 @Override
93 public <T> T getHint(Key<T> hintKey) {
94 if (hintKey == ElementClassHint.KEY) {
95 return (T)this;
98 return super.getHint(hintKey);