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