update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / tree / java / EnumConstantElement.java
blob12aff32fdfe660431769563ff45658c3a4feefc9
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.JavaTokenType;
21 import com.intellij.psi.impl.PsiImplUtil;
22 import com.intellij.psi.impl.source.Constants;
23 import com.intellij.psi.impl.source.tree.*;
24 import com.intellij.psi.tree.ChildRoleBase;
25 import com.intellij.psi.tree.IElementType;
27 /**
28 * @author dsl
30 public class EnumConstantElement extends CompositeElement implements Constants {
31 private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.EnumConstantElement");
32 public EnumConstantElement() {
33 super(ENUM_CONSTANT);
36 public int getTextOffset() {
37 return findChildByRole(ChildRole.NAME).getStartOffset();
40 public ASTNode findChildByRole(int role){
41 LOG.assertTrue(ChildRole.isUnique(role));
42 switch(role){
43 default:
44 return null;
46 case ChildRole.DOC_COMMENT:
47 return PsiImplUtil.findDocComment(this);
49 case ChildRole.NAME:
50 return findChildByType(JavaTokenType.IDENTIFIER);
52 case ChildRole.ARGUMENT_LIST:
53 return findChildByType(EXPRESSION_LIST);
55 case ChildRole.ANONYMOUS_CLASS:
56 return findChildByType(ENUM_CONSTANT_INITIALIZER);
58 case ChildRole.MODIFIER_LIST:
59 return findChildByType(JavaElementType.MODIFIER_LIST);
63 public int getChildRole(ASTNode child) {
64 LOG.assertTrue(child.getTreeParent() == this);
65 IElementType i = child.getElementType();
66 if (i == JavaTokenType.DOC_COMMENT || i == JavaDocElementType.DOC_COMMENT) {
67 return getChildRole(child, ChildRole.DOC_COMMENT);
69 else if (i == JavaTokenType.C_STYLE_COMMENT || i == JavaTokenType.END_OF_LINE_COMMENT) {
71 return ChildRoleBase.NONE;
74 else if (i == JavaTokenType.IDENTIFIER) {
75 return getChildRole(child, ChildRole.NAME);
77 else if (i == ENUM_CONSTANT_INITIALIZER) {
78 return ChildRole.ANONYMOUS_CLASS;
80 else if (i == EXPRESSION_LIST) {
81 return ChildRole.ARGUMENT_LIST;
83 else if (i == MODIFIER_LIST) {
84 return ChildRole.MODIFIER_LIST;
86 else {
87 return ChildRoleBase.NONE;