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.google.common.collect.Lists; 020 import com.intellij.lang.ASTNode; 021 import org.jetbrains.annotations.NotNull; 022 import org.jetbrains.annotations.Nullable; 023 import org.jetbrains.kotlin.JetNodeTypes; 024 025 import java.util.Collections; 026 import java.util.List; 027 028 public class JetCallExpression extends JetExpressionImpl implements JetCallElement, JetReferenceExpression { 029 public JetCallExpression(@NotNull ASTNode node) { 030 super(node); 031 } 032 033 @Override 034 public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) { 035 return visitor.visitCallExpression(this, data); 036 } 037 038 @Override 039 @Nullable 040 public JetExpression getCalleeExpression() { 041 return findChildByClass(JetExpression.class); 042 } 043 044 @Override 045 @Nullable 046 public JetValueArgumentList getValueArgumentList() { 047 return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST); 048 } 049 050 @Override 051 @Nullable 052 public JetTypeArgumentList getTypeArgumentList() { 053 return (JetTypeArgumentList) findChildByType(JetNodeTypes.TYPE_ARGUMENT_LIST); 054 } 055 056 /** 057 * Normally there should be only one (or zero) function literal arguments. 058 * The returned value is a list for better handling of commonly made mistake of a function taking a lambda and returning another function. 059 * Most of users can simply ignore lists of more than one element. 060 */ 061 @Override 062 @NotNull 063 public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() { 064 return findChildrenByType(JetNodeTypes.FUNCTION_LITERAL_ARGUMENT); 065 } 066 067 @Override 068 @NotNull 069 public List<? extends ValueArgument> getValueArguments() { 070 JetValueArgumentList list = getValueArgumentList(); 071 List<JetValueArgument> valueArgumentsInParentheses = list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList(); 072 List<JetFunctionLiteralArgument> functionLiteralArguments = getFunctionLiteralArguments(); 073 if (functionLiteralArguments.isEmpty()) { 074 return valueArgumentsInParentheses; 075 } 076 List<ValueArgument> allValueArguments = Lists.newArrayList(); 077 allValueArguments.addAll(valueArgumentsInParentheses); 078 allValueArguments.addAll(functionLiteralArguments); 079 return allValueArguments; 080 } 081 082 @Override 083 @NotNull 084 public List<JetTypeProjection> getTypeArguments() { 085 JetTypeArgumentList list = getTypeArgumentList(); 086 return list != null ? list.getArguments() : Collections.<JetTypeProjection>emptyList(); 087 } 088 }