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.psi;
018    
019    import com.intellij.lang.ASTNode;
020    import com.intellij.psi.stubs.IStubElementType;
021    import org.jetbrains.annotations.NotNull;
022    import org.jetbrains.annotations.Nullable;
023    import org.jetbrains.kotlin.psi.stubs.KotlinStubWithFqName;
024    import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
025    
026    import java.util.Collections;
027    import java.util.List;
028    
029    public abstract class KtTypeParameterListOwnerStub<T extends KotlinStubWithFqName<?>>
030            extends KtNamedDeclarationStub<T> implements KtTypeParameterListOwner {
031        public KtTypeParameterListOwnerStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
032            super(stub, nodeType);
033        }
034    
035        public KtTypeParameterListOwnerStub(@NotNull ASTNode node) {
036            super(node);
037        }
038    
039        @Override
040        @Nullable
041        public KtTypeParameterList getTypeParameterList() {
042            return getStubOrPsiChild(KtStubElementTypes.TYPE_PARAMETER_LIST);
043        }
044    
045        @Override
046        @Nullable
047        public KtTypeConstraintList getTypeConstraintList() {
048            return getStubOrPsiChild(KtStubElementTypes.TYPE_CONSTRAINT_LIST);
049        }
050    
051        @Override
052        @NotNull
053        public List<KtTypeConstraint> getTypeConstraints() {
054            KtTypeConstraintList typeConstraintList = getTypeConstraintList();
055            if (typeConstraintList == null) {
056                return Collections.emptyList();
057            }
058            return typeConstraintList.getConstraints();
059        }
060    
061        @Override
062        @NotNull
063        public List<KtTypeParameter> getTypeParameters() {
064            KtTypeParameterList list = getTypeParameterList();
065            if (list == null) return Collections.emptyList();
066    
067            return list.getParameters();
068        }
069    }