forked from google/jsinterop-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support instance member overriding a static member with union types
Fixes google#46
- Loading branch information
Showing
5 changed files
with
230 additions
and
7 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,22 @@ | ||
# Description: | ||
# Tests conversion of overridden methods and their args | ||
# | ||
|
||
load( | ||
"//javatests/jsinterop/generator:jsinterop_generator_test.bzl", | ||
"jsinterop_generator_test", | ||
) | ||
|
||
package( | ||
default_visibility = ["//:__subpackages__"], | ||
# Apache2 | ||
licenses = ["notice"], | ||
) | ||
|
||
jsinterop_generator_test( | ||
name = "overloads", | ||
srcs = ["overloads.js"], | ||
expected_output = [ | ||
"Foo.java.txt", | ||
], | ||
) |
157 changes: 157 additions & 0 deletions
157
javatests/jsinterop/generator/externs/overloads/Foo.java.txt
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,157 @@ | ||
package jsinterop.generator.externs.overloads; | ||
|
||
import jsinterop.annotations.JsMethod; | ||
import jsinterop.annotations.JsOverlay; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsProperty; | ||
import jsinterop.annotations.JsType; | ||
import jsinterop.base.Js; | ||
|
||
@JsType(isNative = true, namespace = JsPackage.GLOBAL) | ||
public class Foo { | ||
@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL) | ||
public interface StaticUnionArgMethodArgUnionType { | ||
@JsOverlay | ||
static Foo.StaticUnionArgMethodArgUnionType of(Object o) { | ||
return Js.cast(o); | ||
} | ||
|
||
@JsOverlay | ||
default double asDouble() { | ||
return Js.asDouble(this); | ||
} | ||
|
||
@JsOverlay | ||
default String asString() { | ||
return Js.asString(this); | ||
} | ||
|
||
@JsOverlay | ||
default boolean isDouble() { | ||
return (Object) this instanceof Double; | ||
} | ||
|
||
@JsOverlay | ||
default boolean isString() { | ||
return (Object) this instanceof String; | ||
} | ||
} | ||
|
||
@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL) | ||
public interface StaticUnionPropertyUnionType { | ||
@JsOverlay | ||
static Foo.StaticUnionPropertyUnionType of(Object o) { | ||
return Js.cast(o); | ||
} | ||
|
||
@JsOverlay | ||
default double asDouble() { | ||
return Js.asDouble(this); | ||
} | ||
|
||
@JsOverlay | ||
default String asString() { | ||
return Js.asString(this); | ||
} | ||
|
||
@JsOverlay | ||
default boolean isDouble() { | ||
return (Object) this instanceof Double; | ||
} | ||
|
||
@JsOverlay | ||
default boolean isString() { | ||
return (Object) this instanceof String; | ||
} | ||
} | ||
|
||
@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL) | ||
public interface UnionArgMethodArgUnionType { | ||
@JsOverlay | ||
static Foo.UnionArgMethodArgUnionType of(Object o) { | ||
return Js.cast(o); | ||
} | ||
|
||
@JsOverlay | ||
default double asDouble() { | ||
return Js.asDouble(this); | ||
} | ||
|
||
@JsOverlay | ||
default String asString() { | ||
return Js.asString(this); | ||
} | ||
|
||
@JsOverlay | ||
default boolean isDouble() { | ||
return (Object) this instanceof Double; | ||
} | ||
|
||
@JsOverlay | ||
default boolean isString() { | ||
return (Object) this instanceof String; | ||
} | ||
} | ||
|
||
@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL) | ||
public interface UnionPropertyUnionType { | ||
@JsOverlay | ||
static Foo.UnionPropertyUnionType of(Object o) { | ||
return Js.cast(o); | ||
} | ||
|
||
@JsOverlay | ||
default double asDouble() { | ||
return Js.asDouble(this); | ||
} | ||
|
||
@JsOverlay | ||
default String asString() { | ||
return Js.asString(this); | ||
} | ||
|
||
@JsOverlay | ||
default boolean isDouble() { | ||
return (Object) this instanceof Double; | ||
} | ||
|
||
@JsOverlay | ||
default boolean isString() { | ||
return (Object) this instanceof String; | ||
} | ||
} | ||
|
||
@JsProperty(name = "unionProperty") | ||
public static Foo.StaticUnionPropertyUnionType unionProperty_STATIC; | ||
|
||
@JsMethod(name = "noArgMethod") | ||
public static native Object noArgMethod_STATIC(); | ||
|
||
public static native Object unionArgMethod(Foo.StaticUnionArgMethodArgUnionType arg); | ||
|
||
@JsOverlay | ||
public static final Object unionArgMethod_STATIC(String arg) { | ||
return unionArgMethod(Js.<Foo.StaticUnionArgMethodArgUnionType>uncheckedCast(arg)); | ||
} | ||
|
||
@JsOverlay | ||
public static final Object unionArgMethod_STATIC(double arg) { | ||
return unionArgMethod(Js.<Foo.StaticUnionArgMethodArgUnionType>uncheckedCast(arg)); | ||
} | ||
|
||
public Foo.UnionPropertyUnionType unionProperty; | ||
|
||
public native Object noArgMethod(); | ||
|
||
@JsOverlay | ||
public final Object unionArgMethod(String arg) { | ||
return unionArgMethod(Js.<Foo.UnionArgMethodArgUnionType>uncheckedCast(arg)); | ||
} | ||
|
||
public native Object unionArgMethod(Foo.UnionArgMethodArgUnionType arg); | ||
|
||
@JsOverlay | ||
public final Object unionArgMethod(double arg) { | ||
return unionArgMethod(Js.<Foo.UnionArgMethodArgUnionType>uncheckedCast(arg)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
javatests/jsinterop/generator/externs/overloads/overloads.js
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,31 @@ | ||
|
||
/** | ||
* @fileoverview Test "overloaded" method conventions | ||
* @externs | ||
*/ | ||
|
||
/** | ||
* @constructor | ||
*/ | ||
function Foo() {} | ||
|
||
Foo.noArgMethod = function() {}; | ||
Foo.prototype.noArgMethod = function() {}; | ||
|
||
/** | ||
* @param {string|number} arg | ||
*/ | ||
Foo.unionArgMethod = function(arg) {}; | ||
/** | ||
* @param {string|number} arg | ||
*/ | ||
Foo.prototype.unionArgMethod = function(arg) {}; | ||
|
||
/** | ||
* @type {string|number} | ||
*/ | ||
Foo.unionProperty; | ||
/** | ||
* @type {string|number} | ||
*/ | ||
Foo.prototype.unionProperty; |