-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
Showing
30 changed files
with
1,810 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// This is a generator for java methods to forward to, as a workaround for | ||
// scala bug#11770 | ||
// | ||
// Run this generator like a script: | ||
// scala GeneratorWorkaroundJava.scala > ../src/main/scala-2.13+/com/twitter/bijection/clojure/Workaround11770.java | ||
|
||
def conversionN(n: Int) = { | ||
val intypes = (1 to n).map(i => "I" + i.toString).toList | ||
val invalues = intypes.map(_.toLowerCase) | ||
val intv = intypes.zip(invalues).map{ case (t, v) => s"$t $v"} | ||
val inobjv = invalues.map(v => s"Object $v") | ||
val casts = intypes.zip(invalues).map{ case (t, v) => s"($t)$v"} | ||
def render(args: List[String]) = args.mkString(", ") | ||
|
||
s""" | ||
public static final <O, ${render(intypes)}> Bijection<Function$n<${render(intypes)}, O>, IFn> function${n}ToIFn() { | ||
return new AbstractBijection<Function$n<${render(intypes)}, O>, IFn>() { | ||
public final AFn apply(Function${n}<${render(intypes)}, O> fna) { | ||
final Function${n}<${render(intypes)}, O> fn = fna; | ||
return new AFn() { | ||
public final Object invoke(${render(inobjv)}) { | ||
return (Object)fn.apply(${render(casts)}); | ||
} | ||
}; | ||
} | ||
|
||
public final Function${n}<${render(intypes)}, O> invert(IFn fna) { | ||
final IFn fn = fna; | ||
return new Function${n}<${render(intypes)}, O>(){ | ||
public final O apply(${render(intv)}) { | ||
return (O)fn.invoke(${render(invalues)}); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
""" | ||
} | ||
|
||
val fileContents = s""" | ||
/* | ||
Copyright 2012 Twitter, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.twitter.bijection.clojure; | ||
import clojure.lang.AFn; | ||
import clojure.lang.IFn; | ||
import com.twitter.bijection.AbstractBijection; | ||
import com.twitter.bijection.Bijection; | ||
|
||
${(0 to 22).map(n => s"import scala.Function${n};").mkString("\n")} | ||
|
||
public class Workaround11770 { | ||
|
||
public static final <O> Bijection<Function0<O>, IFn> function0ToIFn() { | ||
return new AbstractBijection<Function0<O>, IFn>() { | ||
public final AFn apply(Function0<O> fna) { | ||
final Function0<O> fn = fna; | ||
return new AFn() { | ||
public final Object invoke() { | ||
return (Object)fn.apply(); | ||
} | ||
}; | ||
} | ||
|
||
public Function0<O> invert(IFn fna) { | ||
final IFn fn = fna; | ||
return new Function0<O>(){ | ||
public final O apply() { | ||
return (O)fn.invoke(); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
${(1 to 22).map(conversionN).mkString("\n\n")} | ||
|
||
}"""; | ||
|
||
println("// Autogenerated code DO NOT EDIT BY HAND") | ||
println("// Generated by bijection-clojure/codegen/GeneratorWorkaroundJava.scala") | ||
println(fileContents) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This is a generator to forward to the generated java methods | ||
// as a workaround for scala bug#11770 | ||
// | ||
// Run this generator like a script: | ||
// scala GeneratorWorkaroundScala.scala > ../src/main/scala-2.13+/com/twitter/bijection/clojure/GenertedIFnBijections.scala | ||
|
||
val letters = (('A' to 'Z').toList.inits.toList.reverse.tail).take(23) | ||
def rot(l: List[Char]) = l.tail :+ l.head | ||
val methods = letters.zipWithIndex.map { case (range, i) => s"""implicit def function${i}ToIFn[${range.mkString(", ")}]: | ||
Bijection[Function${i}[${rot(range).mkString(", ")}], IFn] = | ||
Workaround11770.function${i}ToIFn[${range.mkString(", ")}] | ||
""" } | ||
|
||
println("// Autogenerated code DO NOT EDIT BY HAND") | ||
println("// Generated by bijection-clojure/codegen/GeneratorWorkaroundScala.scala") | ||
println("package com.twitter.bijection.clojure") | ||
println("import clojure.lang.{ AFn, IFn }") | ||
println("import com.twitter.bijection.{ AbstractBijection, Bijection, CastInjection }") | ||
println("\ntrait GeneratedIFnBijections {") | ||
|
||
methods.foreach(method => { | ||
println(method) | ||
println | ||
}) | ||
println("}") |
1 change: 1 addition & 0 deletions
1
...tion/clojure/GeneratedIFnBijections.scala → ...tion/clojure/GeneratedIFnBijections.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...n-clojure/src/main/scala-2.13+/com/twitter/bijection/clojure/GeneratedIFnBijections.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Autogenerated code DO NOT EDIT BY HAND | ||
// Generated by bijection-clojure/codegen/GeneratorWorkaroundScala.scala | ||
package com.twitter.bijection.clojure | ||
import clojure.lang.{AFn, IFn} | ||
import com.twitter.bijection.{AbstractBijection, Bijection, CastInjection} | ||
|
||
trait GeneratedIFnBijections { | ||
implicit def function0ToIFn[A]: Bijection[Function0[A], IFn] = | ||
Workaround11770.function0ToIFn[A] | ||
|
||
implicit def function1ToIFn[A, B]: Bijection[Function1[B, A], IFn] = | ||
Workaround11770.function1ToIFn[A, B] | ||
|
||
implicit def function2ToIFn[A, B, C]: Bijection[Function2[B, C, A], IFn] = | ||
Workaround11770.function2ToIFn[A, B, C] | ||
|
||
implicit def function3ToIFn[A, B, C, D]: Bijection[Function3[B, C, D, A], IFn] = | ||
Workaround11770.function3ToIFn[A, B, C, D] | ||
|
||
implicit def function4ToIFn[A, B, C, D, E]: Bijection[Function4[B, C, D, E, A], IFn] = | ||
Workaround11770.function4ToIFn[A, B, C, D, E] | ||
|
||
implicit def function5ToIFn[A, B, C, D, E, F]: Bijection[Function5[B, C, D, E, F, A], IFn] = | ||
Workaround11770.function5ToIFn[A, B, C, D, E, F] | ||
|
||
implicit def function6ToIFn[A, B, C, D, E, F, G]: Bijection[Function6[B, C, D, E, F, G, A], IFn] = | ||
Workaround11770.function6ToIFn[A, B, C, D, E, F, G] | ||
|
||
implicit def function7ToIFn[A, B, C, D, E, F, G, H] | ||
: Bijection[Function7[B, C, D, E, F, G, H, A], IFn] = | ||
Workaround11770.function7ToIFn[A, B, C, D, E, F, G, H] | ||
|
||
implicit def function8ToIFn[A, B, C, D, E, F, G, H, I] | ||
: Bijection[Function8[B, C, D, E, F, G, H, I, A], IFn] = | ||
Workaround11770.function8ToIFn[A, B, C, D, E, F, G, H, I] | ||
|
||
implicit def function9ToIFn[A, B, C, D, E, F, G, H, I, J] | ||
: Bijection[Function9[B, C, D, E, F, G, H, I, J, A], IFn] = | ||
Workaround11770.function9ToIFn[A, B, C, D, E, F, G, H, I, J] | ||
|
||
implicit def function10ToIFn[A, B, C, D, E, F, G, H, I, J, K] | ||
: Bijection[Function10[B, C, D, E, F, G, H, I, J, K, A], IFn] = | ||
Workaround11770.function10ToIFn[A, B, C, D, E, F, G, H, I, J, K] | ||
|
||
implicit def function11ToIFn[A, B, C, D, E, F, G, H, I, J, K, L] | ||
: Bijection[Function11[B, C, D, E, F, G, H, I, J, K, L, A], IFn] = | ||
Workaround11770.function11ToIFn[A, B, C, D, E, F, G, H, I, J, K, L] | ||
|
||
implicit def function12ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M] | ||
: Bijection[Function12[B, C, D, E, F, G, H, I, J, K, L, M, A], IFn] = | ||
Workaround11770.function12ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M] | ||
|
||
implicit def function13ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N] | ||
: Bijection[Function13[B, C, D, E, F, G, H, I, J, K, L, M, N, A], IFn] = | ||
Workaround11770.function13ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N] | ||
|
||
implicit def function14ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O] | ||
: Bijection[Function14[B, C, D, E, F, G, H, I, J, K, L, M, N, O, A], IFn] = | ||
Workaround11770.function14ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O] | ||
|
||
implicit def function15ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P] | ||
: Bijection[Function15[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, A], IFn] = | ||
Workaround11770.function15ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P] | ||
|
||
implicit def function16ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] | ||
: Bijection[Function16[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, A], IFn] = | ||
Workaround11770.function16ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] | ||
|
||
implicit def function17ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R] | ||
: Bijection[Function17[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, A], IFn] = | ||
Workaround11770.function17ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R] | ||
|
||
implicit def function18ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S] | ||
: Bijection[Function18[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, A], IFn] = | ||
Workaround11770.function18ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S] | ||
|
||
implicit def function19ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] | ||
: Bijection[Function19[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, A], IFn] = | ||
Workaround11770.function19ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] | ||
|
||
implicit def function20ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U] | ||
: Bijection[Function20[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, A], IFn] = | ||
Workaround11770.function20ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U] | ||
|
||
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] | ||
: Bijection[ | ||
Function21[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, A], | ||
IFn | ||
] = | ||
Workaround11770 | ||
.function21ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V] | ||
|
||
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] | ||
: Bijection[ | ||
Function22[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, A], | ||
IFn | ||
] = | ||
Workaround11770 | ||
.function22ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W] | ||
|
||
} |
Oops, something went wrong.