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.lang.resolve.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.jet.lang.resolve.java.structure.*;
023    import org.jetbrains.jet.lang.resolve.name.Name;
024    
025    import java.util.Collection;
026    
027    import static org.jetbrains.jet.lang.resolve.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        @Override
035        public int getIndex() {
036            return getPsi().getIndex();
037        }
038    
039        @NotNull
040        @Override
041        public Name getName() {
042            return Name.identifier(getPsi().getName());
043        }
044    
045        @Override
046        @NotNull
047        public Collection<JavaClassifierType> getUpperBounds() {
048            return classifierTypes(getPsi().getExtendsList().getReferencedTypes());
049        }
050    
051        @Override
052        @Nullable
053        public JavaTypeParameterListOwner getOwner() {
054            PsiTypeParameterListOwner owner = getPsi().getOwner();
055            // TODO: a separate factory for such things
056            if (owner instanceof PsiMethod) {
057                return new JavaMethodImpl((PsiMethod) owner);
058            }
059            else if (owner instanceof PsiClass) {
060                return new JavaClassImpl((PsiClass) owner);
061            }
062            else if (owner != null) {
063                throw new UnsupportedOperationException("Unsupported type parameter list owner: " + owner);
064            }
065    
066            return null;
067        }
068    
069        @NotNull
070        @Override
071        public JavaType getType() {
072            return JavaTypeImpl.create(JavaPsiFacade.getInstance(getPsi().getProject()).getElementFactory().createType(getPsi()));
073        }
074    
075        @Override
076        @NotNull
077        public JavaTypeProvider getTypeProvider() {
078            return new JavaTypeProviderImpl(getPsi().getManager());
079        }
080    }