From 68f93762425a4efcfb91e838661f6a02796a8999 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Mon, 24 Feb 2014 13:59:16 +0400 Subject: [PATCH] Fixes java.lang.Comparable interface --- .../teavm/classlib/java/lang/ClassNativeGenerator.java | 9 +++++---- .../java/org/teavm/classlib/java/lang/TComparable.java | 2 +- .../main/java/org/teavm/classlib/java/util/TArrays.java | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java index 868424c18..250be112b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java @@ -137,11 +137,12 @@ public class ClassNativeGenerator implements Generator, Injector, DependencyPlug writer.outdent().append("}").softNewLine(); writer.append("var cls = " + self + ".$data;").softNewLine(); writer.append("var ctor = cls.$$constructor$$;").softNewLine(); - writer.append("if (ctor === null) {").indent().softNewLine(); - writer.append("var ex = new ").appendClass(InstantiationException.class.getName()).append("();"); + writer.append("if (!ctor) {").indent().softNewLine(); + /*writer.append("var ex = new ").appendClass(InstantiationException.class.getName()).append("();").softNewLine(); writer.appendMethodBody(new MethodReference(InstantiationException.class.getName(), new MethodDescriptor( - "", ValueType.VOID))).append("(ex);").softNewLine(); - writer.append("$rt_throw(ex);").softNewLine(); + "", ValueType.VOID))).append("(ex);").softNewLine();*/ + //writer.append("$rt_throw(ex);").softNewLine(); + writer.append("return null;").softNewLine(); writer.outdent().append("}").softNewLine(); writer.append("var instance = new cls();").softNewLine(); writer.append("ctor(instance);").softNewLine(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TComparable.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TComparable.java index 385181776..c56236365 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TComparable.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TComparable.java @@ -19,6 +19,6 @@ package org.teavm.classlib.java.lang; * * @author Alexey Andreev */ -public interface TComparable> { +public interface TComparable { int compareTo(T other); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java index 10598dd18..e968d6779 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java @@ -196,9 +196,9 @@ public class TArrays extends TObject { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public int compare(Object o1, Object o2) { if (o1 != null) { - return ((TComparable)o1).compareTo((TComparable)o2); + return ((TComparable)o1).compareTo(o2); } else if (o2 != null) { - return ((TComparable)o2).compareTo((TComparable)o1); + return ((TComparable)o2).compareTo(o1); } else { return 0; }