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