AnonymousObjectRegenerationInfo java->kotlin convertion

This commit is contained in:
Michael Bogdanov
2016-03-11 14:05:06 +03:00
parent da76bf7b03
commit ddd992d3dd
@@ -14,127 +14,57 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.codegen.inline; package org.jetbrains.kotlin.codegen.inline
import org.jetbrains.annotations.NotNull; import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.Type;
import java.util.HashMap; import java.util.HashMap
import java.util.List;
import java.util.Map;
public class AnonymousObjectRegenerationInfo extends RegenerationInfo { class AnonymousObjectRegenerationInfo internal constructor(
private val ownerInternalName: String,
private val needReification: Boolean,
val lambdasToInline: Map<Int, LambdaInfo>,
private val capturedOuterRegenerated: Boolean,
private val alreadyRegenerated: Boolean,
val constructorDesc: String?,
private val isStaticOrigin: Boolean) : RegenerationInfo() {
private final String ownerInternalName; private var newLambdaType: Type? = null
private final String constructorDesc; var newConstructorDescriptor: String? = null
private final Map<Integer, LambdaInfo> lambdasToInline; var allRecapturedParameters: List<CapturedParamDesc>? = null
private Type newLambdaType; var capturedLambdasToInline: Map<String, LambdaInfo>? = null
private String newConstructorDescriptor; constructor(
ownerInternalName: String, needReification: Boolean,
private List<CapturedParamDesc> allRecapturedParameters; alreadyRegenerated: Boolean,
isStaticOrigin: Boolean) : this(
private Map<String, LambdaInfo> capturedLambdasToInline;
private final boolean capturedOuterRegenerated;
private final boolean needReification;
private final boolean alreadyRegenerated;
private final boolean isStaticOrigin;
AnonymousObjectRegenerationInfo(
@NotNull String ownerInternalName,
boolean needReification,
@NotNull Map<Integer, LambdaInfo> lambdasToInline,
boolean capturedOuterRegenerated,
boolean alreadyRegenerated,
@Nullable String constructorDesc,
boolean isStaticOrigin
) {
this.ownerInternalName = ownerInternalName;
this.constructorDesc = constructorDesc;
this.lambdasToInline = lambdasToInline;
this.capturedOuterRegenerated = capturedOuterRegenerated;
this.needReification = needReification;
this.alreadyRegenerated = alreadyRegenerated;
this.isStaticOrigin = isStaticOrigin;
}
public AnonymousObjectRegenerationInfo(
@NotNull String ownerInternalName, boolean needReification,
boolean alreadyRegenerated,
boolean isStaticOrigin
) {
this(
ownerInternalName, needReification, ownerInternalName, needReification,
new HashMap<Integer, LambdaInfo>(), false, alreadyRegenerated, null, isStaticOrigin HashMap<Int, LambdaInfo>(), false, alreadyRegenerated, null, isStaticOrigin) {
);
} }
@NotNull override fun getOldClassName(): String {
@Override return ownerInternalName
public String getOldClassName() {
return ownerInternalName;
} }
@Override override fun shouldRegenerate(sameModule: Boolean): Boolean {
public boolean shouldRegenerate(boolean isSameModule) { return !alreadyRegenerated && (!lambdasToInline.isEmpty() || !sameModule || capturedOuterRegenerated || needReification)
return !alreadyRegenerated && (
!lambdasToInline.isEmpty() || !isSameModule || capturedOuterRegenerated || needReification
);
} }
@Override override fun canRemoveAfterTransformation(): Boolean {
public boolean canRemoveAfterTransformation() {
// Note: It is unsafe to remove anonymous class that is referenced by GETSTATIC within lambda // Note: It is unsafe to remove anonymous class that is referenced by GETSTATIC within lambda
// because it can be local function from outer scope // because it can be local function from outer scope
return !isStaticOrigin; return !isStaticOrigin
} }
public Map<Integer, LambdaInfo> getLambdasToInline() { override fun getNewClassName(): String {
return lambdasToInline; return newLambdaType!!.internalName
} }
@NotNull fun setNewLambdaType(newLambdaType: Type) {
@Override this.newLambdaType = newLambdaType
public String getNewClassName() {
return newLambdaType.getInternalName();
}
public void setNewLambdaType(Type newLambdaType) {
this.newLambdaType = newLambdaType;
}
public String getNewConstructorDescriptor() {
return newConstructorDescriptor;
}
public void setNewConstructorDescriptor(String newConstructorDescriptor) {
this.newConstructorDescriptor = newConstructorDescriptor;
}
public List<CapturedParamDesc> getAllRecapturedParameters() {
return allRecapturedParameters;
}
public void setAllRecapturedParameters(List<CapturedParamDesc> allRecapturedParameters) {
this.allRecapturedParameters = allRecapturedParameters;
}
public Map<String, LambdaInfo> getCapturedLambdasToInline() {
return capturedLambdasToInline;
}
public void setCapturedLambdasToInline(Map<String, LambdaInfo> capturedLambdasToInline) {
this.capturedLambdasToInline = capturedLambdasToInline;
}
@Nullable
public String getConstructorDesc() {
return constructorDesc;
} }
} }