Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

putting Option<A> inside Utilities causes the scala 2.9.2 compiler to…

… CRASH. yes, CRASH.

this appears to be the relevant bug: http://scala.myjetbrains.com/youtrack/issue/SI-1232
  • Loading branch information...
commit 06dba2a8466dfff8b7ab969e41c644a8d3ab6750 1 parent 5e1133d
Robey Pointer authored
View
1  scrooge-generator/src/main/resources/javagen/service.java
@@ -1,5 +1,6 @@
package {{package}};
+import com.twitter.scrooge.ScroogeOption;
import com.twitter.finagle.SourcedException;
import com.twitter.scrooge.ThriftStruct;
import com.twitter.scrooge.ThriftStructCodec;
View
7 scrooge-generator/src/main/resources/javagen/struct.java
@@ -1,6 +1,7 @@
{{#public}}
package {{package}};
+import com.twitter.scrooge.ScroogeOption;
import com.twitter.scrooge.Utilities;
import com.twitter.scrooge.ThriftStruct;
import com.twitter.scrooge.ThriftStructCodec;
@@ -22,7 +23,7 @@
private static final TStruct STRUCT = new TStruct("{{name}}");
{{#fields}}
private static final TField {{fieldConst}} = new TField("{{name}}", TType.{{constType}}, (short) {{id}});
- final {{#optional}}Utilities.Option<{{fieldType}}>{{/optional}}{{^optional}}{{primitiveFieldType}}{{/optional}} {{name}};
+ final {{#optional}}ScroogeOption<{{fieldType}}>{{/optional}}{{^optional}}{{primitiveFieldType}}{{/optional}} {{name}};
{{/fields}}
public static class Builder {
@@ -47,7 +48,7 @@
return new {{name}}(
{{#fields}}
{{#optional}}
- Utilities.Option.make(this._got_{{name}}, this._{{name}}){{/optional}}
+ ScroogeOption.make(this._got_{{name}}, this._{{name}}){{/optional}}
{{^optional}}
this._{{name}}{{/optional}}
{{/fields|,
@@ -118,7 +119,7 @@ public static void encode({{name}} struct, TProtocol oprot) throws org.apache.th
public {{name}}(
{{#fields}}
- {{#optional}}Utilities.Option<{{fieldType}}>{{/optional}}{{^optional}}{{primitiveFieldType}}{{/optional}} {{name}}{{comma}}
+ {{#optional}}ScroogeOption<{{fieldType}}>{{/optional}}{{^optional}}{{primitiveFieldType}}{{/optional}} {{name}}{{comma}}
{{/fields}}
) {
{{#isException}}
View
8 scrooge-generator/src/test/scala/com/twitter/scrooge/scalagen/JavaGeneratorSpec.scala
@@ -250,7 +250,7 @@ class JavaGeneratorSpec extends Specification with EvalHelper with JMocker with
endRead(protocol)
}
- OptionalInt.decode(protocol) mustEqual new OptionalInt("Commie", new Utilities.Option.Some(14))
+ OptionalInt.decode(protocol) mustEqual new OptionalInt("Commie", new ScroogeOption.Some(14))
}
"read with missing field" in {
@@ -260,7 +260,7 @@ class JavaGeneratorSpec extends Specification with EvalHelper with JMocker with
endRead(protocol)
}
- OptionalInt.decode(protocol) mustEqual new OptionalInt("Commie", Utilities.Option.none())
+ OptionalInt.decode(protocol) mustEqual new OptionalInt("Commie", ScroogeOption.none())
}
"write" in {
@@ -272,7 +272,7 @@ class JavaGeneratorSpec extends Specification with EvalHelper with JMocker with
endWrite(protocol)
}
- new OptionalInt("Commie", new Utilities.Option.Some(14)).write(protocol) mustEqual ()
+ new OptionalInt("Commie", new ScroogeOption.Some(14)).write(protocol) mustEqual ()
}
"write with missing field" in {
@@ -282,7 +282,7 @@ class JavaGeneratorSpec extends Specification with EvalHelper with JMocker with
endWrite(protocol)
}
- new OptionalInt("Commie", Utilities.Option.none()).write(protocol) mustEqual ()
+ new OptionalInt("Commie", ScroogeOption.none()).write(protocol) mustEqual ()
}
}
View
56 scrooge-runtime/src/main/java/com/twitter/scrooge/ScroogeOption.java
@@ -0,0 +1,56 @@
+package com.twitter.scrooge;
+
+import java.util.*;
+
+public abstract class ScroogeOption<A> {
+ public abstract A get();
+ public abstract boolean isDefined();
+
+ public static <A> ScroogeOption<A> make(boolean b, A a) {
+ if (b) {
+ return new Some<A>(a);
+ } else {
+ return none();
+ }
+ }
+
+ public static <A> ScroogeOption<A> none() {
+ return (ScroogeOption<A>) NONE;
+ }
+
+ public static ScroogeOption<Void> NONE = new ScroogeOption<Void>() {
+ public Void get() {
+ throw new IllegalArgumentException();
+ }
+
+ public boolean isDefined() {
+ return false;
+ }
+ };
+
+ public static class Some<A> extends ScroogeOption<A> {
+ final A a;
+
+ public Some(A a) {
+ this.a = a;
+ }
+
+ public A get() {
+ return a;
+ }
+
+ public boolean isDefined() {
+ return true;
+ }
+
+ public boolean equals(Object other) {
+ if (!(other instanceof Some)) return false;
+ Some<A> that = (Some<A>) other;
+ return this.a.equals(that.a);
+ }
+
+ public String toString() {
+ return "Some(" + this.a.toString() + ")";
+ }
+ }
+}
View
55 scrooge-runtime/src/main/java/com/twitter/scrooge/Utilities.java
@@ -44,57 +44,4 @@ B getSecond() {
public static <A, B> Tuple<A, B> makeTuple(A a, B b) {
return new Tuple<A, B>(a, b);
}
-
- public static abstract class Option<A> {
- public abstract A get();
- public abstract boolean isDefined();
-
- public static <A> Option<A> make(boolean b, A a) {
- if (b) {
- return new Some<A>(a);
- } else {
- return none();
- }
- }
-
- public static <A> Option<A> none() {
- return (Option<A>) NONE;
- }
-
- public static Option<Void> NONE = new Option<Void>() {
- public Void get() {
- throw new IllegalArgumentException();
- }
-
- public boolean isDefined() {
- return false;
- }
- };
-
- public static class Some<A> extends Option<A> {
- final A a;
-
- public Some(A a) {
- this.a = a;
- }
-
- public A get() {
- return a;
- }
-
- public boolean isDefined() {
- return true;
- }
-
- public boolean equals(Object other) {
- if (!(other instanceof Some)) return false;
- Some<A> that = (Some<A>) other;
- return this.a.equals(that.a);
- }
-
- public String toString() {
- return "Some(" + this.a.toString() + ")";
- }
- }
- }
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.