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 org.jetbrains.annotations.NotNull;
022 import org.jetbrains.annotations.Nullable;
023 import org.jetbrains.kotlin.KtNodeTypes;
024
025 import java.util.Collections;
026 import java.util.List;
027
028 public abstract class KtFunctionNotStubbed extends KtTypeParameterListOwnerNotStubbed implements KtFunction {
029
030 public KtFunctionNotStubbed(@NotNull ASTNode node) {
031 super(node);
032 }
033
034 @Override
035 @Nullable
036 public KtParameterList getValueParameterList() {
037 return (KtParameterList) findChildByType(KtNodeTypes.VALUE_PARAMETER_LIST);
038 }
039
040 @Override
041 @NotNull
042 public List<KtParameter> getValueParameters() {
043 KtParameterList list = getValueParameterList();
044 return list != null ? list.getParameters() : Collections.<KtParameter>emptyList();
045 }
046
047 @Override
048 @Nullable
049 public KtExpression getBodyExpression() {
050 return findChildByClass(KtExpression.class);
051 }
052
053 @Override
054 public boolean hasDeclaredReturnType() {
055 return false;
056 }
057
058 @Override
059 @Nullable
060 public KtTypeReference getReceiverTypeReference() {
061 return null;
062 }
063
064 @Override
065 @Nullable
066 public KtTypeReference getTypeReference() {
067 return null;
068 }
069
070 @Nullable
071 @Override
072 public KtTypeReference setTypeReference(@Nullable KtTypeReference typeRef) {
073 if (typeRef == null) return null;
074 throw new IllegalStateException("Lambda expressions can't have type reference");
075 }
076
077 @Nullable
078 @Override
079 public PsiElement getColon() {
080 return null;
081 }
082
083 @Override
084 public boolean isLocal() {
085 PsiElement parent = getParent();
086 return !(parent instanceof KtFile || parent instanceof KtClassBody);
087 }
088 }