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