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 com.intellij.psi.stubs.StubElement;
022    import org.jetbrains.annotations.NotNull;
023    import org.jetbrains.annotations.Nullable;
024    import org.jetbrains.kotlin.lexer.KtModifierKeywordToken;
025    import org.jetbrains.kotlin.psi.addRemoveModifier.AddRemoveModifierKt;
026    import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
027    
028    import java.util.Collections;
029    import java.util.List;
030    
031    public class KtModifierListOwnerStub<T extends StubElement<?>> extends KtElementImplStub<T> implements KtModifierListOwner {
032        public KtModifierListOwnerStub(ASTNode node) {
033            super(node);
034        }
035    
036        public KtModifierListOwnerStub(T stub, IStubElementType nodeType) {
037            super(stub, nodeType);
038        }
039    
040        @Override
041        @Nullable
042        public KtModifierList getModifierList() {
043            return getStubOrPsiChild(KtStubElementTypes.MODIFIER_LIST);
044        }
045    
046        @Override
047        public boolean hasModifier(@NotNull KtModifierKeywordToken modifier) {
048            KtModifierList modifierList = getModifierList();
049            return modifierList != null && modifierList.hasModifier(modifier);
050        }
051    
052        @Override
053        public void addModifier(@NotNull KtModifierKeywordToken modifier) {
054            AddRemoveModifierKt.addModifier(this, modifier);
055        }
056    
057        @Override
058        public void removeModifier(@NotNull KtModifierKeywordToken modifier) {
059            AddRemoveModifierKt.removeModifier(this, modifier);
060        }
061    
062        @NotNull
063        @Override
064        public KtAnnotationEntry addAnnotationEntry(@NotNull KtAnnotationEntry annotationEntry) {
065            return AddRemoveModifierKt.addAnnotationEntry(this, annotationEntry);
066        }
067    
068        @Override
069        @NotNull
070        public List<KtAnnotationEntry> getAnnotationEntries() {
071            KtModifierList modifierList = getModifierList();
072            if (modifierList == null) return Collections.emptyList();
073            return modifierList.getAnnotationEntries();
074        }
075    
076        @Override
077        @NotNull
078        public List<KtAnnotation> getAnnotations() {
079            KtModifierList modifierList = getModifierList();
080            if (modifierList == null) return Collections.emptyList();
081            return modifierList.getAnnotations();
082        }
083    }