Introduced ParameterDescriptor type
This commit is contained in:
@@ -22,7 +22,6 @@ import com.intellij.psi.PsiFile;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
|
||||||
import org.jetbrains.kotlin.codegen.*;
|
import org.jetbrains.kotlin.codegen.*;
|
||||||
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
||||||
import org.jetbrains.kotlin.codegen.context.FieldOwnerContext;
|
import org.jetbrains.kotlin.codegen.context.FieldOwnerContext;
|
||||||
@@ -463,8 +462,8 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
if (field instanceof StackValue.Field) {
|
if (field instanceof StackValue.Field) {
|
||||||
DeclarationDescriptor varDescriptor = ((StackValue.Field) field).descriptor;
|
DeclarationDescriptor varDescriptor = ((StackValue.Field) field).descriptor;
|
||||||
//check that variable is inline function parameter
|
//check that variable is inline function parameter
|
||||||
return !(varDescriptor instanceof CallableDescriptor &&
|
return !(varDescriptor instanceof ParameterDescriptor &&
|
||||||
InlineUtil.isInlineLambdaParameter((CallableDescriptor) varDescriptor) &&
|
InlineUtil.isInlineLambdaParameter((ParameterDescriptor) varDescriptor) &&
|
||||||
InlineUtil.isInline(varDescriptor.getContainingDeclaration()));
|
InlineUtil.isInline(varDescriptor.getContainingDeclaration()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -218,11 +218,8 @@ class InlineChecker implements CallChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInlinableParameter(@NotNull CallableDescriptor descriptor) {
|
private static boolean isInlinableParameter(@NotNull ParameterDescriptor descriptor) {
|
||||||
JetType type = descriptor.getReturnType();
|
return InlineUtil.isInlineLambdaParameter(descriptor) && !descriptor.getType().isMarkedNullable();
|
||||||
return type != null &&
|
|
||||||
InlineUtil.isInlineLambdaParameter(descriptor) &&
|
|
||||||
!type.isMarkedNullable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInvokeOrInlineExtension(@NotNull CallableDescriptor descriptor) {
|
private static boolean isInvokeOrInlineExtension(@NotNull CallableDescriptor descriptor) {
|
||||||
|
|||||||
+3
-4
@@ -132,14 +132,13 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkInlinableParameter(
|
public static boolean checkInlinableParameter(
|
||||||
@NotNull CallableDescriptor parameter,
|
@NotNull ParameterDescriptor parameter,
|
||||||
@NotNull JetElement expression,
|
@NotNull JetElement expression,
|
||||||
@NotNull CallableDescriptor functionDescriptor,
|
@NotNull CallableDescriptor functionDescriptor,
|
||||||
@Nullable BindingTrace trace
|
@Nullable BindingTrace trace
|
||||||
) {
|
) {
|
||||||
JetType type = parameter.getReturnType();
|
if (InlineUtil.isInlineLambdaParameter(parameter)) {
|
||||||
if (type != null && InlineUtil.isInlineLambdaParameter(parameter)) {
|
if (parameter.getType().isMarkedNullable()) {
|
||||||
if (type.isMarkedNullable()) {
|
|
||||||
if (trace != null) {
|
if (trace != null) {
|
||||||
trace.report(Errors.NULLABLE_INLINE_PARAMETER.on(expression, expression, functionDescriptor));
|
trace.report(Errors.NULLABLE_INLINE_PARAMETER.on(expression, expression, functionDescriptor));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,16 +35,13 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
|||||||
import org.jetbrains.kotlin.resolve.constants.ArrayValue;
|
import org.jetbrains.kotlin.resolve.constants.ArrayValue;
|
||||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.kotlin.resolve.constants.EnumValue;
|
import org.jetbrains.kotlin.resolve.constants.EnumValue;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
|
||||||
|
|
||||||
import static kotlin.KotlinPackage.firstOrNull;
|
import static kotlin.KotlinPackage.firstOrNull;
|
||||||
|
|
||||||
public class InlineUtil {
|
public class InlineUtil {
|
||||||
public static boolean isInlineLambdaParameter(@NotNull CallableDescriptor valueParameterOrReceiver) {
|
public static boolean isInlineLambdaParameter(@NotNull ParameterDescriptor valueParameterOrReceiver) {
|
||||||
JetType type = valueParameterOrReceiver.getOriginal().getReturnType();
|
return !KotlinBuiltIns.isNoinline(valueParameterOrReceiver) &&
|
||||||
return type != null &&
|
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(valueParameterOrReceiver.getOriginal().getType());
|
||||||
!KotlinBuiltIns.isNoinline(valueParameterOrReceiver) &&
|
|
||||||
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInline(@Nullable DeclarationDescriptor descriptor) {
|
public static boolean isInline(@Nullable DeclarationDescriptor descriptor) {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.descriptors;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
|
|
||||||
|
public interface ParameterDescriptor extends CallableDescriptor {
|
||||||
|
@NotNull
|
||||||
|
JetType getType();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
DeclarationDescriptor getContainingDeclaration();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
ParameterDescriptor getOriginal();
|
||||||
|
}
|
||||||
+1
-9
@@ -19,25 +19,17 @@ package org.jetbrains.kotlin.descriptors;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||||
|
|
||||||
public interface ReceiverParameterDescriptor extends CallableDescriptor {
|
public interface ReceiverParameterDescriptor extends ParameterDescriptor {
|
||||||
|
|
||||||
// This field exists for better readability of the client code
|
// This field exists for better readability of the client code
|
||||||
@Nullable
|
@Nullable
|
||||||
ReceiverParameterDescriptor NO_RECEIVER_PARAMETER = null;
|
ReceiverParameterDescriptor NO_RECEIVER_PARAMETER = null;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
JetType getType();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
ReceiverValue getValue();
|
ReceiverValue getValue();
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
DeclarationDescriptor getContainingDeclaration();
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
ReceiverParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
ReceiverParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.types.JetType;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface ValueParameterDescriptor extends VariableDescriptor {
|
public interface ValueParameterDescriptor extends VariableDescriptor, ParameterDescriptor {
|
||||||
/**
|
/**
|
||||||
* Returns the 0-based index of the value parameter in the parameter list of its containing function.
|
* Returns the 0-based index of the value parameter in the parameter list of its containing function.
|
||||||
*
|
*
|
||||||
@@ -48,10 +48,6 @@ public interface ValueParameterDescriptor extends VariableDescriptor {
|
|||||||
|
|
||||||
@Nullable JetType getVarargElementType();
|
@Nullable JetType getVarargElementType();
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
JetType getType();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
ValueParameterDescriptor getOriginal();
|
ValueParameterDescriptor getOriginal();
|
||||||
|
|||||||
+1
-1
@@ -106,7 +106,7 @@ public abstract class AbstractReceiverParameterDescriptor extends DeclarationDes
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public CallableDescriptor getOriginal() {
|
public ParameterDescriptor getOriginal() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -21,10 +21,7 @@ import com.google.gwt.dev.js.ThrowExceptionOnErrorReporter;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
|
||||||
import org.jetbrains.kotlin.js.parser.ParserPackage;
|
import org.jetbrains.kotlin.js.parser.ParserPackage;
|
||||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||||
@@ -83,7 +80,8 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor instanceof ValueParameterDescriptor) {
|
if (descriptor instanceof ValueParameterDescriptor) {
|
||||||
return InlineUtil.isInline(descriptor.getContainingDeclaration()) && InlineUtil.isInlineLambdaParameter(descriptor);
|
return InlineUtil.isInline(descriptor.getContainingDeclaration()) &&
|
||||||
|
InlineUtil.isInlineLambdaParameter((ParameterDescriptor) descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user