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
.psi
.JavaElementVisitor
;
20 import com
.intellij
.psi
.PsiElementVisitor
;
21 import com
.intellij
.psi
.PsiTypeParameter
;
22 import com
.intellij
.psi
.PsiTypeParameterList
;
23 import com
.intellij
.psi
.impl
.PsiImplUtil
;
24 import com
.intellij
.psi
.impl
.java
.stubs
.JavaStubElementTypes
;
25 import com
.intellij
.psi
.impl
.java
.stubs
.PsiTypeParameterListStub
;
26 import com
.intellij
.psi
.impl
.source
.SourceTreeToPsiMap
;
27 import com
.intellij
.psi
.impl
.source
.tree
.TreeElement
;
28 import org
.jetbrains
.annotations
.NotNull
;
33 public class ClsTypeParametersListImpl
extends ClsRepositoryPsiElement
<PsiTypeParameterListStub
> implements PsiTypeParameterList
{
34 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.compiled.ClsTypeParametersListImpl");
36 public ClsTypeParametersListImpl(final PsiTypeParameterListStub stub
) {
40 public void appendMirrorText(final int indentLevel
, final StringBuffer buffer
) {
41 final PsiTypeParameter
[] params
= getTypeParameters();
42 if (params
.length
!= 0) {
44 for (int i
= 0; i
< params
.length
; i
++) {
45 ClsTypeParameterImpl parameter
= (ClsTypeParameterImpl
)params
[i
];
46 if (i
> 0) buffer
.append(", ");
47 parameter
.appendMirrorText(indentLevel
, buffer
);
53 public void setMirror(@NotNull TreeElement element
) {
54 setMirrorCheckingType(element
, null);
56 PsiTypeParameter
[] parms
= getTypeParameters();
57 PsiTypeParameter
[] parmMirrors
= ((PsiTypeParameterList
)SourceTreeToPsiMap
.treeElementToPsi(element
)).getTypeParameters();
58 LOG
.assertTrue(parms
.length
== parmMirrors
.length
);
59 if (parms
.length
== parmMirrors
.length
) {
60 for (int i
= 0; i
< parms
.length
; i
++) {
61 ((ClsElementImpl
)parms
[i
]).setMirror((TreeElement
)SourceTreeToPsiMap
.psiElementToTree(parmMirrors
[i
]));
67 public void accept(@NotNull PsiElementVisitor visitor
) {
68 if (visitor
instanceof JavaElementVisitor
) {
69 ((JavaElementVisitor
)visitor
).visitTypeParameterList(this);
72 visitor
.visitElement(this);
76 public PsiTypeParameter
[] getTypeParameters() {
77 return getStub().getChildrenByType(JavaStubElementTypes
.TYPE_PARAMETER
, PsiTypeParameter
.ARRAY_FACTORY
);
80 public int getTypeParameterIndex(PsiTypeParameter typeParameter
) {
81 LOG
.assertTrue(typeParameter
.getParent() == this);
82 return PsiImplUtil
.getTypeParameterIndex(typeParameter
, this);
85 public String
toString() {
86 return "PsiTypeParameterList";