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 LightMemberReference
extends LightElement
implements PsiJavaCodeReferenceElement
{
27 private final PsiMember myRefMember
;
28 private final PsiSubstitutor mySubstitutor
;
30 private LightReferenceParameterList myParameterList
;
32 public LightMemberReference(PsiManager manager
, PsiMember refClass
, PsiSubstitutor substitutor
) {
33 super(manager
, StdFileTypes
.JAVA
.getLanguage());
34 myRefMember
= refClass
;
36 mySubstitutor
= substitutor
;
39 public PsiElement
resolve() {
44 public JavaResolveResult
advancedResolve(boolean incompleteCode
){
45 final PsiElement resolved
= resolve();
46 PsiSubstitutor substitutor
= mySubstitutor
;
47 if (substitutor
== null) {
48 substitutor
= PsiSubstitutor
.EMPTY
;
50 return new CandidateInfo(resolved
, substitutor
);
54 public JavaResolveResult
[] multiResolve(boolean incompleteCode
){
55 final JavaResolveResult result
= advancedResolve(incompleteCode
);
56 if(result
!= JavaResolveResult
.EMPTY
) return new JavaResolveResult
[]{result
};
57 return JavaResolveResult
.EMPTY_ARRAY
;
60 public void processVariants(PsiScopeProcessor processor
){
61 throw new RuntimeException("Variants are not available for light references");
64 public PsiElement
getReferenceNameElement() {
68 public PsiReferenceParameterList
getParameterList() {
69 if (myParameterList
== null) {
70 myParameterList
= new LightReferenceParameterList(myManager
, PsiTypeElement
.EMPTY_ARRAY
);
72 return myParameterList
;
75 public String
getQualifiedName() {
76 final PsiClass containingClass
= myRefMember
.getContainingClass();
77 if (containingClass
!= null) {
78 final String qualifiedName
= containingClass
.getQualifiedName();
79 if (qualifiedName
!= null) {
80 return qualifiedName
+ '.' + myRefMember
.getName();
83 return myRefMember
.getName();
86 public String
getReferenceName() {
87 return getQualifiedName();
90 public String
getText() {
91 return myRefMember
.getName() + getParameterList().getText();
94 public PsiReference
getReference() {
98 public String
getCanonicalText() {
99 String name
= getQualifiedName();
100 if (name
== null) return null;
101 PsiType
[] types
= getTypeParameters();
102 if (types
.length
== 0) return name
;
104 StringBuffer buf
= new StringBuffer();
107 for (int i
= 0; i
< types
.length
; i
++) {
108 if (i
> 0) buf
.append(',');
109 buf
.append(types
[i
].getCanonicalText());
113 return buf
.toString();
116 public PsiElement
copy() {
117 return new LightMemberReference(myManager
, myRefMember
, mySubstitutor
);
120 public PsiElement
handleElementRename(String newElementName
) throws IncorrectOperationException
{
122 throw new IncorrectOperationException();
125 public PsiElement
bindToElement(@NotNull PsiElement element
) throws IncorrectOperationException
{
127 throw new IncorrectOperationException();
130 public void accept(@NotNull PsiElementVisitor visitor
) {
131 if (visitor
instanceof JavaElementVisitor
) {
132 ((JavaElementVisitor
)visitor
).visitReferenceElement(this);
135 visitor
.visitElement(this);
139 public String
toString() {
140 return "LightClassReference:" + myRefMember
.getName();
143 public boolean isReferenceTo(PsiElement element
) {
144 return element
instanceof PsiClass
&& element
.getManager().areElementsEquivalent(resolve(), element
);
147 public Object
[] getVariants() {
148 throw new RuntimeException("Variants are not available for light references");
151 public boolean isSoft(){
155 public TextRange
getRangeInElement() {
156 return new TextRange(0, getTextLength());
159 public PsiElement
getElement() {
163 public boolean isValid() {
164 PsiReferenceParameterList parameterList
= getParameterList();
165 if (parameterList
!= null && !parameterList
.isValid()) return false;
166 return myRefMember
== null || myRefMember
.isValid();
170 public PsiType
[] getTypeParameters() {
171 PsiReferenceParameterList parameterList
= getParameterList();
172 return parameterList
== null ? PsiType
.EMPTY_ARRAY
: parameterList
.getTypeArguments();
175 public PsiElement
getQualifier() {
179 public boolean isQualified() {