code cleanup for JS modules

This commit is contained in:
Dmitry Jemerov
2015-07-20 18:03:05 +02:00
parent 973fa21fe9
commit 3718a7dd44
23 changed files with 34 additions and 34 deletions
@@ -30,6 +30,6 @@ public enum class PredefinedAnnotation(fqName: String) {
companion object {
// TODO: replace with straight assignment when KT-5761 will be fixed
val WITH_CUSTOM_NAME by Delegates.lazy { setOf(LIBRARY, NATIVE) }
val WITH_CUSTOM_NAME by lazy { setOf(LIBRARY, NATIVE) }
}
}
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
import kotlin.properties.Delegates
private val DIAGNOSTIC_FACTORY_TO_RENDERER by Delegates.lazy {
private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
with(DiagnosticFactoryToRendererMap()) {
put(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN,
@@ -324,7 +324,7 @@ class ExpressionDecomposer private constructor(
private inner class Temporary(val value: JsExpression? = null) {
val name: JsName = scope.declareTemporary()
val variable: JsVars by Delegates.lazy {
val variable: JsVars by lazy {
newVar(name, value)
}
@@ -74,13 +74,13 @@ private constructor(
var thisReplacement = getThisReplacement(call)
if (thisReplacement == null || thisReplacement is JsLiteral.JsThisRef) return
if (thisReplacement!!.needToAlias()) {
if (thisReplacement.needToAlias()) {
val thisName = namingContext.getFreshName(getThisAlias())
namingContext.newVar(thisName, thisReplacement)
thisReplacement = thisName.makeRef()
}
replaceThisReference(body, thisReplacement!!)
replaceThisReference(body, thisReplacement)
}
private fun removeStatementsAfterTopReturn() {
@@ -97,7 +97,7 @@ private fun isNameInitialized(
val expr = (lastThenStmt as? JsExpressionStatement)?.getExpression()
if (expr !is JsBinaryOperation) return false
val op = expr.getOperator()!!
val op = expr.getOperator()
if (!op.isAssignment()) return false
val arg1 = expr.getArg1()
@@ -121,7 +121,7 @@ abstract class FunctionContext(
/** in case 4, 5 get ref (reduce 4, 5 to 2, 3 accordingly) */
if (callQualifier is JsNameRef) {
val staticRef = (callQualifier as JsNameRef).getName()?.staticRef
val staticRef = callQualifier.getName()?.staticRef
callQualifier = when (staticRef) {
is JsNameRef -> staticRef
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.js.inline.context
import com.google.dart.compiler.backend.js.ast.JsContext
import com.google.dart.compiler.backend.js.ast.JsStatement
trait InliningContext {
interface InliningContext {
public val statementContext: JsContext<JsStatement>
public val functionContext: FunctionContext
@@ -47,14 +47,14 @@ public fun getSimpleIdent(call: JsInvocation): String? {
qualifiers@ while (qualifier != null) {
when (qualifier) {
is JsInvocation -> {
val callableQualifier = qualifier as JsInvocation
val callableQualifier = qualifier
qualifier = callableQualifier.getQualifier()
if (isCallInvocation(callableQualifier)) {
qualifier = (qualifier as? JsNameRef)?.getQualifier()
}
}
is HasName -> return (qualifier as HasName).getName()?.getIdent()
is HasName -> return qualifier.getName()?.getIdent()
else -> break@qualifiers
}
}
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.serialization.DescriptorSerializer
import org.jetbrains.kotlin.serialization.ProtoBuf
public object ClassSerializationUtil {
public trait Sink {
public interface Sink {
fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class)
}
@@ -32,7 +32,7 @@ import com.google.dart.compiler.backend.js.ast.JsLiteral
import com.google.dart.compiler.backend.js.ast.JsConditional
import com.google.dart.compiler.backend.js.ast.JsBlock
trait CallInfo {
interface CallInfo {
val context: TranslationContext
val resolvedCall: ResolvedCall<out CallableDescriptor>
@@ -87,7 +87,7 @@ fun TranslationContext.getCallInfo(resolvedCall: ResolvedCall<out FunctionDescri
var receiverRef = explicitReceivers.extensionReceiver
if (receiverRef != null) {
receiverRef = this.declareTemporary(null).reference()
this.addStatementToCurrentBlock(JsAstUtils.assignment(receiverRef!!, explicitReceivers.extensionReceiver!!).makeStmt())
this.addStatementToCurrentBlock(JsAstUtils.assignment(receiverRef, explicitReceivers.extensionReceiver!!).makeStmt())
}
ExplicitReceivers(receiverOrThisRef, receiverRef)
}
@@ -138,11 +138,11 @@ private fun TranslationContext.createCallInfo(resolvedCall: ResolvedCall<out Cal
when (resolvedCall.getExplicitReceiverKind()) {
BOTH_RECEIVERS, EXTENSION_RECEIVER -> {
notNullConditional = TranslationUtils.notNullConditional(extensionReceiver!!, JsLiteral.NULL, this)
extensionReceiver = notNullConditional!!.getThenExpression()
extensionReceiver = notNullConditional.getThenExpression()
}
else -> {
notNullConditional = TranslationUtils.notNullConditional(dispatchReceiver!!, JsLiteral.NULL, this)
dispatchReceiver = notNullConditional!!.getThenExpression()
dispatchReceiver = notNullConditional.getThenExpression()
}
}
}
@@ -59,7 +59,7 @@ fun VariableAccessInfo.getAccessFunctionName(): String {
return context.getNameForDescriptor(propertyAccessorDescriptor!!).getIdent()
}
else {
return Namer.getNameForAccessor(variableName.getIdent()!!, isGetAccess(), false)
return Namer.getNameForAccessor(variableName.getIdent(), isGetAccess(), false)
}
}
@@ -154,7 +154,7 @@ fun computeExplicitReceiversForInvoke(
}
}
trait CallCase<I : CallInfo> {
interface CallCase<I : CallInfo> {
protected fun I.unsupported(message: String = "") : Nothing = throw IllegalStateException("this case unsupported. $this")
@@ -183,11 +183,11 @@ trait CallCase<I : CallInfo> {
}
}
trait FunctionCallCase : CallCase<FunctionCallInfo>
interface FunctionCallCase : CallCase<FunctionCallInfo>
trait VariableAccessCase : CallCase<VariableAccessInfo>
interface VariableAccessCase : CallCase<VariableAccessInfo>
trait DelegateIntrinsic<I : CallInfo> {
interface DelegateIntrinsic<I : CallInfo> {
fun I.canBeApply(): Boolean = true
fun I.getDescriptor(): CallableDescriptor
fun I.getArgs(): List<JsExpression>
@@ -39,7 +39,7 @@ class FileDeclarationVisitor(
private val initializer = JsAstUtils.createFunctionWithEmptyBody(context.scope())
private val initializerContext = context.contextWithScope(initializer)
private val initializerStatements = initializer.getBody()!!.getStatements()!!
private val initializerStatements = initializer.getBody().getStatements()
private val initializerVisitor = InitializerVisitor(initializerStatements)
fun computeInitializer(): JsFunction? {
@@ -82,7 +82,7 @@ public class MultiDeclarationTranslator extends AbstractTranslator {
for (JetMultiDeclarationEntry entry : multiDeclaration.getEntries()) {
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
assert entryInitCall != null : "Entry init call must be not null";
JsExpression entryInitializer = CallTranslator.INSTANCE$.translate(context(), entryInitCall, multiObjNameRef);
JsExpression entryInitializer = CallTranslator.translate(context(), entryInitCall, multiObjNameRef);
FunctionDescriptor candidateDescriptor = entryInitCall.getCandidateDescriptor();
if (CallExpressionTranslator.shouldBeInlined(candidateDescriptor)) {
setInlineCallMetadata(entryInitializer, entry, entryInitCall, context());
@@ -46,7 +46,7 @@ public class ObjectIntrinsics {
}
}
public trait ObjectIntrinsic {
public interface ObjectIntrinsic {
fun apply(context: TranslationContext): JsExpression
fun exists(): Boolean = true
}
@@ -26,7 +26,7 @@ import gnu.trove.THashMap
import com.google.dart.compiler.backend.js.ast.JsExpression
import com.google.common.collect.ImmutableSet
public trait BinaryOperationIntrinsic {
public interface BinaryOperationIntrinsic {
fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression
@@ -71,7 +71,7 @@ public class BinaryOperationIntrinsics {
}
}
trait BinaryOperationIntrinsicFactory {
interface BinaryOperationIntrinsicFactory {
public fun getSupportTokens(): ImmutableSet<out JetToken>
@@ -57,6 +57,6 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
@NotNull
private JsExpression overloadedMethodInvocation() {
return CallTranslator.INSTANCE$.translate(context(), resolvedCall, accessTranslator.translateAsGet());
return CallTranslator.translate(context(), resolvedCall, accessTranslator.translateAsGet());
}
}
@@ -42,7 +42,7 @@ public final class OverloadedIncrementTranslator extends IncrementTranslator {
@Override
@NotNull
protected JsExpression operationExpression(@NotNull JsExpression receiver) {
return CallTranslator.INSTANCE$.translate(context(), resolvedCall, receiver);
return CallTranslator.translate(context(), resolvedCall, receiver);
}
}
@@ -82,7 +82,7 @@ public final class UnaryOperationTranslator {
}
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCallWithAssert(expression, context.bindingContext());
return CallTranslator.INSTANCE$.translate(context, resolvedCall, baseExpression);
return CallTranslator.translate(context, resolvedCall, baseExpression);
}
private static boolean isExclForBinaryEqualLikeExpr(@NotNull JetUnaryExpression expression, @NotNull JsExpression baseExpression) {
@@ -82,7 +82,7 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
if (!isGetter) {
context = contextWithValueParameterAliasInArrayGetAccess(toSetTo);
}
return CallTranslator.INSTANCE$.translate(context, resolvedCall, arrayExpression);
return CallTranslator.translate(context, resolvedCall, arrayExpression);
}
@NotNull
@@ -150,14 +150,14 @@ public class CallArgumentTranslator private constructor(
concatArguments!!.addAll(result)
if (!argsBeforeVararg!!.isEmpty()) {
concatArguments!!.add(0, JsArrayLiteral(argsBeforeVararg))
concatArguments.add(0, JsArrayLiteral(argsBeforeVararg))
}
result = SmartList(concatArgumentsIfNeeded(concatArguments!!))
result = SmartList(concatArgumentsIfNeeded(concatArguments))
if (receiver != null) {
cachedReceiver = context().getOrDeclareTemporaryConstVariable(receiver)
result.add(0, cachedReceiver!!.reference())
result.add(0, cachedReceiver.reference())
}
else {
result.add(0, JsLiteral.NULL)
@@ -97,7 +97,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
@NotNull
private JsExpression translate() {
return CallTranslator.INSTANCE$.translate(context(), resolvedCall, receiver);
return CallTranslator.translate(context(), resolvedCall, receiver);
}
@NotNull
@@ -119,7 +119,7 @@ public final class PsiUtils {
@NotNull
public static List<JetParameter> getPrimaryConstructorParameters(@NotNull JetClassOrObject classDeclaration) {
if (classDeclaration instanceof JetClass) {
return ((JetClass) classDeclaration).getPrimaryConstructorParameters();
return classDeclaration.getPrimaryConstructorParameters();
}
return Collections.emptyList();
}