refactoring
This commit is contained in:
@@ -34,7 +34,6 @@ public final class FunctionTranslator extends AbstractTranslator {
|
|||||||
return new FunctionTranslator(function, context);
|
return new FunctionTranslator(function, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: implement more generic and safe way
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final JetDeclarationWithBody functionDeclaration;
|
private final JetDeclarationWithBody functionDeclaration;
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -51,16 +50,16 @@ public final class FunctionTranslator extends AbstractTranslator {
|
|||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
super(context);
|
super(context);
|
||||||
this.functionBody = new JsBlock();
|
this.functionBody = new JsBlock();
|
||||||
|
this.descriptor = getFunctionDescriptor(context.bindingContext(), functionDeclaration);
|
||||||
this.functionDeclaration = functionDeclaration;
|
this.functionDeclaration = functionDeclaration;
|
||||||
this.functionObject = createFunctionObject();
|
this.functionObject = createFunctionObject();
|
||||||
this.functionBodyContext = functionBodyContext().innerBlock(functionBody);
|
this.functionBodyContext = functionBodyContext().innerBlock(functionBody);
|
||||||
this.descriptor = getFunctionDescriptor(context.bindingContext(), functionDeclaration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsPropertyInitializer translateAsMethod() {
|
public JsPropertyInitializer translateAsMethod() {
|
||||||
assert functionDeclaration instanceof JetElement;
|
assert functionDeclaration instanceof JetElement;
|
||||||
JsName functionName = context().getNameForElement((JetElement) functionDeclaration);
|
JsName functionName = context().getNameForElement(functionDeclaration);
|
||||||
JsFunction function = generateFunctionObject();
|
JsFunction function = generateFunctionObject();
|
||||||
return new JsPropertyInitializer(functionName.makeRef(), function);
|
return new JsPropertyInitializer(functionName.makeRef(), function);
|
||||||
}
|
}
|
||||||
@@ -103,10 +102,11 @@ public final class FunctionTranslator extends AbstractTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private JsFunction createFunctionObject() {
|
private JsFunction createFunctionObject() {
|
||||||
if (isDeclaration()) {
|
if (isDeclaration()) {
|
||||||
return functionWithScope(context().getScopeForElement(functionDeclaration));
|
return functionWithScope(context().getScopeForDescriptor(descriptor));
|
||||||
}
|
}
|
||||||
if (isLiteral()) {
|
if (isLiteral()) {
|
||||||
//TODO: look into
|
//TODO: changing this piece of code to more natural "same as for declaration" results in life test failing
|
||||||
|
//TODO: must investigate
|
||||||
return new JsFunction(context().jsScope());
|
return new JsFunction(context().jsScope());
|
||||||
}
|
}
|
||||||
throw new AssertionError("Unsupported type of functionDeclaration.");
|
throw new AssertionError("Unsupported type of functionDeclaration.");
|
||||||
@@ -176,7 +176,6 @@ public final class FunctionTranslator extends AbstractTranslator {
|
|||||||
|
|
||||||
private void mayBeAddThisParameterForExtensionFunction(@NotNull List<JsParameter> jsParameters) {
|
private void mayBeAddThisParameterForExtensionFunction(@NotNull List<JsParameter> jsParameters) {
|
||||||
if (isExtensionFunction()) {
|
if (isExtensionFunction()) {
|
||||||
//TODO: don't do this
|
|
||||||
JsName receiver = functionBodyContext.jsScope().declareName(Namer.getReceiverParameterName());
|
JsName receiver = functionBodyContext.jsScope().declareName(Namer.getReceiverParameterName());
|
||||||
DeclarationDescriptor expectedReceiverDescriptor = getExpectedReceiverDescriptor(descriptor);
|
DeclarationDescriptor expectedReceiverDescriptor = getExpectedReceiverDescriptor(descriptor);
|
||||||
assert expectedReceiverDescriptor != null;
|
assert expectedReceiverDescriptor != null;
|
||||||
|
|||||||
Reference in New Issue
Block a user