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
.PsiAssertStatement
;
22 import com
.intellij
.psi
.PsiElementVisitor
;
23 import com
.intellij
.psi
.PsiExpression
;
24 import com
.intellij
.psi
.impl
.source
.Constants
;
25 import com
.intellij
.psi
.impl
.source
.tree
.ChildRole
;
26 import com
.intellij
.psi
.impl
.source
.tree
.CompositePsiElement
;
27 import com
.intellij
.psi
.tree
.IElementType
;
28 import com
.intellij
.psi
.tree
.ChildRoleBase
;
29 import org
.jetbrains
.annotations
.NotNull
;
31 public class PsiAssertStatementImpl
extends CompositePsiElement
implements PsiAssertStatement
, Constants
{
32 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.source.tree.java.PsiAssertStatementImpl");
34 public PsiAssertStatementImpl() {
35 super(ASSERT_STATEMENT
);
38 public PsiExpression
getAssertCondition() {
39 return (PsiExpression
)findChildByRoleAsPsiElement(ChildRole
.CONDITION
);
42 public PsiExpression
getAssertDescription() {
43 return (PsiExpression
)findChildByRoleAsPsiElement(ChildRole
.ASSERT_DESCRIPTION
);
46 public ASTNode
findChildByRole(int role
) {
47 LOG
.assertTrue(ChildRole
.isUnique(role
));
52 case ChildRole
.ASSERT_KEYWORD
:
53 return findChildByType(ASSERT_KEYWORD
);
55 case ChildRole
.CONDITION
:
56 return findChildByType(EXPRESSION_BIT_SET
);
59 return findChildByType(COLON
);
61 case ChildRole
.ASSERT_DESCRIPTION
:
63 ASTNode colon
= findChildByRole(ChildRole
.COLON
);
64 if (colon
== null) return null;
66 for(child
= colon
.getTreeNext(); child
!= null; child
= child
.getTreeNext()){
67 if (EXPRESSION_BIT_SET
.contains(child
.getElementType())) break;
72 case ChildRole
.CLOSING_SEMICOLON
:
73 return findChildByType(SEMICOLON
);
77 public int getChildRole(ASTNode child
) {
78 LOG
.assertTrue(child
.getTreeParent() == this);
79 IElementType i
= child
.getElementType();
80 if (i
== ASSERT_KEYWORD
) {
81 return ChildRole
.ASSERT_KEYWORD
;
83 else if (i
== COLON
) {
84 return ChildRole
.COLON
;
86 else if (i
== SEMICOLON
) {
87 return ChildRole
.CLOSING_SEMICOLON
;
90 if (EXPRESSION_BIT_SET
.contains(child
.getElementType())) {
91 int role
= getChildRole(child
, ChildRole
.CONDITION
);
92 if (role
!= ChildRoleBase
.NONE
) return role
;
93 return ChildRole
.ASSERT_DESCRIPTION
;
95 return ChildRoleBase
.NONE
;
99 public void accept(@NotNull PsiElementVisitor visitor
) {
100 if (visitor
instanceof JavaElementVisitor
) {
101 ((JavaElementVisitor
)visitor
).visitAssertStatement(this);
104 visitor
.visitElement(this);
108 public String
toString() {
109 return "PsiAssertStatement";