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 false;
059 }
060
061 @Override
062 @Nullable
063 public JetTypeReference getReceiverTypeReference() {
064 return null;
065 }
066
067 @Override
068 @Nullable
069 public JetTypeReference getTypeReference() {
070 return null;
071 }
072
073 @Nullable
074 @Override
075 public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) {
076 if (typeRef == null) return null;
077 throw new IllegalStateException("Function literals can't have type reference");
078 }
079
080 @Nullable
081 @Override
082 public PsiElement getColon() {
083 return null;
084 }
085
086 @Override
087 public boolean isLocal() {
088 PsiElement parent = getParent();
089 return !(parent instanceof JetFile || parent instanceof JetClassBody);
090 }
091 }