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 com.intellij.psi.PsiElement; 021 import com.intellij.psi.tree.IElementType; 022 import org.jetbrains.annotations.NotNull; 023 import org.jetbrains.annotations.Nullable; 024 import org.jetbrains.kotlin.JetNodeTypes; 025 import org.jetbrains.kotlin.lexer.JetTokens; 026 import org.jetbrains.kotlin.psi.typeRefHelpers.TypeRefHelpersPackage; 027 028 import java.util.Collections; 029 import java.util.List; 030 031 public abstract class JetFunctionNotStubbed extends JetTypeParameterListOwnerNotStubbed implements JetFunction { 032 033 public JetFunctionNotStubbed(@NotNull ASTNode node) { 034 super(node); 035 } 036 037 @Override 038 @Nullable 039 public JetParameterList getValueParameterList() { 040 return (JetParameterList) findChildByType(JetNodeTypes.VALUE_PARAMETER_LIST); 041 } 042 043 @Override 044 @NotNull 045 public List<JetParameter> getValueParameters() { 046 JetParameterList list = getValueParameterList(); 047 return list != null ? list.getParameters() : Collections.<JetParameter>emptyList(); 048 } 049 050 @Override 051 @Nullable 052 public JetExpression getBodyExpression() { 053 return findChildByClass(JetExpression.class); 054 } 055 056 @Override 057 public boolean hasDeclaredReturnType() { 058 return getTypeReference() != null; 059 } 060 061 @Override 062 @Nullable 063 public JetTypeReference getReceiverTypeReference() { 064 PsiElement child = getFirstChild(); 065 while (child != null) { 066 IElementType tt = child.getNode().getElementType(); 067 if (tt == JetTokens.LPAR || tt == JetTokens.COLON) break; 068 if (child instanceof JetTypeReference) { 069 return (JetTypeReference) child; 070 } 071 child = child.getNextSibling(); 072 } 073 074 return null; 075 } 076 077 @Override 078 @Nullable 079 public JetTypeReference getTypeReference() { 080 return TypeRefHelpersPackage.getTypeReference(this); 081 } 082 083 @Nullable 084 @Override 085 public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) { 086 return TypeRefHelpersPackage.setTypeReference(this, getValueParameterList(), typeRef); 087 } 088 089 @Nullable 090 @Override 091 public PsiElement getColon() { 092 return findChildByType(JetTokens.COLON); 093 } 094 095 @Override 096 public boolean isLocal() { 097 PsiElement parent = getParent(); 098 return !(parent instanceof JetFile || parent instanceof JetClassBody); 099 } 100 }