@JsType(prototype = "Object")
interface JsObject extends Auto_JsObject {
static JsObject of(Object obj) {
return obj instanceof JsObject ? (JsObject) obj : null;
}
interface Static {
String[] keys(JsObject obj);
JsObject defineProperties(JsObject obj, JsObject props);
}
interface constructors {
void constructor(String param);
}
boolean hasOwnProperty(String prop);
boolean isPrototypeOf(JsObject prop);
}
interface Auto_JsObject {
public static JsObject newInstance(String param) {
return js("new Object($0)", param);
}
public static String[] keys(JsObject obj) {
return js("Object.keys($0)", obj);
}
public static JsObject defineProperties(JsObject obj, JsObject props) {
...
}
@PrototypeOfJsType(JsObject.class)
public static class prototype {
JsObject constructor(String param) { return null}
boolean hasOwnProperty(String prop) { return false; };
boolean isPrototypeOf(JsObject prop) { return false; };
}
}
MyObject extends JsObject.prototype {}
JsObject.keys( ... );
JsObject.newInstance( ... );
JsObject.of(new Object());
@JsApi("Object") // A new annotation for the DSL, not required to be in the SDK
interface __JsObject { // Used underscore so it doesn't show up in code completion
String[] keys(JsObject obj);
JsObject defineProperties(JsObject obj, JsObject props);
static JsObject of(Object obj) {
return obj instanceof JsObject ? (JsObject) obj : null;
}
interface prototype {
boolean hasOwnProperty(String prop);
boolean isPrototypeOf(JsObject prop);
}
interface constructors {
void constructor(String param);
}
}
@JsType(prototype = "Object")
interface JsObject {
static JsObject newInstance(String param) {
return js("new Object($0)", param);
}
static String[] keys(JsObject obj) {
return js("Object.keys($0)", obj);
};
static JsObject defineProperties(JsObject obj, JsObject props) {
...
}
static JsObject of(Object obj) {
return __JsObject.of(obj);
}
boolean hasOwnProperty(String prop);
boolean isPrototypeOf(JsObject prop);
public static JsObject defineProperties(JsObject obj, JsObject props) {
...
}
@PrototypeOfJsType(JsObject.class)
public static class prototype {
JsObject constructor(String param) { return null;}
boolean hasOwnProperty(String prop) { return false; };
boolean isPrototypeOf(JsObject prop) { return false; };
}
}
@JsType(prototype="Object")
public class JsObject {
@JsConstructor
public static native JsObject newInstance(String param);
public static native String[] keys(JsObject obj);
public static native JsObject defineProperties(JsObject obj, JsObject props);
public static JsObject of(Object obj) {
return obj instanceof JsObject ? (JsObject) obj : null;
}
public native boolean hasOwnProperty(String prop);
public native boolean isPrototypeOf(JsObject prop);
}
public final native void setCssText(String cssText);
--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA2DvnfqtL1F4zd_ydM4KdWx9bBXCdtY7RGs_vaVvh88%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
@JsType(prototype = "Object")
interface JsObject {
class prototype extends Prototype_JsObject {}
interface Static {
String[] keys(JsObject obj);
JsObject defineProperties(JsObject obj, JsObject props)
;
}
static Static getStatic() {
return new Static_JsObject();
}
static JsObject of(Object obj) {
return obj instanceof JsObject ? (JsObject) obj : null
;
}
@JsConstructor
void constructor(String param);
boolean hasOwnProperty(String prop);
boolean isPrototypeOf(JsObject prop);
}
@PrototypeOfJsType(JsObject.class)
public class Prototype_JsObject {
JsObject constructor(String param) { return null;}
boolean hasOwnProperty(String prop) { return false; }
boolean isPrototypeOf(JsObject prop) { return false; }
}
public class Static_JsObject implements Static {
JsObject newInstance(String param) {
return js("new Object($0)", param)
;
}
public String[] keys(JsObject obj) {
return js("Object.keys($0)", obj)
;
};
public JsObject defineProperties(JsObject obj, JsObject props) {
...
}
}
MyObject extends JsObject.prototype {}
JsObject.getStatic().keys( ... );
JsObject.getStatic().newInstance( ... );
JsObject.of(new Object());
--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/20141101102535.45715a48%40sh9.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA30t6RmeVs%3D9XGOp4HU0_u_NYu4J42SYJ9HQnH9PgoXSg%40mail.gmail.com.
After reading, and playing with some stub code based on these ideas, I come to the conclusion than 'native' is almost perfect from the point of view of a gwt developer.We want pure java syntax and simplicity, and any other conventions like DSLs or magic interface names, etc, could obscure the understanding existing code, or trying to figure out how to implement something.For java developers 'native' means that the platform knows how to deal with this method, and in the case of gwt this is true and intuitive, meaning that 'this is native because it's implemented natively in JS'.The compiler ability to automatically resolve native methods, could be very useful not only for JsInterop but for many other cases where we use them.Hence any getter or setter could be automatically written by the compiler if it does not have the jsni fragment. For instance in c.g.g.d.c.StyleElement we could get rid of all of the jsni fragments and just write methods declarationpublic final native void setCssText(String cssText);
If the compiler does this, we could save thousands of line of code in jsni fragments in the gwt core, also in elemental, and in several other 3 party libraries.Even, we could have an annotation to deal with simple JSNI code instead of using c++ comment blocks to change the default implementation:@Jsni("return $doc.head || $doc.getElementsByTagName('head')[0]")public final native void getHead();
Also it would be nice if the compiler is able to deal directly with type conversion and it is able to box returned values: java arrays to jsArrays, js numbers to java types, etc. This will make gwt developer experience better.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAM28XAtxB%3DZwRGfKxGVN-qa-%3DKk1jSZAMsq-0zsKTGRWuqzFZw%40mail.gmail.com.
> I will try to summarize my thought process and different options that
> I have played with so that you could get a better understanding where
> I'm coming from and I hope it will provide good documentation for
> future.
Thanks for the email; I think the format was really useful.
> One may argue that if we are committing to use some kind of DSL why
> not use something else like IDL or xml etc. There are 3 main reasons
> to use java + APT instead of others:
I really want to advocate APT, as I've used it and do generally like it,
but frankly it can be a huge PITA for Eclipse. See long-standing issues
e.g.:
https://github.com/square/dagger/issues/126
Granted, maybe someone can just fix Eclipse, but, in my experience, it
can really ruin the first impressions for a project (1000s of compile
errors due to missing generated code, and no hints that, btw, it's
because the APT was not on the classpath/didn't run).
> All the cons are around the testability aspect. For JRE testing,
> native methods are a headache. Also we no longer generate an interface
> for static methods.
I know I just bitched about APT, but, just musing, what if the class
(with the native methods/etc.) was the DSL the user wrote, and then APT
just generated an interface from that?
This is basically what I'm doing by hand in tessell with writing
IsTextBox for TextBox, etc.
I admittedly am not an expert on JS prototype semantics, so am not sure
how this would handle statics/etc. But in testing I usually only care
about instance methods anyway...
A few years ago I spiked an APT processor to do this automatically:
https://github.com/stephenh/interfacegen
The oddity then becomes that the user is writing "class JsObject", but
then if they want testable code, they need to code against the generated
"IsJsObject" interface. But perhaps that it's optional is a good thing,
e.g. you could come back and add the "@GenInterface"-type method later
if/when you wanted.
Anyway, I think I do like the last proposal, the class/native method
best.
Thanks, Goktug!
- Stephen
--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/20141101102535.45715a48%40sh9.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAPVRV7eyW-Xw8SHefBOHff6ttUgh5X20ghSn0A9t9V_vcv0aHw%40mail.gmail.com.
@JsType(prototype = "Document")
public interface Document {
public HTMLElement createElement(String div);
public HTMLElement getElementsByTagName(String body);
@JsProperty
public HTMLBodyElement getBody();
public NodeList querySelector(String selector);
public NodeList querySelectorAll(String selector);
class prototype extends Prototype_Document {}
....
....
}
@PrototypeOfJsType(Document.class)
public class Prototype_Document{
....
....
public NodeList querySelectorAll(String selector){
//The question (How will called underlying code?)
}
}
public class MyDocument extends Document.prototype{
public void myMethod(){
//TODO
}
}
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/a10b0e54-eea9-4886-bfc0-1103eede4be2%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/2ccff98a-eb73-40b3-8535-ef456eec5ac7%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.