001 /*
002 * Copyright 2010-2014 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.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.jet.lang.psi.addRemoveModifier.AddRemoveModifierPackage;
025 import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
026 import org.jetbrains.jet.lexer.JetModifierKeywordToken;
027 import org.jetbrains.jet.lexer.JetTokens;
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.INTERNAL_KEYWORD);
056 }
057
058 @Override
059 public void removeModifier(@NotNull JetModifierKeywordToken modifier) {
060 AddRemoveModifierPackage.removeModifier(this, modifier);
061 }
062
063 @Override
064 @NotNull
065 public List<JetAnnotationEntry> getAnnotationEntries() {
066 JetModifierList modifierList = getModifierList();
067 if (modifierList == null) return Collections.emptyList();
068 return modifierList.getAnnotationEntries();
069 }
070
071 @Override
072 @NotNull
073 public List<JetAnnotation> getAnnotations() {
074 JetModifierList modifierList = getModifierList();
075 if (modifierList == null) return Collections.emptyList();
076 return modifierList.getAnnotations();
077 }
078 }