001    /*
002     * Copyright 2010-2013 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 org.jetbrains.annotations.NotNull;
022    import org.jetbrains.annotations.Nullable;
023    import org.jetbrains.jet.JetNodeTypes;
024    import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub;
025    import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
026    
027    import java.util.Collections;
028    import java.util.List;
029    
030    public class JetAnnotationEntry extends JetElementImplStub<PsiJetAnnotationStub> implements JetCallElement {
031        public JetAnnotationEntry(@NotNull ASTNode node) {
032            super(node);
033        }
034    
035        @NotNull
036        @Override
037        public IStubElementType getElementType() {
038            return JetStubElementTypes.ANNOTATION_ENTRY;
039        }
040    
041        public JetAnnotationEntry(@NotNull PsiJetAnnotationStub stub) {
042            super(stub, JetStubElementTypes.ANNOTATION_ENTRY);
043        }
044    
045        @Override
046        public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
047            return visitor.visitAnnotationEntry(this, data);
048        }
049    
050    
051        @Nullable @IfNotParsed
052        public JetTypeReference getTypeReference() {
053            JetConstructorCalleeExpression calleeExpression = getCalleeExpression();
054            if (calleeExpression == null) {
055                return null;
056            }
057            return calleeExpression.getTypeReference();
058        }
059    
060        @Override
061        public JetConstructorCalleeExpression getCalleeExpression() {
062            return (JetConstructorCalleeExpression) findChildByType(JetNodeTypes.CONSTRUCTOR_CALLEE);
063        }
064    
065        @Override
066        public JetValueArgumentList getValueArgumentList() {
067            return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
068        }
069    
070        @NotNull
071        @Override
072        public List<? extends ValueArgument> getValueArguments() {
073            JetValueArgumentList list = getValueArgumentList();
074            return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
075        }
076    
077        @NotNull
078        @Override
079        public List<JetExpression> getFunctionLiteralArguments() {
080            return Collections.emptyList();
081        }
082    
083        @NotNull
084        @Override
085        public List<JetTypeProjection> getTypeArguments() {
086            JetTypeArgumentList typeArgumentList = getTypeArgumentList();
087            if (typeArgumentList == null) {
088                return Collections.emptyList();
089            }
090            return typeArgumentList.getArguments();
091        }
092    
093        @Override
094        public JetTypeArgumentList getTypeArgumentList() {
095            JetTypeReference typeReference = getTypeReference();
096            if (typeReference == null) {
097                return null;
098            }
099            JetTypeElement typeElement = typeReference.getTypeElement();
100            if (typeElement instanceof JetUserType) {
101                JetUserType userType = (JetUserType) typeElement;
102                return userType.getTypeArgumentList();
103            }
104            return null;
105        }
106    
107    }