JSVarStatementImpl.java

1    /* 
2     * Copyright 2000-2005 JetBrains s.r.o. 
3     * 
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 
7     * 
8     * http://www.apache.org/licenses/LICENSE-2.0 
9     * 
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. 
15    */ 
16   package com.intellij.lang.javascript.psi.impl; 
17    
18   import com.intellij.lang.ASTNode; 
19   import com.intellij.lang.javascript.JSElementTypes; 
20   import com.intellij.lang.javascript.psi.JSElementVisitor; 
21   import com.intellij.lang.javascript.psi.JSExpression; 
22   import com.intellij.lang.javascript.psi.JSVarStatement; 
23   import com.intellij.lang.javascript.psi.JSVariable; 
24   import com.intellij.psi.PsiElement; 
25   import com.intellij.psi.PsiElementVisitor; 
26   import com.intellij.psi.PsiSubstitutor; 
27   import com.intellij.psi.scope.PsiScopeProcessor; 
28   import com.intellij.psi.tree.TokenSet; 
29    
30   /** 
31    * Created by IntelliJ IDEA. 
32    * User: max 
33    * Date: Jan 30, 2005 
34    * Time: 9:35:47 PM 
35    * To change this template use File | Settings | File Templates. 
36    */ 
37   public class JSVarStatementImpl extends JSElementImpl implements JSVarStatement { 
38     private static final TokenSet VARIABLE_FILTER = TokenSet.create(JSElementTypes.VARIABLE); 
39    
40     public JSVarStatementImpl(final ASTNode node) { 
41       super(node); 
42     } 
43    
44     public JSVariable[] getVariables() { 
45       final ASTNode[] nodes = getNode().getChildren(VARIABLE_FILTER); 
46       JSVariable[] vars = new JSVariable[nodes.length]; 
47       for (int i = 0; i < vars.length; i++) { 
48         vars[i] = (JSVariable)nodes[i].getPsi(); 
49       } 
50       return vars; 
51     } 
52    
53     public void declareVariable(String name, JSExpression initializer) { 
54       throw new UnsupportedOperationException("TODO: implement"); 
55     } 
56    
57     public String toString() { 
58       return "JSVarStatement"; 
59     } 
60    
61     public void accept(PsiElementVisitor visitor) { 
62       if (visitor instanceof JSElementVisitor) { 
63         ((JSElementVisitor)visitor).visitJSVarStatement(this); 
64       } 
65       else { 
66         visitor.visitElement(this); 
67       } 
68     } 
69    
70     public boolean processDeclarations(PsiScopeProcessor processor, 
71                                        PsiSubstitutor substitutor, 
72                                        PsiElement lastParent, 
73                                        PsiElement place) { 
74       final JSVariable[] vars = getVariables(); 
75       for (JSVariable var : vars) { 
76         if (!processor.execute(var, substitutor)) return false; 
77       } 
78    
79       return true; 
80     } 
81   } 
82