update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / PsiImportStaticStatementImpl.java
blob86bb921a94e1dc031b855db7b5e8bb7b176666ee
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;
18 import com.intellij.lang.ASTNode;
19 import com.intellij.psi.*;
20 import com.intellij.psi.impl.java.stubs.PsiImportStatementStub;
21 import com.intellij.util.ArrayFactory;
22 import org.jetbrains.annotations.NotNull;
23 import org.jetbrains.annotations.Nullable;
25 public class PsiImportStaticStatementImpl extends PsiImportStatementBaseImpl implements PsiImportStaticStatement {
26 public static final PsiImportStaticStatementImpl[] EMPTY_ARRAY = new PsiImportStaticStatementImpl[0];
27 public static final ArrayFactory<PsiImportStaticStatementImpl> ARRAY_FACTORY = new ArrayFactory<PsiImportStaticStatementImpl>() {
28 public PsiImportStaticStatementImpl[] create(final int count) {
29 return count == 0 ? EMPTY_ARRAY : new PsiImportStaticStatementImpl[count];
33 public PsiImportStaticStatementImpl(final PsiImportStatementStub stub) {
34 super(stub);
37 public PsiImportStaticStatementImpl(final ASTNode node) {
38 super(node);
41 public PsiClass resolveTargetClass() {
42 final PsiJavaCodeReferenceElement classReference = getClassReference();
43 if (classReference == null) return null;
44 final PsiElement result = classReference.resolve();
45 if (result instanceof PsiClass) {
46 return (PsiClass) result;
48 else {
49 return null;
53 public String getReferenceName() {
54 if (isOnDemand()) return null;
55 final PsiImportStaticReferenceElement memberReference = getMemberReference();
56 if (memberReference != null) {
57 return memberReference.getReferenceName();
59 else {
60 return null;
64 @Nullable
65 private PsiImportStaticReferenceElement getMemberReference() {
66 if (isOnDemand()) {
67 return null;
69 else {
70 return (PsiImportStaticReferenceElement) getImportReference();
74 @Nullable
75 private PsiJavaCodeReferenceElement getClassReference() {
76 if (isOnDemand()) {
77 return getImportReference();
79 else {
80 final PsiImportStaticReferenceElement memberReference = getMemberReference();
81 if (memberReference != null) {
82 return memberReference.getClassReference();
84 else {
85 return null;
90 public void accept(@NotNull PsiElementVisitor visitor){
91 if (visitor instanceof JavaElementVisitor) {
92 ((JavaElementVisitor)visitor).visitImportStaticStatement(this);
94 else {
95 visitor.visitElement(this);
99 public String toString(){
100 return "PsiImportStaticStatement";