update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / tree / java / ImportStatementBaseElement.java
blobf79eca57107e69752b0fde99b2bc2287f190ea35
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.impl.source.Constants;
21 import com.intellij.psi.impl.source.tree.ChildRole;
22 import com.intellij.psi.impl.source.tree.CompositeElement;
23 import com.intellij.psi.impl.source.tree.TreeUtil;
24 import com.intellij.psi.tree.ChildRoleBase;
25 import com.intellij.psi.tree.IElementType;
27 /**
28 * @author dsl
30 public class ImportStatementBaseElement extends CompositeElement implements Constants {
31 private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.ImportStatementBaseElement");
33 protected ImportStatementBaseElement(IElementType type) {
34 super(type);
37 public ASTNode findChildByRole(int role){
38 LOG.assertTrue(ChildRole.isUnique(role));
39 switch(role){
40 default:
41 return null;
43 case ChildRole.IMPORT_KEYWORD:
44 return getFirstChildNode();
46 case ChildRole.IMPORT_ON_DEMAND_DOT:
47 return findChildByType(DOT);
49 case ChildRole.IMPORT_ON_DEMAND_ASTERISK:
50 return findChildByType(ASTERISK);
52 case ChildRole.CLOSING_SEMICOLON:
53 return TreeUtil.findChildBackward(this, SEMICOLON);
57 public int getChildRole(ASTNode child) {
58 LOG.assertTrue(child.getTreeParent() == this);
59 IElementType i = child.getElementType();
60 if (i == IMPORT_KEYWORD) {
61 return ChildRole.IMPORT_KEYWORD;
63 else if (i == JAVA_CODE_REFERENCE) {
64 return ChildRole.IMPORT_REFERENCE;
66 else if (i == DOT) {
67 return ChildRole.IMPORT_ON_DEMAND_DOT;
69 else if (i == ASTERISK) {
70 return ChildRole.IMPORT_ON_DEMAND_ASTERISK;
72 else if (i == SEMICOLON) {
73 return ChildRole.CLOSING_SEMICOLON;
75 else {
76 return ChildRoleBase.NONE;