JS: minor, simplify code locating default argument values
At the only call site of getDefaultArgument it is checked that the parameter actually _declares_ default value, so it's not necessary to try to load that value from supertypes
This commit is contained in:
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.kotlin.types.TypeUtils;
|
import org.jetbrains.kotlin.types.TypeUtils;
|
||||||
|
|
||||||
@@ -178,26 +177,12 @@ public final class BindingUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static KtExpression getDefaultArgument(@NotNull ValueParameterDescriptor parameterDescriptor) {
|
public static KtExpression getDefaultArgument(@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||||
ValueParameterDescriptor descriptorWhichDeclaresDefaultValue =
|
KtParameter psiParameter = getParameterForDescriptor(parameterDescriptor);
|
||||||
getOriginalDescriptorWhichDeclaresDefaultValue(parameterDescriptor);
|
|
||||||
KtParameter psiParameter = getParameterForDescriptor(descriptorWhichDeclaresDefaultValue);
|
|
||||||
KtExpression defaultValue = psiParameter.getDefaultValue();
|
KtExpression defaultValue = psiParameter.getDefaultValue();
|
||||||
assert defaultValue != null : message(parameterDescriptor, "No default value found in PSI");
|
assert defaultValue != null : message(parameterDescriptor, "No default value found in PSI");
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ValueParameterDescriptor getOriginalDescriptorWhichDeclaresDefaultValue(
|
|
||||||
@NotNull ValueParameterDescriptor parameterDescriptor
|
|
||||||
) {
|
|
||||||
ValueParameterDescriptor result = parameterDescriptor;
|
|
||||||
assert DescriptorUtilsKt.hasDefaultValue(result) : message(parameterDescriptor, "Unsupplied parameter must have default value");
|
|
||||||
// TODO: this seems incorrect, as the default value may come from _not the first_ overridden parameter
|
|
||||||
while (!result.declaresDefaultValue()) {
|
|
||||||
result = result.getOverriddenDescriptors().iterator().next();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ResolvedCall<FunctionDescriptor> getIteratorFunction(@NotNull BindingContext context,
|
public static ResolvedCall<FunctionDescriptor> getIteratorFunction(@NotNull BindingContext context,
|
||||||
@NotNull KtExpression rangeExpression) {
|
@NotNull KtExpression rangeExpression) {
|
||||||
|
|||||||
+1
-2
@@ -43,7 +43,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getDefaultArgument;
|
|
||||||
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.*;
|
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.*;
|
||||||
import static org.jetbrains.kotlin.js.translate.utils.mutator.LastExpressionMutator.mutateLastExpression;
|
import static org.jetbrains.kotlin.js.translate.utils.mutator.LastExpressionMutator.mutateLastExpression;
|
||||||
|
|
||||||
@@ -84,7 +83,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
|||||||
if (!valueParameter.declaresDefaultValue()) continue;
|
if (!valueParameter.declaresDefaultValue()) continue;
|
||||||
|
|
||||||
JsExpression jsNameRef = ReferenceTranslator.translateAsValueReference(valueParameter, functionBodyContext);
|
JsExpression jsNameRef = ReferenceTranslator.translateAsValueReference(valueParameter, functionBodyContext);
|
||||||
KtExpression defaultArgument = getDefaultArgument(valueParameter);
|
KtExpression defaultArgument = BindingUtils.getDefaultArgument(valueParameter);
|
||||||
JsBlock defaultArgBlock = new JsBlock();
|
JsBlock defaultArgBlock = new JsBlock();
|
||||||
JsExpression defaultValue = Translation.translateAsExpression(defaultArgument, functionBodyContext, defaultArgBlock);
|
JsExpression defaultValue = Translation.translateAsExpression(defaultArgument, functionBodyContext, defaultArgBlock);
|
||||||
PsiElement psi = KotlinSourceElementKt.getPsi(valueParameter.getSource());
|
PsiElement psi = KotlinSourceElementKt.getPsi(valueParameter.getSource());
|
||||||
|
|||||||
Reference in New Issue
Block a user