Cleanup in js modules
This commit is contained in:
+2
-2
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import java.util.ArrayList
|
||||
|
||||
public fun CallArgumentTranslator.ArgumentsInfo.argsWithReceiver(receiver: JsExpression): List<JsExpression> {
|
||||
val allArguments = ArrayList<JsExpression>(1 + reifiedArguments.size() + valueArguments.size())
|
||||
val allArguments = ArrayList<JsExpression>(1 + reifiedArguments.size + valueArguments.size)
|
||||
allArguments.addAll(reifiedArguments)
|
||||
allArguments.add(receiver)
|
||||
allArguments.addAll(valueArguments)
|
||||
@@ -165,7 +165,7 @@ object InvokeIntrinsic : FunctionCallCase() {
|
||||
val callableDescriptor = callInfo.callableDescriptor
|
||||
if (callableDescriptor.getName() != OperatorNameConventions.INVOKE)
|
||||
return false
|
||||
val parameterCount = callableDescriptor.getValueParameters().size()
|
||||
val parameterCount = callableDescriptor.getValueParameters().size
|
||||
val funDeclaration = callableDescriptor.getContainingDeclaration()
|
||||
|
||||
val reflectionTypes = callInfo.context.getReflectionTypes()
|
||||
|
||||
@@ -82,7 +82,7 @@ public fun UsageTracker.getNameForCapturedDescriptor(descriptor: DeclarationDesc
|
||||
public fun UsageTracker.hasCapturedExceptContaining(): Boolean {
|
||||
val hasNotCaptured =
|
||||
capturedDescriptorToJsName.isEmpty() ||
|
||||
(capturedDescriptorToJsName.size() == 1 && capturedDescriptorToJsName.containsKey(containingDescriptor))
|
||||
(capturedDescriptorToJsName.size == 1 && capturedDescriptorToJsName.containsKey(containingDescriptor))
|
||||
|
||||
return !hasNotCaptured
|
||||
}
|
||||
|
||||
+4
-4
@@ -180,7 +180,7 @@ public class ClassTranslator private constructor(
|
||||
if (supertypes.isEmpty()) {
|
||||
return emptyList()
|
||||
}
|
||||
if (supertypes.size() == 1) {
|
||||
if (supertypes.size == 1) {
|
||||
val type = supertypes.get(0)
|
||||
val supertypeDescriptor = getClassDescriptorForType(type)
|
||||
return listOf<JsExpression>(getClassReference(supertypeDescriptor))
|
||||
@@ -232,9 +232,9 @@ public class ClassTranslator private constructor(
|
||||
}
|
||||
|
||||
private fun generateBridgesToTraitImpl(properties: MutableList<JsPropertyInitializer>) {
|
||||
for (entry in CodegenUtil.getNonPrivateTraitMethods(descriptor).entrySet()) {
|
||||
if (!areNamesEqual(entry.getKey(), entry.getValue())) {
|
||||
properties.add(generateDelegateCall(entry.getValue(), entry.getKey(), JsLiteral.THIS, context()))
|
||||
for (entry in CodegenUtil.getNonPrivateTraitMethods(descriptor).entries) {
|
||||
if (!areNamesEqual(entry.key, entry.value)) {
|
||||
properties.add(generateDelegateCall(entry.value, entry.key, JsLiteral.THIS, context()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@ public class DelegationTranslator(
|
||||
val jsFunction = JsFunction(context().getScopeForDescriptor(setterDescriptor.getContainingDeclaration()),
|
||||
"setter for " + setterDescriptor.getName().asString())
|
||||
|
||||
assert(setterDescriptor.getValueParameters().size() == 1) { "Setter must have 1 parameter" }
|
||||
assert(setterDescriptor.getValueParameters().size == 1) { "Setter must have 1 parameter" }
|
||||
val defaultParameter = JsParameter(jsFunction.getScope().declareTemporary())
|
||||
val defaultParameterRef = defaultParameter.getName().makeRef()
|
||||
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ private class PropertyTranslator(
|
||||
val containingScope = context().getScopeForDescriptor(setterDescriptor.getContainingDeclaration())
|
||||
val function = JsFunction(containingScope, JsBlock(), accessorDescription(setterDescriptor))
|
||||
|
||||
assert(setterDescriptor.getValueParameters().size() == 1) { "Setter must have 1 parameter" }
|
||||
assert(setterDescriptor.getValueParameters().size == 1) { "Setter must have 1 parameter" }
|
||||
val correspondingPropertyName = setterDescriptor.getCorrespondingProperty().getName().asString()
|
||||
val valueParameter = function.addParameter(correspondingPropertyName).getName()
|
||||
val withAliased = context().innerContextWithAliased(setterDescriptor.getValueParameters().get(0), valueParameter.makeRef())
|
||||
|
||||
@@ -44,7 +44,7 @@ public class InlineMetadata(val tag: JsStringLiteral, val function: JsFunction)
|
||||
if (Namer.CREATE_INLINE_FUNCTION != call.getQualifier()) return null
|
||||
|
||||
val arguments = call.getArguments()
|
||||
if (arguments.size() != METADATA_PROPERTIES_COUNT) return null
|
||||
if (arguments.size != METADATA_PROPERTIES_COUNT) return null
|
||||
|
||||
val tag = arguments[0] as? JsStringLiteral
|
||||
val function = arguments[1] as? JsFunction
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public object LongOperationFIF : FunctionIntrinsicFactory {
|
||||
class BaseBinaryIntrinsic(val applyFun: (left: JsExpression, right: JsExpression) -> JsExpression) : FunctionIntrinsic() {
|
||||
override fun apply(receiver: JsExpression?, arguments: List<JsExpression>, context: TranslationContext): JsExpression {
|
||||
assert(receiver != null)
|
||||
assert(arguments.size() == 1)
|
||||
assert(arguments.size == 1)
|
||||
return applyFun(receiver!!, arguments.get(0))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public object NumberAndCharConversionFIF : CompositeFIF() {
|
||||
class ConversionUnaryIntrinsic(val applyFun: (receiver: JsExpression) -> JsExpression) : FunctionIntrinsic() {
|
||||
override fun apply(receiver: JsExpression?, arguments: List<JsExpression>, context: TranslationContext): JsExpression {
|
||||
assert(receiver != null)
|
||||
assert(arguments.size() == 0)
|
||||
assert(arguments.size == 0)
|
||||
return applyFun(receiver!!)
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -61,7 +61,7 @@ public class CallArgumentTranslator private constructor(
|
||||
private val isNativeFunctionCall = AnnotationsUtils.isNativeObject(resolvedCall.getCandidateDescriptor())
|
||||
|
||||
private fun removeLastUndefinedArguments(result: MutableList<JsExpression>) {
|
||||
var i = result.size() - 1
|
||||
var i = result.size - 1
|
||||
|
||||
while (i >= 0) {
|
||||
if (result.get(i) != context().namer().getUndefinedExpression()) {
|
||||
@@ -70,7 +70,7 @@ public class CallArgumentTranslator private constructor(
|
||||
i--
|
||||
}
|
||||
|
||||
result.subList(i + 1, result.size()).clear()
|
||||
result.subList(i + 1, result.size).clear()
|
||||
}
|
||||
|
||||
private fun translate(): ArgumentsInfo {
|
||||
@@ -81,7 +81,7 @@ public class CallArgumentTranslator private constructor(
|
||||
var hasSpreadOperator = false
|
||||
var cachedReceiver: TemporaryConstVariable? = null
|
||||
|
||||
var result: MutableList<JsExpression> = ArrayList(valueParameters.size())
|
||||
var result: MutableList<JsExpression> = ArrayList(valueParameters.size)
|
||||
val valueArgumentsByIndex = resolvedCall.getValueArgumentsByIndex()
|
||||
if (valueArgumentsByIndex == null) {
|
||||
throw IllegalStateException("Failed to arrange value arguments by index: " + resolvedCall.getResultingDescriptor())
|
||||
@@ -101,7 +101,7 @@ public class CallArgumentTranslator private constructor(
|
||||
|
||||
val arguments = actualArgument.getArguments()
|
||||
|
||||
val size = arguments.size()
|
||||
val size = arguments.size
|
||||
var i = 0
|
||||
while (i != size) {
|
||||
if (arguments.get(i).getSpreadElement() != null) {
|
||||
@@ -199,7 +199,7 @@ public class CallArgumentTranslator private constructor(
|
||||
}
|
||||
|
||||
assert(actualArgument is ExpressionValueArgument)
|
||||
assert(valueArguments.size() == 1)
|
||||
assert(valueArguments.size == 1)
|
||||
|
||||
val argumentExpression = valueArguments.get(0).getArgumentExpression()
|
||||
assert(argumentExpression != null)
|
||||
@@ -226,7 +226,7 @@ public class CallArgumentTranslator private constructor(
|
||||
|
||||
val list: MutableList<JsExpression>
|
||||
if (shouldWrapVarargInArray) {
|
||||
list = if (arguments.size() == 1) SmartList<JsExpression>() else ArrayList<JsExpression>(arguments.size())
|
||||
list = if (arguments.size == 1) SmartList<JsExpression>() else ArrayList<JsExpression>(arguments.size)
|
||||
}
|
||||
else {
|
||||
list = result
|
||||
@@ -269,10 +269,10 @@ public class CallArgumentTranslator private constructor(
|
||||
}
|
||||
|
||||
private fun concatArgumentsIfNeeded(concatArguments: List<JsExpression>): JsExpression {
|
||||
assert(concatArguments.size() > 0) { "concatArguments.size should not be 0" }
|
||||
assert(concatArguments.size > 0) { "concatArguments.size should not be 0" }
|
||||
|
||||
if (concatArguments.size() > 1) {
|
||||
return JsInvocation(JsNameRef("concat", concatArguments.get(0)), concatArguments.subList(1, concatArguments.size()))
|
||||
if (concatArguments.size > 1) {
|
||||
return JsInvocation(JsNameRef("concat", concatArguments.get(0)), concatArguments.subList(1, concatArguments.size))
|
||||
|
||||
}
|
||||
else {
|
||||
@@ -281,19 +281,19 @@ public class CallArgumentTranslator private constructor(
|
||||
}
|
||||
|
||||
private fun prepareConcatArguments(arguments: List<ValueArgument>, list: List<JsExpression>): MutableList<JsExpression> {
|
||||
assert(arguments.size() != 0) { "arguments.size should not be 0" }
|
||||
assert(arguments.size() == list.size()) { "arguments.size: " + arguments.size() + " != list.size: " + list.size() }
|
||||
assert(arguments.size != 0) { "arguments.size should not be 0" }
|
||||
assert(arguments.size == list.size) { "arguments.size: " + arguments.size + " != list.size: " + list.size }
|
||||
|
||||
val concatArguments = SmartList<JsExpression>()
|
||||
var lastArrayContent: MutableList<JsExpression> = SmartList()
|
||||
|
||||
val size = arguments.size()
|
||||
val size = arguments.size
|
||||
for (index in 0..size - 1) {
|
||||
val valueArgument = arguments.get(index)
|
||||
val expressionArgument = list.get(index)
|
||||
|
||||
if (valueArgument.getSpreadElement() != null) {
|
||||
if (lastArrayContent.size() > 0) {
|
||||
if (lastArrayContent.size > 0) {
|
||||
concatArguments.add(JsArrayLiteral(lastArrayContent))
|
||||
concatArguments.add(expressionArgument)
|
||||
lastArrayContent = SmartList<JsExpression>()
|
||||
@@ -306,7 +306,7 @@ public class CallArgumentTranslator private constructor(
|
||||
lastArrayContent.add(expressionArgument)
|
||||
}
|
||||
}
|
||||
if (lastArrayContent.size() > 0) {
|
||||
if (lastArrayContent.size > 0) {
|
||||
concatArguments.add(JsArrayLiteral(lastArrayContent))
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ private fun Map<TypeParameterDescriptor, KotlinType>.addReifiedTypeArgsTo(
|
||||
val reifiedTypeArguments = SmartList<JsExpression>()
|
||||
val patternTranslator = PatternTranslator.newInstance(context)
|
||||
|
||||
for (param in keySet().sortedBy { it.getIndex() }) {
|
||||
for (param in keys.sortedBy { it.getIndex() }) {
|
||||
if (!param.isReified()) continue
|
||||
|
||||
val argumentType = get(param)
|
||||
|
||||
Reference in New Issue
Block a user