001 /*
002 * Copyright 2010-2013 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.jet.asJava;
018
019 import com.intellij.psi.*;
020 import com.intellij.psi.impl.light.AbstractLightClass;
021 import org.jetbrains.annotations.NotNull;
022 import org.jetbrains.annotations.Nullable;
023 import org.jetbrains.jet.plugin.JetLanguage;
024
025 public class KotlinLightTypeParameter extends AbstractLightClass implements PsiTypeParameter {
026
027 private final KotlinLightClassForExplicitDeclaration lightClass;
028 private final int index;
029 private final String name;
030
031 protected KotlinLightTypeParameter(
032 @NotNull KotlinLightClassForExplicitDeclaration lightClass,
033 int index,
034 @NotNull String name) {
035 super(lightClass.getManager(), JetLanguage.INSTANCE);
036 this.lightClass = lightClass;
037 this.index = index;
038 this.name = name;
039 }
040
041 @NotNull
042 @Override
043 public PsiTypeParameter getDelegate() {
044 return lightClass.getDelegate().getTypeParameters()[index];
045 }
046
047 @NotNull
048 @Override
049 public PsiElement copy() {
050 return new KotlinLightTypeParameter(lightClass, index, name);
051 }
052
053 @Override
054 public void accept(@NotNull PsiElementVisitor visitor) {
055 if (visitor instanceof JavaElementVisitor) {
056 ((JavaElementVisitor) visitor).visitTypeParameter(this);
057 }
058 else {
059 super.accept(visitor);
060 }
061 }
062
063 @Nullable
064 @Override
065 public String getName() {
066 return name;
067 }
068
069 @Override
070 public PsiTypeParameterListOwner getOwner() {
071 return lightClass;
072 }
073
074 @Override
075 public int getIndex() {
076 return index;
077 }
078
079 @NotNull
080 @Override
081 public PsiAnnotation[] getAnnotations() {
082 return getDelegate().getAnnotations();
083 }
084
085 @NotNull
086 @Override
087 public PsiAnnotation[] getApplicableAnnotations() {
088 return getDelegate().getApplicableAnnotations();
089 }
090
091 @Override
092 public PsiAnnotation findAnnotation(@NotNull String qualifiedName) {
093 return getDelegate().findAnnotation(qualifiedName);
094 }
095
096 @NotNull
097 @Override
098 public PsiAnnotation addAnnotation(@NotNull String qualifiedName) {
099 return getDelegate().addAnnotation(qualifiedName);
100 }
101
102 @Override
103 public String toString() {
104 return "KotlinLightTypeParameter:" + getName();
105 }
106 }