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.
18 * Created by IntelliJ IDEA.
23 package com
.intellij
.psi
.impl
.source
.tree
.java
;
25 import com
.intellij
.openapi
.diagnostic
.Logger
;
26 import com
.intellij
.psi
.JavaTokenType
;
27 import com
.intellij
.psi
.tree
.IElementType
;
28 import com
.intellij
.psi
.tree
.ChildRoleBase
;
29 import com
.intellij
.psi
.impl
.source
.tree
.*;
30 import com
.intellij
.lang
.ASTNode
;
32 public abstract class AnonymousClassElementBase
extends ClassElement
{
33 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.source.tree.java.AnonymousClassElement");
35 public AnonymousClassElementBase(IElementType type
) {
39 public ASTNode
findChildByRole(int role
) {
40 LOG
.assertTrue(ChildRole
.isUnique(role
));
45 case ChildRole
.BASE_CLASS_REFERENCE
:
46 return getFirstChildNode().getElementType() == JavaElementType
.JAVA_CODE_REFERENCE ?
getFirstChildNode() : null;
48 case ChildRole
.ARGUMENT_LIST
:
49 return findChildByType(JavaElementType
.EXPRESSION_LIST
);
51 case ChildRole
.LBRACE
:
52 return findChildByType(JavaTokenType
.LBRACE
);
54 case ChildRole
.RBRACE
:
55 return TreeUtil
.findChildBackward(this, JavaTokenType
.RBRACE
);
59 public int getChildRole(ASTNode child
) {
60 LOG
.assertTrue(child
.getTreeParent() == this);
61 IElementType i
= child
.getElementType();
62 if (i
== JavaElementType
.JAVA_CODE_REFERENCE
) {
63 return getChildRole(child
, ChildRole
.BASE_CLASS_REFERENCE
);
65 else if (i
== JavaElementType
.EXPRESSION_LIST
) {
66 return ChildRole
.ARGUMENT_LIST
;
68 else if (i
== JavaElementType
.FIELD
) {
69 return ChildRole
.FIELD
;
71 else if (i
== JavaElementType
.METHOD
) {
72 return ChildRole
.METHOD
;
74 else if (i
== JavaElementType
.CLASS_INITIALIZER
) {
75 return ChildRole
.CLASS_INITIALIZER
;
77 else if (i
== JavaElementType
.CLASS
) {
78 return ChildRole
.CLASS
;
80 else if (i
== JavaTokenType
.LBRACE
) {
81 return getChildRole(child
, ChildRole
.LBRACE
);
83 else if (i
== JavaTokenType
.RBRACE
) {
84 return getChildRole(child
, ChildRole
.RBRACE
);
87 return ChildRoleBase
.NONE
;