Refactor: Remove context parameter from BindingContextUtils.descriptorToDeclaration utilities family
This commit is contained in:
@@ -50,7 +50,7 @@ trait CallInfo {
|
||||
fun constructSafeCallIsNeeded(result: JsExpression): JsExpression
|
||||
|
||||
override fun toString(): String {
|
||||
val location = DiagnosticUtils.atLocation(context.bindingContext(), callableDescriptor)
|
||||
val location = DiagnosticUtils.atLocation(callableDescriptor)
|
||||
val name = callableDescriptor.getName().asString()
|
||||
return "callableDescriptor: $name at $location; thisObject: $thisObject; receiverObject: $receiverObject"
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.config.LibrarySourcesConfig;
|
||||
@@ -37,6 +36,7 @@ import org.jetbrains.k2js.translate.utils.JsAstUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.getNameForAnnotatedObjectWithOverrides;
|
||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.isLibraryObject;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.*;
|
||||
@@ -448,10 +448,9 @@ public final class StaticContext {
|
||||
}
|
||||
|
||||
private String getExternalModuleName(DeclarationDescriptor descriptor) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||
PsiElement element = descriptorToDeclaration(descriptor);
|
||||
if (element == null && descriptor instanceof PropertyAccessorDescriptor) {
|
||||
element = BindingContextUtils.descriptorToDeclaration(bindingContext, ((PropertyAccessorDescriptor) descriptor)
|
||||
.getCorrespondingProperty());
|
||||
element = descriptorToDeclaration(((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty());
|
||||
}
|
||||
|
||||
if (element == null) {
|
||||
|
||||
+1
-2
@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Modality;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression;
|
||||
import org.jetbrains.k2js.translate.context.AliasingContext;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
@@ -70,7 +69,7 @@ public final class FunctionTranslator extends AbstractTranslator {
|
||||
this.functionDeclaration = functionDeclaration;
|
||||
this.functionObject = context().getFunctionObject(descriptor);
|
||||
assert this.functionObject.getParameters().isEmpty()
|
||||
: message(bindingContext(), descriptor, "Function " + functionDeclaration.getText() + " processed for the second time.");
|
||||
: message(descriptor, "Function " + functionDeclaration.getText() + " processed for the second time.");
|
||||
//NOTE: it's important we compute the context before we start the computation
|
||||
this.functionBodyContext = getFunctionBodyContext();
|
||||
}
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public final class InlinedCallExpressionTranslator extends AbstractCallExpressio
|
||||
|
||||
@NotNull
|
||||
private JetFunction getFunctionBody() {
|
||||
return getFunctionForDescriptor(bindingContext(), getFunctionDescriptor());
|
||||
return getFunctionForDescriptor(getFunctionDescriptor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -75,20 +75,16 @@ public final class BindingUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetFunction getFunctionForDescriptor(@NotNull BindingContext context,
|
||||
@NotNull SimpleFunctionDescriptor descriptor) {
|
||||
PsiElement result = BindingContextUtils.callableDescriptorToDeclaration(context, descriptor);
|
||||
assert result instanceof JetFunction
|
||||
: message(context, descriptor, "SimpleFunctionDescriptor should have declaration of type JetFunction");
|
||||
public static JetFunction getFunctionForDescriptor(@NotNull SimpleFunctionDescriptor descriptor) {
|
||||
PsiElement result = BindingContextUtils.callableDescriptorToDeclaration(descriptor);
|
||||
assert result instanceof JetFunction : message(descriptor, "SimpleFunctionDescriptor should have declaration of type JetFunction");
|
||||
return (JetFunction) result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetParameter getParameterForDescriptor(@NotNull BindingContext context,
|
||||
@NotNull ValueParameterDescriptor descriptor) {
|
||||
PsiElement result = BindingContextUtils.descriptorToDeclaration(context, descriptor);
|
||||
assert result instanceof JetParameter :
|
||||
message(context, descriptor, "ValueParameterDescriptor should have corresponding JetParameter");
|
||||
private static JetParameter getParameterForDescriptor(@NotNull ValueParameterDescriptor descriptor) {
|
||||
PsiElement result = BindingContextUtils.descriptorToDeclaration(descriptor);
|
||||
assert result instanceof JetParameter : message(descriptor, "ValueParameterDescriptor should have corresponding JetParameter");
|
||||
return (JetParameter) result;
|
||||
}
|
||||
|
||||
@@ -183,21 +179,20 @@ public final class BindingUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getDefaultArgument(@NotNull BindingContext context,
|
||||
@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||
public static JetExpression getDefaultArgument(@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||
ValueParameterDescriptor descriptorWhichDeclaresDefaultValue =
|
||||
getOriginalDescriptorWhichDeclaresDefaultValue(context, parameterDescriptor);
|
||||
JetParameter psiParameter = getParameterForDescriptor(context, descriptorWhichDeclaresDefaultValue);
|
||||
getOriginalDescriptorWhichDeclaresDefaultValue(parameterDescriptor);
|
||||
JetParameter psiParameter = getParameterForDescriptor(descriptorWhichDeclaresDefaultValue);
|
||||
JetExpression defaultValue = psiParameter.getDefaultValue();
|
||||
assert defaultValue != null : message(context, parameterDescriptor, "No default value found in PSI");
|
||||
assert defaultValue != null : message(parameterDescriptor, "No default value found in PSI");
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static ValueParameterDescriptor getOriginalDescriptorWhichDeclaresDefaultValue(
|
||||
BindingContext context, @NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||
@NotNull ValueParameterDescriptor parameterDescriptor
|
||||
) {
|
||||
ValueParameterDescriptor result = parameterDescriptor;
|
||||
assert result.hasDefaultValue() :
|
||||
message(context, parameterDescriptor, "Unsupplied parameter must have default value");
|
||||
assert result.hasDefaultValue() : message(parameterDescriptor, "Unsupplied parameter must have default value");
|
||||
while (!result.declaresDefaultValue()) {
|
||||
result = result.getOverriddenDescriptors().iterator().next();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
public final class ErrorReportingUtils {
|
||||
private ErrorReportingUtils() {
|
||||
@@ -43,21 +42,12 @@ public final class ErrorReportingUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String message(@NotNull BindingContext context,
|
||||
@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull String explainingMessage) {
|
||||
return explainingMessage + " at " + DiagnosticUtils.atLocation(context, descriptor) + ".";
|
||||
public static String message(@NotNull DeclarationDescriptor descriptor, @NotNull String explainingMessage) {
|
||||
return explainingMessage + " at " + DiagnosticUtils.atLocation(descriptor) + ".";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String message(@NotNull PsiElement element) {
|
||||
return "Error at " + DiagnosticUtils.atLocation(element) + ".";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static RuntimeException reportErrorWithLocation(@NotNull RuntimeException e,
|
||||
@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull BindingContext bindingContext) {
|
||||
throw reportErrorWithLocation(e, DiagnosticUtils.atLocation(bindingContext, descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
for (ValueParameterDescriptor valueParameter : descriptor.getValueParameters()) {
|
||||
if (valueParameter.hasDefaultValue()) {
|
||||
JsNameRef jsNameRef = functionBodyContext.getNameForDescriptor(valueParameter).makeRef();
|
||||
JetExpression defaultArgument = getDefaultArgument(functionBodyContext.bindingContext(), valueParameter);
|
||||
JetExpression defaultArgument = getDefaultArgument(valueParameter);
|
||||
JsExpression defaultValue = Translation.translateAsExpression(defaultArgument, functionBodyContext);
|
||||
|
||||
JsBinaryOperation checkArgIsUndefined = equality(jsNameRef, functionBodyContext.namer().getUndefinedExpression());
|
||||
|
||||
Reference in New Issue
Block a user