JSLabeledStatementImpl.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.JSLabeledStatement; 
23   import com.intellij.lang.javascript.psi.JSStatement; 
24   import com.intellij.psi.PsiElement; 
25   import com.intellij.psi.PsiElementVisitor; 
26    
27   /** 
28    * Created by IntelliJ IDEA. 
29    * User: max 
30    * Date: Jan 30, 2005 
31    * Time: 9:20:04 PM 
32    * To change this template use File | Settings | File Templates. 
33    */ 
34   public class JSLabeledStatementImpl extends JSElementImpl implements JSLabeledStatement { 
35     public JSLabeledStatementImpl(final ASTNode node) { 
36       super(node); 
37     } 
38    
39     public String getLabel() { 
40       return getNode().findChildByType(JSTokenTypes.IDENTIFIER).getText(); 
41     } 
42    
43     public PsiElement getLabelIdentifier() { 
44       return getNode().findChildByType(JSTokenTypes.IDENTIFIER).getPsi(); 
45     } 
46    
47     public JSStatement getStatement() { 
48       final ASTNode[] statement = getNode().getChildren(JSElementTypes.STATEMENTS); 
49       return (JSStatement)(statement.length == 1 ? statement[0].getPsi() : null); 
50     } 
51    
52     public JSStatement unlabel() { 
53       throw new UnsupportedOperationException("TODO: implement"); 
54     } 
55    
56     public JSLabeledStatement setLabel(String label) { 
57       throw new UnsupportedOperationException("TODO: implement"); 
58     } 
59    
60     public void accept(PsiElementVisitor visitor) { 
61       if (visitor instanceof JSElementVisitor) { 
62         ((JSElementVisitor)visitor).visitJSLabeledStatement(this); 
63       } 
64       else { 
65         visitor.visitElement(this); 
66       } 
67     } 
68    
69     public String toString() { 
70       return "JSLabeledStatement"; 
71     } 
72   } 
73