update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / tree / java / PsiReturnStatementImpl.java
blob55a7359916b478ffc87d8349aefec94617d96912
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.JavaElementVisitor;
21 import com.intellij.psi.PsiElementVisitor;
22 import com.intellij.psi.PsiExpression;
23 import com.intellij.psi.PsiReturnStatement;
24 import com.intellij.psi.impl.source.tree.ChildRole;
25 import com.intellij.psi.impl.source.tree.CompositePsiElement;
26 import com.intellij.psi.impl.source.tree.TreeUtil;
27 import com.intellij.psi.impl.source.Constants;
28 import com.intellij.psi.tree.IElementType;
29 import com.intellij.psi.tree.ChildRoleBase;
30 import org.jetbrains.annotations.NotNull;
32 public class PsiReturnStatementImpl extends CompositePsiElement implements PsiReturnStatement, Constants {
33 private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiReturnStatementImpl");
35 public PsiReturnStatementImpl() {
36 super(RETURN_STATEMENT);
39 public PsiExpression getReturnValue() {
40 return (PsiExpression)findChildByRoleAsPsiElement(ChildRole.RETURN_VALUE);
43 public ASTNode findChildByRole(int role) {
44 LOG.assertTrue(ChildRole.isUnique(role));
45 switch(role){
46 default:
47 return null;
49 case ChildRole.RETURN_KEYWORD:
50 return findChildByType(RETURN_KEYWORD);
52 case ChildRole.RETURN_VALUE:
53 return findChildByType(EXPRESSION_BIT_SET);
55 case ChildRole.CLOSING_SEMICOLON:
56 return TreeUtil.findChildBackward(this, SEMICOLON);
60 public int getChildRole(ASTNode child) {
61 LOG.assertTrue(child.getTreeParent() == this);
62 IElementType i = child.getElementType();
63 if (i == RETURN_KEYWORD) {
64 return ChildRole.RETURN_KEYWORD;
66 else if (i == SEMICOLON) {
67 return ChildRole.CLOSING_SEMICOLON;
69 else {
70 if (EXPRESSION_BIT_SET.contains(child.getElementType())) {
71 return ChildRole.RETURN_VALUE;
73 else {
74 return ChildRoleBase.NONE;
79 public void accept(@NotNull PsiElementVisitor visitor) {
80 if (visitor instanceof JavaElementVisitor) {
81 ((JavaElementVisitor)visitor).visitReturnStatement(this);
83 else {
84 visitor.visitElement(this);
88 public String toString() {
89 return "PsiReturnStatement";