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());
33 myRefPackage
= refPackage
;
36 public LightPackageReference(PsiManager manager
, String packageName
) {
37 super(manager
, StdFileTypes
.JAVA
.getLanguage());
38 myPackageName
= packageName
;
42 public PsiElement
resolve(){
43 if (myPackageName
!= null){
44 return JavaPsiFacade
.getInstance(myManager
.getProject()).findPackage(myPackageName
);
52 public JavaResolveResult
advancedResolve(boolean incompleteCode
){
53 return new CandidateInfo(resolve(), PsiSubstitutor
.EMPTY
);
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){
68 return myRefPackage
.getQualifiedName();
72 public PsiReference
getReference() {
76 public String
getCanonicalText(){
80 public PsiElement
copy(){
81 if (myPackageName
!= null){
82 return new LightPackageReference(myManager
, myPackageName
);
85 return new LightPackageReference(myManager
, myRefPackage
);
89 public PsiElement
handleElementRename(String newElementName
) throws IncorrectOperationException
{
91 throw new UnsupportedOperationException();
94 public PsiElement
bindToElement(@NotNull PsiElement element
) throws IncorrectOperationException
{
96 throw new UnsupportedOperationException();
99 public void accept(@NotNull PsiElementVisitor visitor
){
100 if (visitor
instanceof JavaElementVisitor
) {
101 ((JavaElementVisitor
)visitor
).visitReferenceElement(this);
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(){
125 public void processVariants(PsiScopeProcessor processor
){
126 throw new RuntimeException("Variants are not available for light references");
129 public PsiElement
getReferenceNameElement() {
133 public PsiReferenceParameterList
getParameterList() {
137 public String
getQualifiedName() {
141 public String
getReferenceName() {
142 if (myPackageName
!= null){
143 return PsiNameHelper
.getShortClassName(myPackageName
);
146 return myRefPackage
.getName();
150 public TextRange
getRangeInElement() {
151 return new TextRange(0, getTextLength());
154 public PsiElement
getElement() {
158 public boolean isValid() {
159 return myRefPackage
== null || myRefPackage
.isValid();
163 public PsiType
[] getTypeParameters() {
164 return PsiType
.EMPTY_ARRAY
;
167 public PsiElement
getQualifier() {
171 public boolean isQualified() {