Skip to content

Commit f1aaa9d

Browse files
Martijn Hoekstrajohnynek
authored andcommitted
cross-build for 2.13 (#287)
* rebooting 213 port * bijection-core: cross build 213 * bijection-json split 213 * bijection-util: use Future.apply instead of concurrent.future * bijection-clojure: codegen updated for scalabug 11770 * bijection-json: re-unifiy shared code * bijection-core: unify Bufferable
1 parent d8d37a4 commit f1aaa9d

File tree

30 files changed

+1810
-190
lines changed

30 files changed

+1810
-190
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ matrix:
1010
"++$TRAVIS_SCALA_VERSION clean"
1111
"++$TRAVIS_SCALA_VERSION test"
1212
13-
- name: checks
13+
- scala: 2.13.1
14+
jdk: openjdk8
15+
script:
16+
- >
17+
sbt
18+
"++$TRAVIS_SCALA_VERSION clean"
19+
"++$TRAVIS_SCALA_VERSION test"
20+
21+
- name: scalafmtCheck
1422
scala: 2.12.10
1523
jdk: openjdk8
1624
script: sbt scalafmtCheckAll scalafmtSbtCheck

bijection-clojure/codegen/Generator.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Run this generator like a script:
2-
// scala Generator.scala > ../src/main/scala/com/twitter/bijection/clojure/GeneratedIFnBijections.scala
2+
// scala Generator.scala > ../src/main/scala-2.12-/com/twitter/bijection/clojure/GeneratedIFnBijections.scala
33

44
/*
55
* Example of the code generated:
@@ -46,6 +46,7 @@ def implicitIFn(i: Int): String = {
4646
}
4747

4848
println("// Autogenerated code DO NOT EDIT BY HAND")
49+
println("// Generated by bijection-clojure/codegen/Generator.scala")
4950
println("package com.twitter.bijection.clojure")
5051
println("import clojure.lang.{ AFn, IFn }")
5152
println("import com.twitter.bijection.{ AbstractBijection, Bijection, CastInjection }")
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// This is a generator for java methods to forward to, as a workaround for
2+
// scala bug#11770
3+
//
4+
// Run this generator like a script:
5+
// scala GeneratorWorkaroundJava.scala > ../src/main/scala-2.13+/com/twitter/bijection/clojure/Workaround11770.java
6+
7+
def conversionN(n: Int) = {
8+
val intypes = (1 to n).map(i => "I" + i.toString).toList
9+
val invalues = intypes.map(_.toLowerCase)
10+
val intv = intypes.zip(invalues).map{ case (t, v) => s"$t $v"}
11+
val inobjv = invalues.map(v => s"Object $v")
12+
val casts = intypes.zip(invalues).map{ case (t, v) => s"($t)$v"}
13+
def render(args: List[String]) = args.mkString(", ")
14+
15+
s"""
16+
public static final <O, ${render(intypes)}> Bijection<Function$n<${render(intypes)}, O>, IFn> function${n}ToIFn() {
17+
return new AbstractBijection<Function$n<${render(intypes)}, O>, IFn>() {
18+
public final AFn apply(Function${n}<${render(intypes)}, O> fna) {
19+
final Function${n}<${render(intypes)}, O> fn = fna;
20+
return new AFn() {
21+
public final Object invoke(${render(inobjv)}) {
22+
return (Object)fn.apply(${render(casts)});
23+
}
24+
};
25+
}
26+
27+
public final Function${n}<${render(intypes)}, O> invert(IFn fna) {
28+
final IFn fn = fna;
29+
return new Function${n}<${render(intypes)}, O>(){
30+
public final O apply(${render(intv)}) {
31+
return (O)fn.invoke(${render(invalues)});
32+
}
33+
};
34+
}
35+
};
36+
}
37+
"""
38+
}
39+
40+
val fileContents = s"""
41+
/*
42+
Copyright 2012 Twitter, Inc.
43+
44+
Licensed under the Apache License, Version 2.0 (the "License");
45+
you may not use this file except in compliance with the License.
46+
You may obtain a copy of the License at
47+
48+
http://www.apache.org/licenses/LICENSE-2.0
49+
50+
Unless required by applicable law or agreed to in writing, software
51+
distributed under the License is distributed on an "AS IS" BASIS,
52+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53+
See the License for the specific language governing permissions and
54+
limitations under the License.
55+
*/
56+
57+
package com.twitter.bijection.clojure;
58+
import clojure.lang.AFn;
59+
import clojure.lang.IFn;
60+
import com.twitter.bijection.AbstractBijection;
61+
import com.twitter.bijection.Bijection;
62+
63+
${(0 to 22).map(n => s"import scala.Function${n};").mkString("\n")}
64+
65+
public class Workaround11770 {
66+
67+
public static final <O> Bijection<Function0<O>, IFn> function0ToIFn() {
68+
return new AbstractBijection<Function0<O>, IFn>() {
69+
public final AFn apply(Function0<O> fna) {
70+
final Function0<O> fn = fna;
71+
return new AFn() {
72+
public final Object invoke() {
73+
return (Object)fn.apply();
74+
}
75+
};
76+
}
77+
78+
public Function0<O> invert(IFn fna) {
79+
final IFn fn = fna;
80+
return new Function0<O>(){
81+
public final O apply() {
82+
return (O)fn.invoke();
83+
}
84+
};
85+
}
86+
};
87+
}
88+
89+
${(1 to 22).map(conversionN).mkString("\n\n")}
90+
91+
}""";
92+
93+
println("// Autogenerated code DO NOT EDIT BY HAND")
94+
println("// Generated by bijection-clojure/codegen/GeneratorWorkaroundJava.scala")
95+
println(fileContents)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This is a generator to forward to the generated java methods
2+
// as a workaround for scala bug#11770
3+
//
4+
// Run this generator like a script:
5+
// scala GeneratorWorkaroundScala.scala > ../src/main/scala-2.13+/com/twitter/bijection/clojure/GenertedIFnBijections.scala
6+
7+
val letters = (('A' to 'Z').toList.inits.toList.reverse.tail).take(23)
8+
def rot(l: List[Char]) = l.tail :+ l.head
9+
val methods = letters.zipWithIndex.map { case (range, i) => s"""implicit def function${i}ToIFn[${range.mkString(", ")}]:
10+
Bijection[Function${i}[${rot(range).mkString(", ")}], IFn] =
11+
Workaround11770.function${i}ToIFn[${range.mkString(", ")}]
12+
""" }
13+
14+
println("// Autogenerated code DO NOT EDIT BY HAND")
15+
println("// Generated by bijection-clojure/codegen/GeneratorWorkaroundScala.scala")
16+
println("package com.twitter.bijection.clojure")
17+
println("import clojure.lang.{ AFn, IFn }")
18+
println("import com.twitter.bijection.{ AbstractBijection, Bijection, CastInjection }")
19+
println("\ntrait GeneratedIFnBijections {")
20+
21+
methods.foreach(method => {
22+
println(method)
23+
println
24+
})
25+
println("}")

bijection-clojure/src/main/scala/com/twitter/bijection/clojure/GeneratedIFnBijections.scala renamed to bijection-clojure/src/main/scala-2.12-/com/twitter/bijection/clojure/GeneratedIFnBijections.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Autogenerated code DO NOT EDIT BY HAND
2+
// Generated by bijection-clojure/codegen/Generator.scala
23
package com.twitter.bijection.clojure
34
import clojure.lang.{AFn, IFn}
45
import com.twitter.bijection.{AbstractBijection, Bijection}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Autogenerated code DO NOT EDIT BY HAND
2+
// Generated by bijection-clojure/codegen/GeneratorWorkaroundScala.scala
3+
package com.twitter.bijection.clojure
4+
import clojure.lang.{AFn, IFn}
5+
import com.twitter.bijection.{AbstractBijection, Bijection, CastInjection}
6+
7+
trait GeneratedIFnBijections {
8+
implicit def function0ToIFn[A]: Bijection[Function0[A], IFn] =
9+
Workaround11770.function0ToIFn[A]
10+
11+
implicit def function1ToIFn[A, B]: Bijection[Function1[B, A], IFn] =
12+
Workaround11770.function1ToIFn[A, B]
13+
14+
implicit def function2ToIFn[A, B, C]: Bijection[Function2[B, C, A], IFn] =
15+
Workaround11770.function2ToIFn[A, B, C]
16+
17+
implicit def function3ToIFn[A, B, C, D]: Bijection[Function3[B, C, D, A], IFn] =
18+
Workaround11770.function3ToIFn[A, B, C, D]
19+
20+
implicit def function4ToIFn[A, B, C, D, E]: Bijection[Function4[B, C, D, E, A], IFn] =
21+
Workaround11770.function4ToIFn[A, B, C, D, E]
22+
23+
implicit def function5ToIFn[A, B, C, D, E, F]: Bijection[Function5[B, C, D, E, F, A], IFn] =
24+
Workaround11770.function5ToIFn[A, B, C, D, E, F]
25+
26+
implicit def function6ToIFn[A, B, C, D, E, F, G]: Bijection[Function6[B, C, D, E, F, G, A], IFn] =
27+
Workaround11770.function6ToIFn[A, B, C, D, E, F, G]
28+
29+
implicit def function7ToIFn[A, B, C, D, E, F, G, H]
30+
: Bijection[Function7[B, C, D, E, F, G, H, A], IFn] =
31+
Workaround11770.function7ToIFn[A, B, C, D, E, F, G, H]
32+
33+
implicit def function8ToIFn[A, B, C, D, E, F, G, H, I]
34+
: Bijection[Function8[B, C, D, E, F, G, H, I, A], IFn] =
35+
Workaround11770.function8ToIFn[A, B, C, D, E, F, G, H, I]
36+
37+
implicit def function9ToIFn[A, B, C, D, E, F, G, H, I, J]
38+
: Bijection[Function9[B, C, D, E, F, G, H, I, J, A], IFn] =
39+
Workaround11770.function9ToIFn[A, B, C, D, E, F, G, H, I, J]
40+
41+
implicit def function10ToIFn[A, B, C, D, E, F, G, H, I, J, K]
42+
: Bijection[Function10[B, C, D, E, F, G, H, I, J, K, A], IFn] =
43+
Workaround11770.function10ToIFn[A, B, C, D, E, F, G, H, I, J, K]
44+
45+
implicit def function11ToIFn[A, B, C, D, E, F, G, H, I, J, K, L]
46+
: Bijection[Function11[B, C, D, E, F, G, H, I, J, K, L, A], IFn] =
47+
Workaround11770.function11ToIFn[A, B, C, D, E, F, G, H, I, J, K, L]
48+
49+
implicit def function12ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M]
50+
: Bijection[Function12[B, C, D, E, F, G, H, I, J, K, L, M, A], IFn] =
51+
Workaround11770.function12ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M]
52+
53+
implicit def function13ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N]
54+
: Bijection[Function13[B, C, D, E, F, G, H, I, J, K, L, M, N, A], IFn] =
55+
Workaround11770.function13ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N]
56+
57+
implicit def function14ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]
58+
: Bijection[Function14[B, C, D, E, F, G, H, I, J, K, L, M, N, O, A], IFn] =
59+
Workaround11770.function14ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]
60+
61+
implicit def function15ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]
62+
: Bijection[Function15[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, A], IFn] =
63+
Workaround11770.function15ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]
64+
65+
implicit def function16ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]
66+
: Bijection[Function16[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, A], IFn] =
67+
Workaround11770.function16ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]
68+
69+
implicit def function17ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R]
70+
: Bijection[Function17[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, A], IFn] =
71+
Workaround11770.function17ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R]
72+
73+
implicit def function18ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S]
74+
: Bijection[Function18[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, A], IFn] =
75+
Workaround11770.function18ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S]
76+
77+
implicit def function19ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T]
78+
: Bijection[Function19[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, A], IFn] =
79+
Workaround11770.function19ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T]
80+
81+
implicit def function20ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U]
82+
: Bijection[Function20[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, A], IFn] =
83+
Workaround11770.function20ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U]
84+
85+
implicit def function21ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V]
86+
: Bijection[
87+
Function21[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, A],
88+
IFn
89+
] =
90+
Workaround11770
91+
.function21ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V]
92+
93+
implicit def function22ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W]
94+
: Bijection[
95+
Function22[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, A],
96+
IFn
97+
] =
98+
Workaround11770
99+
.function22ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W]
100+
101+
}

0 commit comments

Comments
 (0)