update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / compiled / ClsTypeParameterReferenceImpl.java
blobe1c42bb22e73ee51ac47ff226ea8600cac9a5183
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.compiled;
18 import com.intellij.openapi.diagnostic.Logger;
19 import com.intellij.openapi.util.TextRange;
20 import com.intellij.psi.*;
21 import com.intellij.psi.impl.source.tree.ElementType;
22 import com.intellij.psi.impl.source.tree.TreeElement;
23 import com.intellij.psi.infos.CandidateInfo;
24 import com.intellij.psi.scope.PsiScopeProcessor;
25 import com.intellij.util.IncorrectOperationException;
26 import org.jetbrains.annotations.NotNull;
28 /**
29 * @author max
31 public class ClsTypeParameterReferenceImpl extends ClsElementImpl implements PsiJavaCodeReferenceElement {
32 private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsTypeParameterReferenceImpl");
33 private final PsiElement myParent;
34 private final String myName;
36 public ClsTypeParameterReferenceImpl(PsiElement parent, String name) {
37 myParent = parent;
38 myName = name;
41 public void processVariants(PsiScopeProcessor processor) {
42 throw new RuntimeException("Variants are not available for light references");
45 public PsiElement getReferenceNameElement() {
46 return null;
49 public PsiReferenceParameterList getParameterList() {
50 return null;
53 public String getQualifiedName() {
54 return myName;
57 public String getReferenceName() {
58 return myName;
61 public PsiElement resolve() {
62 LOG.assertTrue(myParent.isValid());
63 PsiElement parent = myParent;
64 while (!(parent instanceof PsiFile)) {
65 PsiTypeParameterList parameterList = null;
66 if (parent instanceof PsiClass) {
67 parameterList = ((PsiClass) parent).getTypeParameterList();
69 else if (parent instanceof PsiMethod) {
70 parameterList = ((PsiMethod) parent).getTypeParameterList();
73 if (parameterList != null) {
74 PsiTypeParameter[] parameters = parameterList.getTypeParameters();
75 for (PsiTypeParameter parameter : parameters) {
76 if (myName.equals(parameter.getName())) return parameter;
79 parent = parent.getParent();
82 return null;
85 @NotNull
86 public JavaResolveResult advancedResolve(boolean incompleteCode){
87 return new CandidateInfo(resolve(), PsiSubstitutor.EMPTY);
90 @NotNull
91 public JavaResolveResult[] multiResolve(boolean incompleteCode){
92 final JavaResolveResult result = advancedResolve(incompleteCode);
93 if(result != JavaResolveResult.EMPTY) return new JavaResolveResult[]{result};
94 return JavaResolveResult.EMPTY_ARRAY;
97 @NotNull
98 public PsiType[] getTypeParameters() {
99 return PsiType.EMPTY_ARRAY;
102 public PsiElement getQualifier() {
103 return null;
106 public boolean isQualified() {
107 return false;
110 public String getCanonicalText() {
111 return myName;
114 public boolean isReferenceTo(PsiElement element) {
115 if (!(element instanceof ClsTypeParameterImpl)) return false;
117 return element == resolve();
120 public String getText() {
121 return myName;
124 public int getTextLength() {
125 return getText().length();
128 public PsiReference getReference() {
129 return this;
132 @NotNull
133 public PsiElement[] getChildren(){
134 return PsiElement.EMPTY_ARRAY;
137 public PsiElement getParent(){
138 return myParent;
141 public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
142 throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE);
145 public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
146 throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE);
149 public Object[] getVariants() {
150 throw new RuntimeException("Variants are not available for references to compiled code");
153 public boolean isSoft(){
154 return false;
157 public void appendMirrorText(final int indentLevel, final StringBuffer buffer){
158 buffer.append(getCanonicalText());
161 public void setMirror(@NotNull TreeElement element){
162 setMirrorCheckingType(element, ElementType.JAVA_CODE_REFERENCE);
165 public void accept(@NotNull PsiElementVisitor visitor){
166 if (visitor instanceof JavaElementVisitor) {
167 ((JavaElementVisitor)visitor).visitReferenceElement(this);
169 else {
170 visitor.visitElement(this);
174 public String toString() {
175 return "PsiJavaCodeReferenceElement:" + getText();
178 public TextRange getRangeInElement() {
179 final PsiElement mirror = getMirror();
180 return mirror != null ? mirror.getTextRange() : new TextRange(0, getTextLength());
183 public PsiElement getElement() {
184 return this;