Skip to content

Commit 21ad6ab

Browse files
committed
SwingJS hack for Spliterator
SwingJS cannot follow an interface call at runtime using captures. Solution was to include tryAdvance(XxxConsumer) explicitly in Spliterators.EmptySpliterator.ofXxx [Int,Long,Double]
1 parent a4efd9a commit 21ad6ab

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

sources/net.sf.j2s.java.core/src/java/util/Spliterator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ default Comparator<? super T> getComparator() {
596596
* @see Spliterator.OfDouble
597597
* @since 1.8
598598
*/
599-
public interface OfPrimitive<T, T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>>
599+
public interface OfPrimitive<T, C, S extends Spliterator.OfPrimitive<T, C, S>>
600600
extends Spliterator<T> {
601601
@Override
602-
T_SPLITR trySplit();
602+
S trySplit();
603603

604604
/**
605605
* If a remaining element exists, performs the given action on it,
@@ -614,7 +614,7 @@ public interface OfPrimitive<T, T_CONS, T_SPLITR extends Spliterator.OfPrimitive
614614
* @throws NullPointerException if the specified action is null
615615
*/
616616
@SuppressWarnings("overloads")
617-
boolean tryAdvance(T_CONS action);
617+
boolean tryAdvance(C action);
618618

619619
/**
620620
* Performs the given action for each remaining element, sequentially in
@@ -632,7 +632,7 @@ public interface OfPrimitive<T, T_CONS, T_SPLITR extends Spliterator.OfPrimitive
632632
* @throws NullPointerException if the specified action is null
633633
*/
634634
@SuppressWarnings("overloads")
635-
default void forEachRemaining(T_CONS action) {
635+
default void forEachRemaining(C action) {
636636
do { } while (tryAdvance(action));
637637
}
638638
}

sources/net.sf.j2s.java.core/src/java/util/Spliterators.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,24 +862,58 @@ private static final class OfRef<T>
862862
extends EmptySpliterator<T, Spliterator<T>, Consumer<? super T>>
863863
implements Spliterator<T> {
864864
OfRef() { }
865+
865866
}
866867

867868
private static final class OfInt
868869
extends EmptySpliterator<Integer, Spliterator.OfInt, IntConsumer>
869870
implements Spliterator.OfInt {
870871
OfInt() { }
872+
873+
/**
874+
* Was necessary for SwingJS
875+
*/
876+
@Override
877+
public boolean tryAdvance(IntConsumer consumer) {
878+
Objects.requireNonNull(consumer);
879+
return false;
880+
}
881+
882+
871883
}
872884

873885
private static final class OfLong
874886
extends EmptySpliterator<Long, Spliterator.OfLong, LongConsumer>
875887
implements Spliterator.OfLong {
876888
OfLong() { }
889+
890+
/**
891+
* Was necessary for SwingJS
892+
*/
893+
@Override
894+
public boolean tryAdvance(LongConsumer consumer) {
895+
Objects.requireNonNull(consumer);
896+
return false;
897+
}
898+
899+
877900
}
878901

879902
private static final class OfDouble
880903
extends EmptySpliterator<Double, Spliterator.OfDouble, DoubleConsumer>
881904
implements Spliterator.OfDouble {
882905
OfDouble() { }
906+
907+
/**
908+
* Was necessary for SwingJS
909+
*/
910+
@Override
911+
public boolean tryAdvance(DoubleConsumer consumer) {
912+
Objects.requireNonNull(consumer);
913+
return false;
914+
}
915+
916+
883917
}
884918
}
885919

0 commit comments

Comments
 (0)