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 org.jetbrains.annotations.NotNull; 021 import org.jetbrains.annotations.Nullable; 022 import org.jetbrains.kotlin.JetNodeTypes; 023 import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub; 024 import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes; 025 026 import java.util.Collections; 027 import java.util.List; 028 029 public class JetAnnotationEntry extends JetElementImplStub<KotlinAnnotationEntryStub> implements JetCallElement { 030 public JetAnnotationEntry(@NotNull ASTNode node) { 031 super(node); 032 } 033 034 public JetAnnotationEntry(@NotNull KotlinAnnotationEntryStub 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 getStubOrPsiChild(JetStubElementTypes.CONSTRUCTOR_CALLEE); 056 } 057 058 @Override 059 public JetValueArgumentList getValueArgumentList() { 060 KotlinAnnotationEntryStub stub = getStub(); 061 if (stub != null && !stub.hasValueArguments()) { 062 return null; 063 } 064 return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST); 065 } 066 067 @NotNull 068 @Override 069 public List<? extends ValueArgument> getValueArguments() { 070 JetValueArgumentList list = getValueArgumentList(); 071 return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList(); 072 } 073 074 @NotNull 075 @Override 076 public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() { 077 return Collections.emptyList(); 078 } 079 080 @NotNull 081 @Override 082 public List<JetTypeProjection> getTypeArguments() { 083 JetTypeArgumentList typeArgumentList = getTypeArgumentList(); 084 if (typeArgumentList == null) { 085 return Collections.emptyList(); 086 } 087 return typeArgumentList.getArguments(); 088 } 089 090 @Override 091 public JetTypeArgumentList getTypeArgumentList() { 092 JetTypeReference typeReference = getTypeReference(); 093 if (typeReference == null) { 094 return null; 095 } 096 JetTypeElement typeElement = typeReference.getTypeElement(); 097 if (typeElement instanceof JetUserType) { 098 JetUserType userType = (JetUserType) typeElement; 099 return userType.getTypeArgumentList(); 100 } 101 return null; 102 } 103 104 }