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 017package org.jetbrains.jet.lang.psi; 018 019import com.intellij.lang.ASTNode; 020import com.intellij.psi.stubs.IStubElementType; 021import org.jetbrains.annotations.NotNull; 022import org.jetbrains.annotations.Nullable; 023import org.jetbrains.jet.JetNodeTypes; 024import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub; 025import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; 026 027import java.util.Collections; 028import java.util.List; 029 030public 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 void accept(@NotNull JetVisitorVoid visitor) { 047 visitor.visitAnnotationEntry(this); 048 } 049 050 @Override 051 public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) { 052 return visitor.visitAnnotationEntry(this, data); 053 } 054 055 056 @Nullable @IfNotParsed 057 public JetTypeReference getTypeReference() { 058 JetConstructorCalleeExpression calleeExpression = getCalleeExpression(); 059 if (calleeExpression == null) { 060 return null; 061 } 062 return calleeExpression.getTypeReference(); 063 } 064 065 @Override 066 public JetConstructorCalleeExpression getCalleeExpression() { 067 return (JetConstructorCalleeExpression) findChildByType(JetNodeTypes.CONSTRUCTOR_CALLEE); 068 } 069 070 @Override 071 public JetValueArgumentList getValueArgumentList() { 072 return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST); 073 } 074 075 @NotNull 076 @Override 077 public List<? extends ValueArgument> getValueArguments() { 078 JetValueArgumentList list = getValueArgumentList(); 079 return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList(); 080 } 081 082 @NotNull 083 @Override 084 public List<JetExpression> getFunctionLiteralArguments() { 085 return Collections.emptyList(); 086 } 087 088 @NotNull 089 @Override 090 public List<JetTypeProjection> getTypeArguments() { 091 JetTypeArgumentList typeArgumentList = getTypeArgumentList(); 092 if (typeArgumentList == null) { 093 return Collections.emptyList(); 094 } 095 return typeArgumentList.getArguments(); 096 } 097 098 @Override 099 public JetTypeArgumentList getTypeArgumentList() { 100 JetTypeReference typeReference = getTypeReference(); 101 if (typeReference == null) { 102 return null; 103 } 104 JetTypeElement typeElement = typeReference.getTypeElement(); 105 if (typeElement instanceof JetUserType) { 106 JetUserType userType = (JetUserType) typeElement; 107 return userType.getTypeArgumentList(); 108 } 109 return null; 110 } 111 112}