Clean code
This commit is contained in:
@@ -21,16 +21,12 @@ import org.jetbrains.org.objectweb.asm.commons.RemappingSignatureAdapter
|
||||
import org.jetbrains.org.objectweb.asm.signature.SignatureReader
|
||||
import org.jetbrains.org.objectweb.asm.signature.SignatureVisitor
|
||||
|
||||
class AsmTypeRemapper(val typeRemapper: TypeRemapper, val isDefaultGeneration: Boolean, val result: InlineResult) : Remapper() {
|
||||
class AsmTypeRemapper(val typeRemapper: TypeRemapper, val result: InlineResult) : Remapper() {
|
||||
override fun map(type: String): String {
|
||||
return typeRemapper.map(type)
|
||||
}
|
||||
|
||||
override fun createRemappingSignatureAdapter(v: SignatureVisitor?): SignatureVisitor {
|
||||
if (isDefaultGeneration) {
|
||||
return super.createRemappingSignatureAdapter(v)
|
||||
}
|
||||
|
||||
return object : RemappingSignatureAdapter(v, this) {
|
||||
override fun visitTypeVariable(name: String) {
|
||||
/*TODO try to erase absent type variable*/
|
||||
|
||||
@@ -26,7 +26,7 @@ class RootInliningContext(
|
||||
val callElement: KtElement,
|
||||
override val callSiteInfo: InlineCallSiteInfo,
|
||||
val reifiedTypeInliner: ReifiedTypeInliner,
|
||||
val typeParameterMappings: TypeParameterMappings
|
||||
typeParameterMappings: TypeParameterMappings
|
||||
) : InliningContext(
|
||||
null, expressionMap, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), null, false
|
||||
)
|
||||
@@ -76,12 +76,10 @@ open class InliningContext(
|
||||
generator: NameGenerator,
|
||||
newTypeMappings: MutableMap<String, String>,
|
||||
callSiteInfo: InlineCallSiteInfo
|
||||
): InliningContext {
|
||||
return RegeneratedClassContext(
|
||||
this, expressionMap, state, generator, TypeRemapper.createFrom(typeRemapper, newTypeMappings),
|
||||
lambdaInfo, callSiteInfo
|
||||
)
|
||||
}
|
||||
): InliningContext = RegeneratedClassContext(
|
||||
this, expressionMap, state, generator, TypeRemapper.createFrom(typeRemapper, newTypeMappings),
|
||||
lambdaInfo, callSiteInfo
|
||||
)
|
||||
|
||||
@JvmOverloads
|
||||
fun subInline(
|
||||
@@ -89,7 +87,6 @@ open class InliningContext(
|
||||
additionalTypeMappings: Map<String, String?> = emptyMap(),
|
||||
lambdaInfo: LambdaInfo? = this.lambdaInfo
|
||||
): InliningContext {
|
||||
//isInliningLambda && !this.isInliningLambda for root inline lambda
|
||||
val isInliningLambda = lambdaInfo != null
|
||||
return InliningContext(
|
||||
this, expressionMap, state, generator,
|
||||
|
||||
@@ -123,7 +123,7 @@ class MethodInliner(
|
||||
resultNode.access,
|
||||
resultNode.desc,
|
||||
resultNode,
|
||||
AsmTypeRemapper(remapper, inliningContext.root.typeParameterMappings == null, result)
|
||||
AsmTypeRemapper(remapper, result)
|
||||
)
|
||||
|
||||
val markerShift = InlineCodegenUtil.calcMarkerShift(parameters, node)
|
||||
@@ -231,8 +231,7 @@ class MethodInliner(
|
||||
else if (isAnonymousConstructorCall(owner, name)) { //TODO add method
|
||||
//TODO add proper message
|
||||
assert(transformationInfo is AnonymousObjectTransformationInfo) {
|
||||
"<init> call doesn't correspond to object transformation info: " +
|
||||
owner + "." + name + ", info " + transformationInfo
|
||||
"<init> call doesn't correspond to object transformation info for '$owner.$name': $transformationInfo"
|
||||
}
|
||||
val parent = inliningContext.parent
|
||||
val shouldRegenerate = transformationInfo!!.shouldRegenerate(isSameModule)
|
||||
@@ -258,7 +257,7 @@ class MethodInliner(
|
||||
|
||||
//TODO: add new inner class also for other contexts
|
||||
if (inliningContext.parent is RegeneratedClassContext) {
|
||||
inliningContext.parent!!.typeRemapper.addAdditionalMappings(
|
||||
inliningContext.parent.typeRemapper.addAdditionalMappings(
|
||||
transformationInfo!!.oldClassName, transformationInfo!!.newClassName
|
||||
)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ abstract class ObjectTransformer<out T : TransformationInfo>(@JvmField val trans
|
||||
|
||||
return RemappingClassBuilder(
|
||||
classBuilder,
|
||||
AsmTypeRemapper(inliningContext.typeRemapper, inliningContext.root.typeParameterMappings == null, transformationResult)
|
||||
AsmTypeRemapper(inliningContext.typeRemapper, transformationResult)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ class TypeParameter(val oldName: String, val newName: String?, val isReified: Bo
|
||||
//typeMapping data could be changed outside through method processing
|
||||
class TypeRemapper private constructor(
|
||||
private val typeMapping: MutableMap<String, String>,
|
||||
val parent: TypeRemapper?,
|
||||
val isInlineLambda: Boolean = false
|
||||
val parent: TypeRemapper? = null,
|
||||
val isRootInlineLambda: Boolean = false
|
||||
) {
|
||||
private var additionalMappings: MutableMap<String, String> = hashMapOf()
|
||||
private val typeParametersMapping: MutableMap<String, TypeParameter> = hashMapOf()
|
||||
private var additionalMappings = hashMapOf<String, String>()
|
||||
private val typeParametersMapping = hashMapOf<String, TypeParameter>()
|
||||
|
||||
fun addMapping(type: String, newType: String) {
|
||||
typeMapping.put(type, newType)
|
||||
@@ -59,13 +59,13 @@ class TypeRemapper private constructor(
|
||||
}
|
||||
|
||||
fun mapTypeParameter(name: String): TypeParameter? {
|
||||
return typeParametersMapping[name] ?: if (!isInlineLambda) parent?.mapTypeParameter(name) else null
|
||||
return typeParametersMapping[name] ?: if (!isRootInlineLambda) parent?.mapTypeParameter(name) else null
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun createRoot(formalTypeParameters: TypeParameterMappings?): TypeRemapper {
|
||||
return TypeRemapper(HashMap<String, String>(), null).apply {
|
||||
return TypeRemapper(HashMap<String, String>()).apply {
|
||||
formalTypeParameters?.forEach {
|
||||
registerTypeParameter(it)
|
||||
}
|
||||
@@ -74,13 +74,13 @@ class TypeRemapper private constructor(
|
||||
|
||||
@JvmStatic
|
||||
fun createFrom(mappings: MutableMap<String, String>): TypeRemapper {
|
||||
return TypeRemapper(mappings, null)
|
||||
return TypeRemapper(mappings)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun createFrom(remapper: TypeRemapper, mappings: Map<String, String?>, isInlineLambda: Boolean = false): TypeRemapper {
|
||||
return TypeRemapper(createNewAndMerge(remapper, mappings), remapper, isInlineLambda)
|
||||
fun createFrom(parentRemapper: TypeRemapper, mappings: Map<String, String?>, isRootInlineLambda: Boolean = false): TypeRemapper {
|
||||
return TypeRemapper(createNewAndMerge(parentRemapper, mappings), parentRemapper, isRootInlineLambda)
|
||||
}
|
||||
|
||||
private fun createNewAndMerge(remapper: TypeRemapper, additionalTypeMappings: Map<String, String?>): MutableMap<String, String> {
|
||||
|
||||
Reference in New Issue
Block a user