Skip to content

Commit a678b91

Browse files
committed
Repacking/renaming.
Moves everything into a new package, `scala.runtime.jfunc`. This is a preemptive move to avoid split-packaging problems under OSGi. Uses slightly longer names for the types: s/F1/JFunction1/ s/P1/JProcedure1/ s/F/JFunc/
1 parent 201012b commit a678b91

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using Java 8 lambda syntax.
88

99
```java
1010
import scala.concurrent.*;
11-
import static scala.runtime.F.func;
11+
import static scala.runtime.jfunc.JFunc.*;
1212

1313
class Test {
1414
private static Future<Integer> futureExample(Future<String> future, ExecutionContext ec) {
@@ -17,7 +17,7 @@ class Test {
1717
}
1818
```
1919

20-
[More Examples / Documentation](https://github.com/retronym/java-8-function1/blob/master/src/test/java/scala/runtime/test/Test.java)
20+
[More Examples / Documentation](https://github.com/retronym/java-8-function1/blob/master/src/test/java/scala/runtime/jfunc/Test.java)
2121

2222
### Hacking
2323

@@ -38,7 +38,7 @@ class Test {
3838
package scala.runtime;
3939

4040
@FunctionalInterface
41-
public interface F1$mcII$sp extends F1 {
41+
public interface JFunction1$mcII$sp extends JFunction1 {
4242
abstract int apply$mcII$sp(int v1);
4343

4444
default Object apply(Object s) { return (Integer) apply$mcII$sp((Integer) s); }

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ scalaVersion := "2.11.0-RC1"
22

33
sourceGenerators in Compile <+= sourceManaged in Compile map { dir =>
44
def write(name: String, content: String) = {
5-
val f = dir / "java" / "scala" / "runtime" / s"${name}.java"
5+
val f = dir / "java" / "scala" / "runtime" / "jfunc" / s"${name}.java"
66
IO.write(f, content)
77
f
88
}
9-
Seq(write("F", CodeGen.factory)) ++ (0 to 22).map(n => write("F" + n, CodeGen.fN(n))) ++ (1 to 22).map(n => write("P" + n, CodeGen.pN(n)))
9+
Seq(write("JFunc", CodeGen.factory)) ++ (0 to 22).map(n => write("JFunction" + n, CodeGen.fN(n))) ++ (1 to 22).map(n => write("JProcedure" + n, CodeGen.pN(n)))
1010
}
1111

1212
sourceGenerators in Test <+= sourceManaged in Test map { dir =>
1313
def write(name: String, content: String) = {
14-
val f = dir / "java" / "scala" / "runtime" / "test" / s"${name}.java"
14+
val f = dir / "java" / "scala" / "runtime" / "jfunc" / s"${name}.java"
1515
IO.write(f, content)
1616
f
1717
}

project/CodeGen.scala

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object Type {
1717
}
1818

1919
object CodeGen {
20+
def packaging = "package scala.runtime.jfunc;"
2021
case class arity(n: Int) {
2122
val ns = (1 to n).toList
2223

@@ -28,21 +29,21 @@ object CodeGen {
2829
s"""
2930
|$copyright
3031
|
31-
|package scala.runtime;
32+
|$packaging
3233
|
3334
|@FunctionalInterface
34-
|public interface F0<R> extends scala.Function0<R> {
35+
|public interface JFunction0<R> extends scala.Function0<R> {
3536
| default void $initName() {
3637
| };
3738
|""".stripMargin
3839
private def f1Header =
3940
s"""
4041
|$copyright
4142
|
42-
|package scala.runtime;
43+
|$packaging
4344
|
4445
|@FunctionalInterface
45-
|public interface F1<T1, R> extends scala.Function1<T1, R> {
46+
|public interface JFunction1<T1, R> extends scala.Function1<T1, R> {
4647
| default void $initName() {
4748
| };
4849
|
@@ -65,10 +66,10 @@ object CodeGen {
6566
s"""
6667
|$copyright
6768
|
68-
|package scala.runtime;
69+
|$packaging
6970
|
7071
|@FunctionalInterface
71-
|public interface F$n<$tparams, R> extends scala.Function$n<$tparams, R> {
72+
|public interface JFunction$n<$tparams, R> extends scala.Function$n<$tparams, R> {
7273
| default void $initName() {
7374
| };
7475
|
@@ -93,16 +94,16 @@ object CodeGen {
9394
def pN: String = {
9495
val vparams = csv(n => s"T$n t$n")
9596
val vparamRefs = csv(n => s"t$n")
96-
val parent = "F" + n
97+
val parent = "JFunction" + n
9798
s"""
9899
|$copyright
99100
|
100-
|package scala.runtime;
101+
|$packaging
101102
|
102103
|import scala.runtime.BoxedUnit;
103104
|
104105
|@FunctionalInterface
105-
|public interface P${n}<${tparams}> extends ${parent}<$tparams, BoxedUnit> {
106+
|public interface JProcedure${n}<${tparams}> extends ${parent}<$tparams, BoxedUnit> {
106107
| default void $initName() {
107108
| }
108109
|
@@ -118,8 +119,8 @@ object CodeGen {
118119

119120
def factory: String = {
120121
s"""
121-
|public static <$tparams, R> scala.Function$n<$tparams, R> func(F$n<$tparams, R> f) { return f; }
122-
|public static <$tparams> scala.Function$n<$tparams, BoxedUnit> proc(P$n<$tparams> p) { return p; }
122+
|public static <$tparams, R> scala.Function$n<$tparams, R> func(JFunction$n<$tparams, R> f) { return f; }
123+
|public static <$tparams> scala.Function$n<$tparams, BoxedUnit> proc(JProcedure$n<$tparams> p) { return p; }
123124
|""".stripMargin.trim
124125
}
125126

@@ -220,13 +221,13 @@ object CodeGen {
220221
s"""
221222
|$copyright
222223
|
223-
|package scala.runtime;
224+
|$packaging
224225
|
225226
|import scala.runtime.BoxedUnit;
226227
|
227-
|public final class F {
228-
| private F() {}
229-
| public static <R> scala.Function0<R> f0(F0<R> f) { return f; }
228+
|public final class JFunc {
229+
| private JFunc() {}
230+
| public static <R> scala.Function0<R> func(JFunction0<R> f) { return f; }
230231
|${indent(ms)}
231232
|}
232233
|
@@ -237,7 +238,7 @@ object CodeGen {
237238
s"""
238239
|$copyright
239240
|
240-
|package scala.runtime.test;
241+
|$packaging
241242
|
242243
|final class TestAPI {
243244
|${(1 to 22).map(n => arity(n).accept).map(indent).mkString("\n\n")}

src/test/java/scala/runtime/test/Test.java renamed to src/test/java/scala/runtime/jfunc/Test.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* Copyright (C) 2012-2014 Typesafe Inc. <http://www.typesafe.com>
33
*/
4-
package scala.runtime.test;
4+
package scala.runtime.jfunc;
55

66
import scala.runtime.*;
7-
import static scala.runtime.test.TestAPI.*;
8-
import static scala.runtime.F.*;
7+
import static scala.runtime.jfunc.TestAPI.*;
8+
import static scala.runtime.jfunc.JFunc.*;
99

1010
public class Test {
1111
public static void main(String[] args) {
@@ -21,11 +21,11 @@ public static void main(String[] args) {
2121

2222
// That's a pity, but we can get pretty close with this library!
2323

24-
// We have to tell javac to use `F1` as the functional interface.
25-
F1<String, String> f1 = (String s) -> s;
24+
// We have to tell javac to use `JFunction1` as the functional interface.
25+
JFunction1<String, String> f1 = (String s) -> s;
2626

2727
// That's more or less equivalent to the old, anonymous class syntax:
28-
new F1<String, String>() {
28+
new JFunction1<String, String>() {
2929
public String apply(String s) { return s; }
3030
};
3131

@@ -40,9 +40,9 @@ public static void main(String[] args) {
4040
// F1 is a subclass of Function1:
4141
scala.Function1<String, String> f2 = f1;
4242

43-
// Factory methods in `F` can reduce the verbosity a little:
43+
// Factory methods in `JFunc` can reduce the verbosity a little:
4444
// `func` is actually just an identity method; it only exists to
45-
// trigger lambda creation using the `F1` functional interface.
45+
// trigger lambda creation using the `JFunction1` functional interface.
4646
scala.Function1<String, String> f3 = func((String s) -> s);
4747

4848
// Note that javac's type inference can infer the parameter type here,
@@ -53,7 +53,7 @@ public static void main(String[] args) {
5353

5454
// Specialized variants of the `apply` method are implenented in the
5555
// functional interface
56-
F1<Integer, Integer> f5 = (i) -> -i;
56+
JFunction1<Integer, Integer> f5 = (i) -> -i;
5757
assert(f5.apply(1) == -1);
5858
assert(f5.apply$mcII$sp(1) == -1);
5959

@@ -62,10 +62,10 @@ public static void main(String[] args) {
6262
scala.Function2<String, String, String> f6 = func((s1, s2) -> join(s1, s2));
6363
assert(f6.curried().apply("1").apply("2").equals("12"));
6464

65-
// Functions returning unit must use the `P1`, ... functional interfaces
65+
// Functions returning unit must use the `JProcedure1`, ... functional interfaces
6666
// in order to convert a void lamdba return to Scala's Unit.
6767
//
68-
// The easiest way to do this is via `F.proc`, ....
68+
// The easiest way to do this is via `JFunc.proc`, ....
6969
//
7070
// Note that the lambda has a return type of `void` if the last
7171
// statement is a call to a `void` returning method, or if it is
@@ -74,7 +74,7 @@ public static void main(String[] args) {
7474
scala.Function1<String, BoxedUnit> f8 = proc(s -> {s.toUpperCase(); return;});
7575

7676
// Function0 is also available
77-
scala.Function0<String> f9 = F.f0(() -> "42");
77+
scala.Function0<String> f9 = func(() -> "42");
7878
assert(f9.apply().equals("42"));
7979

8080
// You can go up to 22 (the highest arity function defined in the Scala standard library.)

0 commit comments

Comments
 (0)