-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate static method for generic methods. #107
Labels
Comments
jDramaix
changed the title
Generate static method when @this annotation is present.
Generate static method for generic methods.
Apr 22, 2019
jDramaix
added a commit
that referenced
this issue
Apr 30, 2019
… up elemental2 diff that were removing @this annotation. We differentiate two cases: - @this {THIS} @template THIS: this is used in closure type system to reflect the class used when a method is called. This pattern is used for allowing subclasses methods chaining. When this pattern is used, we will just use the enclosing type of the method as return type. This is the current behavior we have with the diff solution. A better solution would be to override the method by specializing the return type on each known subclasses. - Generic methods: Generic methods use @this for redefining the minimum contract that has to be satisfied by the instance the method is called on. For that purpose, they also redefine the template types at method level. For the java conversion purpose, we ignore the @this annotation and we don't redefine the template type (used in @this annotation) at the method level. I've also created #107 that propose a possible improvement for generic methods PiperOrigin-RevId: 245975596
jDramaix
added a commit
to google/jsinterop-generator
that referenced
this issue
Apr 30, 2019
… up elemental2 diff that were removing @this annotation. We differentiate two cases: - @this {THIS} @template THIS: this is used in closure type system to reflect the class used when a method is called. This pattern is used for allowing subclasses methods chaining. When this pattern is used, we will just use the enclosing type of the method as return type. This is the current behavior we have with the diff solution. A better solution would be to override the method by specializing the return type on each known subclasses. - Generic methods: Generic methods use @this for redefining the minimum contract that has to be satisfied by the instance the method is called on. For that purpose, they also redefine the template types at method level. For the java conversion purpose, we ignore the @this annotation and we don't redefine the template type (used in @this annotation) at the method level. I've also created google/elemental2#107 that propose a possible improvement for generic methods PiperOrigin-RevId: 245975596
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some javascript methods like Array.prototype.shift are generics. It means they can be called or applied to objects resembling to the type defining the method.
In Closure-compiler, the @this annotations in function's jsdoc is used for that purpose and for the time being we just skip @this annotation (we even remove them by patching externs file).
We should use this information and create static methods that allow the developer to call those methods with another type of object.
Let's take for example the Array.prototype.shift definition, this method can be called on any IArrayLike object. We should generate the following method on JsArray.java class:
Note: the code snippet is just an idea how we could implement the improvement. We should discuss the final implementation (unchecked cast, auto-boxing, introducing a specific Type for shift_function...)
The text was updated successfully, but these errors were encountered: