JSIndexedPropertyAccessExpressionImpl.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.JSTokenTypes; 
21   import com.intellij.lang.javascript.psi.JSElementVisitor; 
22   import com.intellij.lang.javascript.psi.JSExpression; 
23   import com.intellij.lang.javascript.psi.JSIndexedPropertyAccessExpression; 
24   import com.intellij.lang.javascript.psi.JSReferenceExpression; 
25   import com.intellij.psi.PsiElementVisitor; 
26   import com.intellij.psi.tree.IElementType; 
27    
28   /** 
29    * Created by IntelliJ IDEA. 
30    * User: max 
31    * Date: Jan 30, 2005 
32    * Time: 11:59:36 PM 
33    * To change this template use File | Settings | File Templates. 
34    */ 
35   public class JSIndexedPropertyAccessExpressionImpl extends JSElementImpl implements JSIndexedPropertyAccessExpression { 
36     public JSIndexedPropertyAccessExpressionImpl(final ASTNode node) { 
37       super(node); 
38     } 
39    
40     public JSReferenceExpression getQualifier() { 
41       ASTNode child = getNode().getFirstChildNode(); 
42       while (child != null) { 
43         final IElementType type = child.getElementType(); 
44         if (type == JSTokenTypes.LBRACKET) return null; 
45         if (JSElementTypes.EXPRESSIONS.isInSet(type)) return (JSReferenceExpression)child.getPsi(); 
46         child = child.getTreeNext(); 
47       } 
48       return null; 
49     } 
50    
51     public JSExpression getIndexExpression() { 
52       ASTNode child = getNode().getFirstChildNode(); 
53       boolean bracketPassed = false; 
54       while (child != null) { 
55         final IElementType type = child.getElementType(); 
56         if (type == JSTokenTypes.LBRACKET) { 
57           bracketPassed = true; 
58         } 
59         if (bracketPassed && JSElementTypes.EXPRESSIONS.isInSet(type)) return (JSReferenceExpression)child.getPsi(); 
60         child = child.getTreeNext(); 
61       } 
62       return null; 
63     } 
64    
65     public void accept(PsiElementVisitor visitor) { 
66       if (visitor instanceof JSElementVisitor) { 
67         ((JSElementVisitor)visitor).visitJSIndexedPropertyAccessExpression(this); 
68       } 
69       else { 
70         visitor.visitElement(this); 
71       } 
72     } 
73    
74     public String toString() { 
75       return "JSIndexedPropertyAccessExpression"; 
76     } 
77   } 
78