Minor, remove duplicate method in ExpressionCodegen

This commit is contained in:
Alexander Udalov
2014-09-02 14:55:15 +04:00
parent 937404239e
commit 8c781e5d14
3 changed files with 16 additions and 29 deletions
@@ -339,13 +339,17 @@ public class AsmUtil {
}
}
public static void genThrow(@NotNull MethodVisitor mv, @NotNull String exception, @NotNull String message) {
InstructionAdapter iv = new InstructionAdapter(mv);
iv.anew(Type.getObjectType(exception));
iv.dup();
iv.aconst(message);
iv.invokespecial(exception, "<init>", "(Ljava/lang/String;)V", false);
iv.athrow();
public static void genThrow(@NotNull InstructionAdapter v, @NotNull String exception, @Nullable String message) {
v.anew(Type.getObjectType(exception));
v.dup();
if (message != null) {
v.aconst(message);
v.invokespecial(exception, "<init>", "(Ljava/lang/String;)V", false);
}
else {
v.invokespecial(exception, "<init>", "()V", false);
}
v.athrow();
}
public static void genClosureFields(CalculatedClosure closure, ClassBuilder v, JetTypeMapper typeMapper) {
@@ -3650,9 +3650,9 @@ The "returned" value of try expression with no finally is either the last expres
v.ifnonnull(nonnull);
JetType leftType = bindingContext.get(EXPRESSION_TYPE, left);
assert leftType != null;
throwNewException("kotlin/TypeCastException", DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(leftType) +
" cannot be cast to " +
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(rightType));
genThrow(v, "kotlin/TypeCastException", DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(leftType) +
" cannot be cast to " +
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(rightType));
v.mark(nonnull);
}
}
@@ -3812,7 +3812,7 @@ The "returned" value of try expression with no finally is either the last expres
) {
if (Boolean.TRUE.equals(bindingContext.get(BindingContext.EXHAUSTIVE_WHEN, expression))) {
// when() is supposed to be exhaustive
throwNewException("kotlin/NoWhenBranchMatchedException");
genThrow(v, "kotlin/NoWhenBranchMatchedException", null);
}
else {
// non-exhaustive when() with no else -> Unit must be expected
@@ -3854,23 +3854,6 @@ The "returned" value of try expression with no finally is either the last expres
return false;
}
private void throwNewException(@NotNull String className) {
throwNewException(className, null);
}
private void throwNewException(@NotNull String className, @Nullable String message) {
v.anew(Type.getObjectType(className));
v.dup();
if (message != null) {
v.visitLdcInsn(message);
v.invokespecial(className, "<init>", "(Ljava/lang/String;)V", false);
}
else {
v.invokespecial(className, "<init>", "()V", false);
}
v.athrow();
}
private Call makeFakeCall(ReceiverValue initializerAsReceiver) {
JetSimpleNameExpression fake = JetPsiFactory(state.getProject()).createSimpleName("fake");
return CallMaker.makeCall(fake, initializerAsReceiver);
@@ -565,7 +565,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
MethodVisitor mv = v.newMethod(NO_ORIGIN, access, name, desc, null, null);
if (descriptor.getKind() != ClassKind.TRAIT) {
mv.visitCode();
genThrow(mv, "java/lang/UnsupportedOperationException", "Mutating immutable collection");
genThrow(new InstructionAdapter(mv), "java/lang/UnsupportedOperationException", "Mutating immutable collection");
FunctionCodegen.endVisit(mv, "built-in stub for " + name + desc, null);
}
}