update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / tree / java / PsiSwitchStatementImpl.java
blobf93e869ca9711d60f58d39b39235182687b55a69
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.
16 package com.intellij.psi.impl.source.tree.java;
18 import com.intellij.lang.ASTNode;
19 import com.intellij.openapi.diagnostic.Logger;
20 import com.intellij.psi.*;
21 import com.intellij.psi.impl.source.Constants;
22 import com.intellij.psi.impl.source.tree.ChildRole;
23 import com.intellij.psi.impl.source.tree.CompositePsiElement;
24 import com.intellij.psi.tree.IElementType;
25 import com.intellij.psi.tree.ChildRoleBase;
26 import org.jetbrains.annotations.NotNull;
28 public class PsiSwitchStatementImpl extends CompositePsiElement implements PsiSwitchStatement, Constants {
29 private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiSwitchStatementImpl");
31 public PsiSwitchStatementImpl() {
32 super(SWITCH_STATEMENT);
35 public PsiExpression getExpression() {
36 return (PsiExpression)findChildByRoleAsPsiElement(ChildRole.SWITCH_EXPRESSION);
39 public PsiCodeBlock getBody() {
40 return (PsiCodeBlock)findChildByRoleAsPsiElement(ChildRole.SWITCH_BODY);
43 public PsiJavaToken getLParenth() {
44 return (PsiJavaToken)findChildByRoleAsPsiElement(ChildRole.LPARENTH);
47 public PsiJavaToken getRParenth() {
48 return (PsiJavaToken)findChildByRoleAsPsiElement(ChildRole.RPARENTH);
51 public ASTNode findChildByRole(int role) {
52 LOG.assertTrue(ChildRole.isUnique(role));
53 switch(role){
54 default:
55 return null;
57 case ChildRole.SWITCH_KEYWORD:
58 return findChildByType(SWITCH_KEYWORD);
60 case ChildRole.LPARENTH:
61 return findChildByType(LPARENTH);
63 case ChildRole.SWITCH_EXPRESSION:
64 return findChildByType(EXPRESSION_BIT_SET);
66 case ChildRole.RPARENTH:
67 return findChildByType(RPARENTH);
69 case ChildRole.SWITCH_BODY:
70 return findChildByType(CODE_BLOCK);
74 public int getChildRole(ASTNode child) {
75 LOG.assertTrue(child.getTreeParent() == this);
76 IElementType i = child.getElementType();
77 if (i == SWITCH_KEYWORD) {
78 return ChildRole.SWITCH_KEYWORD;
80 else if (i == LPARENTH) {
81 return ChildRole.LPARENTH;
83 else if (i == RPARENTH) {
84 return ChildRole.RPARENTH;
86 else {
87 if (EXPRESSION_BIT_SET.contains(child.getElementType())) {
88 return ChildRole.SWITCH_EXPRESSION;
90 else if (child.getElementType() == CODE_BLOCK) {
91 return ChildRole.SWITCH_BODY;
93 else {
94 return ChildRoleBase.NONE;
99 public void accept(@NotNull PsiElementVisitor visitor) {
100 if (visitor instanceof JavaElementVisitor) {
101 ((JavaElementVisitor)visitor).visitSwitchStatement(this);
103 else {
104 visitor.visitElement(this);
108 public String toString() {
109 return "PsiSwitchStatement";