update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / light / LightPackageReference.java
blob3c7d906efde6a9883a1a764720347b3a8c76bd89
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.light;
18 import com.intellij.openapi.util.TextRange;
19 import com.intellij.openapi.fileTypes.StdFileTypes;
20 import com.intellij.psi.*;
21 import com.intellij.psi.infos.CandidateInfo;
22 import com.intellij.psi.scope.PsiScopeProcessor;
23 import com.intellij.util.IncorrectOperationException;
24 import org.jetbrains.annotations.NotNull;
26 public class LightPackageReference extends LightElement implements PsiJavaCodeReferenceElement {
27 private final String myPackageName;
28 private final PsiPackage myRefPackage;
30 public LightPackageReference(PsiManager manager, PsiPackage refPackage) {
31 super(manager, StdFileTypes.JAVA.getLanguage());
32 myPackageName = null;
33 myRefPackage = refPackage;
36 public LightPackageReference(PsiManager manager, String packageName) {
37 super(manager, StdFileTypes.JAVA.getLanguage());
38 myPackageName = packageName;
39 myRefPackage = null;
42 public PsiElement resolve(){
43 if (myPackageName != null){
44 return JavaPsiFacade.getInstance(myManager.getProject()).findPackage(myPackageName);
46 else {
47 return myRefPackage;
51 @NotNull
52 public JavaResolveResult advancedResolve(boolean incompleteCode){
53 return new CandidateInfo(resolve(), PsiSubstitutor.EMPTY);
56 @NotNull
57 public JavaResolveResult[] multiResolve(boolean incompleteCode){
58 final JavaResolveResult result = advancedResolve(incompleteCode);
59 if(result != JavaResolveResult.EMPTY) return new JavaResolveResult[]{result};
60 return JavaResolveResult.EMPTY_ARRAY;
63 public String getText(){
64 if (myPackageName != null){
65 return myPackageName;
67 else {
68 return myRefPackage.getQualifiedName();
72 public PsiReference getReference() {
73 return this;
76 public String getCanonicalText(){
77 return getText();
80 public PsiElement copy(){
81 if (myPackageName != null){
82 return new LightPackageReference(myManager, myPackageName);
84 else{
85 return new LightPackageReference(myManager, myRefPackage);
89 public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
90 //TODO?
91 throw new UnsupportedOperationException();
94 public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
95 //TODO?
96 throw new UnsupportedOperationException();
99 public void accept(@NotNull PsiElementVisitor visitor){
100 if (visitor instanceof JavaElementVisitor) {
101 ((JavaElementVisitor)visitor).visitReferenceElement(this);
103 else {
104 visitor.visitElement(this);
108 public String toString(){
109 return "PsiJavaCodeReferenceElement:" + getText();
112 public boolean isReferenceTo(PsiElement element) {
113 if (!(element instanceof PsiPackage)) return false;
114 return getManager().areElementsEquivalent(resolve(), element);
117 public Object[] getVariants() {
118 throw new RuntimeException("Variants are not available for light references");
121 public boolean isSoft(){
122 return false;
125 public void processVariants(PsiScopeProcessor processor){
126 throw new RuntimeException("Variants are not available for light references");
129 public PsiElement getReferenceNameElement() {
130 return null;
133 public PsiReferenceParameterList getParameterList() {
134 return null;
137 public String getQualifiedName() {
138 return getText();
141 public String getReferenceName() {
142 if (myPackageName != null){
143 return PsiNameHelper.getShortClassName(myPackageName);
145 else {
146 return myRefPackage.getName();
150 public TextRange getRangeInElement() {
151 return new TextRange(0, getTextLength());
154 public PsiElement getElement() {
155 return this;
158 public boolean isValid() {
159 return myRefPackage == null || myRefPackage.isValid();
162 @NotNull
163 public PsiType[] getTypeParameters() {
164 return PsiType.EMPTY_ARRAY;
167 public PsiElement getQualifier() {
168 return null;
171 public boolean isQualified() {
172 return false;