diff --git a/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java b/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java index 8b3b7b571..024f1a241 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java @@ -156,7 +156,13 @@ public class ObjectMethodsSubstitutor implements BootstrapMethodSubstitutor { private ValueEmitter substituteToString(DynamicCallSite callSite, ProgramEmitter pe) { ValueEmitter thisVar = callSite.getArguments().get(0); String names = callSite.getBootstrapArguments().get(1).getString(); - ValueEmitter resultVar = pe.construct(StringBuilder.class, pe.constant("[")); + String className = ((ValueType.Object) thisVar.getType()).getClassName(); + String simpleName = callSite.getAgent().getClassSource().get(className).getSimpleName(); + if (simpleName == null) { + int idx = className.lastIndexOf('.'); + simpleName = idx >= 0 ? className.substring(idx + 1) : className; + } + ValueEmitter resultVar = pe.construct(StringBuilder.class, pe.constant(simpleName + "[")); int argIndex = 2; int index = 0; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java b/classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java index de808af8d..ad871ab1f 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java @@ -17,7 +17,6 @@ package org.teavm.classlib.java.util; import java.util.Arrays; import org.teavm.classlib.java.io.TSerializable; -import org.teavm.classlib.java.lang.TComparable; import org.teavm.classlib.java.lang.TIllegalArgumentException; import org.teavm.classlib.java.lang.TIllegalStateException; import org.teavm.classlib.java.lang.TNullPointerException; @@ -99,15 +98,7 @@ public class TPriorityQueue<E> extends TAbstractQueue<E> implements TSerializabl private void setComparator(TComparator<? super E> comparator) { this.originalComparator = comparator; if (comparator == null) { - comparator = new TComparator<Object>() { - @Override public int compare(Object o1, Object o2) { - if (o1 instanceof TComparable) { - return ((TComparable<Object>) o1).compareTo(o2); - } else { - return -((TComparable<Object>) o2).compareTo(o1); - } - } - }; + comparator = TComparator.NaturalOrder.instance(); } this.comparator = (TComparator<Object>) comparator; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java b/classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java index f23275f1f..429e50d94 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java @@ -17,7 +17,6 @@ package org.teavm.classlib.java.util; import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.lang.TCloneable; -import org.teavm.classlib.java.lang.TComparable; import org.teavm.classlib.java.lang.TIllegalArgumentException; public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TCloneable, TSerializable, TNavigableMap<K, V> { @@ -105,12 +104,7 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TCloneable, TS public TTreeMap(TComparator<? super K> comparator) { this.originalComparator = comparator; if (comparator == null) { - comparator = new TComparator<Object>() { - @SuppressWarnings("unchecked") @Override public int compare(Object o1, Object o2) { - return o1 != null ? ((TComparable<Object>) o1).compareTo(o2) - : ((TComparable<Object>) o2).compareTo(o1); - } - }; + comparator = TComparator.NaturalOrder.instance(); } this.comparator = comparator; } diff --git a/tests/src/test/java/org/teavm/vm/RecordTest.java b/tests/src/test/java/org/teavm/vm/RecordTest.java index b310a59b7..e0c3a86e9 100644 --- a/tests/src/test/java/org/teavm/vm/RecordTest.java +++ b/tests/src/test/java/org/teavm/vm/RecordTest.java @@ -44,6 +44,10 @@ public class RecordTest { int index = 0; + index = s.indexOf("B", index); + assertTrue(index >= 0); + ++index; + index = s.indexOf("x", index); assertTrue(index > 0); ++index;