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
.tree
.IElementType
;
24 import com
.intellij
.psi
.tree
.ChildRoleBase
;
25 import org
.jetbrains
.annotations
.NotNull
;
26 import org
.jetbrains
.annotations
.Nullable
;
28 public class PsiTypeCastExpressionImpl
extends ExpressionPsiElement
implements PsiTypeCastExpression
, Constants
{
29 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.source.tree.java.PsiTypeCastExpressionImpl");
31 public PsiTypeCastExpressionImpl() {
32 super(TYPE_CAST_EXPRESSION
);
35 public PsiTypeElement
getCastType() {
36 return (PsiTypeElement
)findChildByRoleAsPsiElement(ChildRole
.TYPE
);
39 public PsiExpression
getOperand() {
40 return (PsiExpression
)findChildByRoleAsPsiElement(ChildRole
.OPERAND
);
43 @Nullable public PsiType
getType() {
44 final PsiTypeElement castType
= getCastType();
45 if (castType
== null) return null;
46 return castType
.getType();
49 public ASTNode
findChildByRole(int role
) {
50 LOG
.assertTrue(ChildRole
.isUnique(role
));
55 case ChildRole
.LPARENTH
:
56 return findChildByType(LPARENTH
);
59 return findChildByType(TYPE
);
61 case ChildRole
.RPARENTH
:
62 return findChildByType(RPARENTH
);
64 case ChildRole
.OPERAND
:
65 return findChildByType(EXPRESSION_BIT_SET
);
69 public int getChildRole(ASTNode child
) {
70 assert child
.getTreeParent() == this: "child:"+child
+"; child.getTreeParent():"+child
.getTreeParent();
71 IElementType i
= child
.getElementType();
73 return ChildRole
.LPARENTH
;
75 else if (i
== RPARENTH
) {
76 return ChildRole
.RPARENTH
;
79 return ChildRole
.TYPE
;
82 if (EXPRESSION_BIT_SET
.contains(child
.getElementType())) {
83 return ChildRole
.OPERAND
;
85 return ChildRoleBase
.NONE
;
89 public void accept(@NotNull PsiElementVisitor visitor
) {
90 if (visitor
instanceof JavaElementVisitor
) {
91 ((JavaElementVisitor
)visitor
).visitTypeCastExpression(this);
94 visitor
.visitElement(this);
98 public String
toString() {
99 return "PsiTypeCastExpression:" + getText();