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
.Pair
;
20 import com
.intellij
.psi
.*;
21 import com
.intellij
.psi
.impl
.InheritanceImplUtil
;
22 import com
.intellij
.psi
.impl
.PsiClassImplUtil
;
23 import com
.intellij
.psi
.impl
.PsiSuperMethodImplUtil
;
24 import com
.intellij
.psi
.impl
.java
.stubs
.JavaStubElementTypes
;
25 import com
.intellij
.psi
.impl
.java
.stubs
.PsiTypeParameterStub
;
26 import com
.intellij
.psi
.impl
.light
.LightEmptyImplementsList
;
27 import com
.intellij
.psi
.impl
.meta
.MetaRegistry
;
28 import com
.intellij
.psi
.impl
.source
.SourceTreeToPsiMap
;
29 import com
.intellij
.psi
.impl
.source
.tree
.TreeElement
;
30 import com
.intellij
.psi
.javadoc
.PsiDocComment
;
31 import com
.intellij
.psi
.meta
.PsiMetaData
;
32 import com
.intellij
.psi
.scope
.PsiScopeProcessor
;
33 import com
.intellij
.psi
.search
.SearchScope
;
34 import com
.intellij
.util
.IncorrectOperationException
;
35 import org
.jetbrains
.annotations
.NonNls
;
36 import org
.jetbrains
.annotations
.NotNull
;
39 import java
.util
.Collection
;
40 import java
.util
.List
;
45 public class ClsTypeParameterImpl
extends ClsRepositoryPsiElement
<PsiTypeParameterStub
> implements PsiTypeParameter
{
46 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.compiled.ClsTypeParameterImpl");
47 static final ClsTypeParameterImpl
[] EMPTY_ARRAY
= new ClsTypeParameterImpl
[0];
48 private final LightEmptyImplementsList myLightEmptyImplementsList
;
50 public ClsTypeParameterImpl(final PsiTypeParameterStub stub
) {
52 myLightEmptyImplementsList
= new LightEmptyImplementsList(getManager());
55 public String
getQualifiedName() {
59 public boolean isInterface() {
63 public boolean isAnnotationType() {
67 public boolean isEnum() {
72 public PsiField
[] getFields() {
73 return PsiField
.EMPTY_ARRAY
;
77 public PsiMethod
[] getMethods() {
78 return PsiMethod
.EMPTY_ARRAY
;
81 public PsiMethod
findMethodBySignature(PsiMethod patternMethod
, boolean checkBases
) {
82 return PsiClassImplUtil
.findMethodBySignature(this, patternMethod
, checkBases
);
86 public PsiMethod
[] findMethodsBySignature(PsiMethod patternMethod
, boolean checkBases
) {
87 return PsiClassImplUtil
.findMethodsBySignature(this, patternMethod
, checkBases
);
90 public PsiField
findFieldByName(String name
, boolean checkBases
) {
91 return PsiClassImplUtil
.findFieldByName(this, name
, checkBases
);
95 public PsiMethod
[] findMethodsByName(String name
, boolean checkBases
) {
96 return PsiClassImplUtil
.findMethodsByName(this, name
, checkBases
);
100 public List
<Pair
<PsiMethod
, PsiSubstitutor
>> findMethodsAndTheirSubstitutorsByName(String name
, boolean checkBases
) {
101 return PsiClassImplUtil
.findMethodsAndTheirSubstitutorsByName(this, name
, checkBases
);
105 public List
<Pair
<PsiMethod
, PsiSubstitutor
>> getAllMethodsAndTheirSubstitutors() {
106 return PsiClassImplUtil
.getAllWithSubstitutorsByMap(this, PsiMethod
.class);
109 public PsiClass
findInnerClassByName(String name
, boolean checkBases
) {
110 return PsiClassImplUtil
.findInnerByName(this, name
, checkBases
);
113 public PsiTypeParameterList
getTypeParameterList() {
117 public boolean hasTypeParameters() {
121 // very special method!
122 public PsiElement
getScope() {
123 return getParent().getParent();
126 public boolean isInheritorDeep(PsiClass baseClass
, PsiClass classToByPass
) {
127 return InheritanceImplUtil
.isInheritorDeep(this, baseClass
, classToByPass
);
130 public boolean isInheritor(@NotNull PsiClass baseClass
, boolean checkDeep
) {
131 return InheritanceImplUtil
.isInheritor(this, baseClass
, checkDeep
);
134 public PsiIdentifier
getNameIdentifier() {
138 public boolean processDeclarations(@NotNull PsiScopeProcessor processor
, @NotNull ResolveState state
, PsiElement lastParent
, @NotNull PsiElement place
) {
139 return PsiClassImplUtil
.processDeclarationsInClass(this, processor
, state
, null, lastParent
, place
, false);
142 public String
getName() {
143 return getStub().getName();
146 public PsiElement
setName(@NotNull String name
) throws IncorrectOperationException
{
147 throw new IncorrectOperationException("Cannot change compiled classes");
151 public PsiMethod
[] getConstructors() {
152 return PsiMethod
.EMPTY_ARRAY
;
155 public PsiDocComment
getDocComment() {
159 public boolean isDeprecated() {
164 public PsiReferenceList
getExtendsList() {
165 return getStub().findChildStubByType(JavaStubElementTypes
.EXTENDS_BOUND_LIST
).getPsi();
168 public PsiReferenceList
getImplementsList() {
169 return myLightEmptyImplementsList
;
173 public PsiClassType
[] getExtendsListTypes() {
174 return getExtendsList().getReferencedTypes();
178 public PsiClassType
[] getImplementsListTypes() {
179 return PsiClassType
.EMPTY_ARRAY
;
183 public PsiClass
[] getInnerClasses() {
184 return PsiClass
.EMPTY_ARRAY
;
188 public PsiField
[] getAllFields() {
189 return PsiField
.EMPTY_ARRAY
;
193 public PsiMethod
[] getAllMethods() {
194 return PsiMethod
.EMPTY_ARRAY
;
198 public PsiClass
[] getAllInnerClasses() {
199 return PsiClass
.EMPTY_ARRAY
;
203 public PsiClassInitializer
[] getInitializers() {
204 return PsiClassInitializer
.EMPTY_ARRAY
;
208 public PsiTypeParameter
[] getTypeParameters() {
209 return PsiTypeParameter
.EMPTY_ARRAY
;
212 public PsiClass
getSuperClass() {
213 return PsiClassImplUtil
.getSuperClass(this);
216 public PsiClass
[] getInterfaces() {
217 return PsiClassImplUtil
.getInterfaces(this);
221 public PsiClass
[] getSupers() {
222 return PsiClassImplUtil
.getSupers(this);
226 public PsiClassType
[] getSuperTypes() {
227 return PsiClassImplUtil
.getSuperTypes(this);
230 public PsiClass
getContainingClass() {
235 public Collection
<HierarchicalMethodSignature
> getVisibleSignatures() {
236 return PsiSuperMethodImplUtil
.getVisibleSignatures(this);
239 public PsiModifierList
getModifierList() {
243 public boolean hasModifierProperty(@NotNull String name
) {
247 public PsiJavaToken
getLBrace() {
251 public PsiJavaToken
getRBrace() {
255 public void accept(@NotNull PsiElementVisitor visitor
) {
256 if (visitor
instanceof JavaElementVisitor
) {
257 ((JavaElementVisitor
)visitor
).visitTypeParameter(this);
260 visitor
.visitElement(this);
265 public String
toString() {
266 return "PsiTypeParameter";
269 public void appendMirrorText(final int indentLevel
, @NonNls final StringBuffer buffer
) {
270 buffer
.append(getName());
271 PsiJavaCodeReferenceElement
[] bounds
= getExtendsList().getReferenceElements();
272 if (bounds
.length
> 0) {
273 buffer
.append(" extends ");
274 for (int i
= 0; i
< bounds
.length
; i
++) {
275 PsiJavaCodeReferenceElement bound
= bounds
[i
];
276 if (i
> 0) buffer
.append(" & ");
277 buffer
.append(bound
.getCanonicalText());
282 public void setMirror(@NotNull TreeElement element
) {
283 setMirrorCheckingType(element
, null);
285 PsiTypeParameter mirror
= (PsiTypeParameter
)SourceTreeToPsiMap
.treeElementToPsi(element
);
286 ((ClsReferenceListImpl
)getExtendsList()).setMirror((TreeElement
)SourceTreeToPsiMap
.psiElementToTree(mirror
.getExtendsList()));
290 public PsiElement
[] getChildren() {
291 return PsiElement
.EMPTY_ARRAY
;
294 public PsiTypeParameterListOwner
getOwner() {
295 return (PsiTypeParameterListOwner
)getParent().getParent();
299 public int getIndex() {
300 final PsiTypeParameterStub st
= getStub();
301 return st
.getParentStub().getChildrenStubs().indexOf(st
);
304 public PsiMetaData
getMetaData() {
305 return MetaRegistry
.getMeta(this);
308 public Icon
getElementIcon(final int flags
) {
309 return PsiClassImplUtil
.getClassIcon(flags
, this);
313 public boolean isEquivalentTo(final PsiElement another
) {
314 return PsiClassImplUtil
.isClassEquivalentTo(this, another
);
318 public SearchScope
getUseScope() {
319 return PsiClassImplUtil
.getClassUseScope(this);
322 //todo parse annotataions
324 public PsiAnnotation
[] getAnnotations() {
325 return PsiAnnotation
.EMPTY_ARRAY
;
328 public PsiAnnotation
findAnnotation(@NotNull @NonNls String qualifiedName
) {
333 public PsiAnnotation
addAnnotation(@NotNull @NonNls String qualifiedName
) {
334 throw new IncorrectOperationException();
337 public PsiAnnotation
[] getApplicableAnnotations() {
338 return getAnnotations();