001    /*
002     * Copyright 2010-2015 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.kotlin.load.java.structure.impl;
018    
019    import com.intellij.psi.*;
020    import org.jetbrains.annotations.NotNull;
021    import org.jetbrains.annotations.Nullable;
022    import org.jetbrains.kotlin.load.java.structure.*;
023    import org.jetbrains.kotlin.name.Name;
024    
025    import java.util.Collection;
026    
027    import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.classifierTypes;
028    
029    public class JavaTypeParameterImpl extends JavaClassifierImpl<PsiTypeParameter> implements JavaTypeParameter {
030        public JavaTypeParameterImpl(@NotNull PsiTypeParameter psiTypeParameter) {
031            super(psiTypeParameter);
032        }
033    
034        @NotNull
035        @Override
036        public Name getName() {
037            return Name.identifier(getPsi().getName());
038        }
039    
040        @Override
041        @NotNull
042        public Collection<JavaClassifierType> getUpperBounds() {
043            return classifierTypes(getPsi().getExtendsList().getReferencedTypes());
044        }
045    
046        @Override
047        @Nullable
048        public JavaTypeParameterListOwner getOwner() {
049            PsiTypeParameterListOwner owner = getPsi().getOwner();
050            // TODO: a separate factory for such things
051            if (owner instanceof PsiMethod) {
052                PsiMethod psiMethod = (PsiMethod) owner;
053                return psiMethod.isConstructor() ? new JavaConstructorImpl(psiMethod) : new JavaMethodImpl(psiMethod);
054            }
055            else if (owner instanceof PsiClass) {
056                return new JavaClassImpl((PsiClass) owner);
057            }
058            else if (owner != null) {
059                throw new UnsupportedOperationException("Unsupported type parameter list owner: " + owner);
060            }
061    
062            return null;
063        }
064    
065        @NotNull
066        @Override
067        public JavaType getType() {
068            return JavaTypeImpl.create(JavaPsiFacade.getInstance(getPsi().getProject()).getElementFactory().createType(getPsi()));
069        }
070    
071        @Override
072        @NotNull
073        public JavaTypeProvider getTypeProvider() {
074            return new JavaTypeProviderImpl(getPsi().getManager());
075        }
076    }