Hi Brian, thanks for the feedback!
What you proposes is not so hard to add, but I want the API end users to 
not have to deal with GWT.create() at all. 

El lunes, 19 de agosto de 2013 19:18:24 UTC-3, Brian Slesinsky escribió:
>
> Interesting. I like the idea of replacing class parameters with something 
> else. I'm not sure we need to sweep the implementation under the rug. 
> Particularly in fancier scenarios, it might be easier to work with it 
> explicitly.
>
> Suppose we have:
>
> /** Encapsulates a GWT create call. */
> interface Creator<T> {
>   Class<?> getClassLiteral();
>   List<Object> getArgs();
>   T get();
> }
>
> public class GWT {
>   ...  
>
>    /** Performs a GWT.create() call an encapsulates the result. */
>    final <T> Creator<T> creator(Class<?> classLiteral, Object... args);
> }
>
> Then you can write code that takes a Creator:
>
> MyService s = createService(GWT.creator(MyService.class), arg);
>
> static <S extends FooService> S createService(Creator<S> creator, String 
> arg) {
>    S s = creator.get();
>    // do some initialization involving arg.
>    return s;
> }
>
> This is how you write it without any compiler magic. But we would also 
> support using a bare class:
>
> MyService s = createService(MyService.class, arg);
>
> static <S extends FooService> S createService(@Creator final Class<S> 
> theClass, String arg) {
>    S s = GWT.create(theClass);
>    // do some initialization involving arg.
>    return s;
> }
>
> The compiler rewrites any Class arg marked as @Creator to actually take a 
> Creator, inserts the GWT.creator() call at the call site, and replaces the 
> GWT.create() call with a creator.get() call in the API. So we have compiler 
> magic to make the API look pretty for simple cases, but it's not strictly 
> necessary since you could write the same thing yourself (at the cost of 
> some verbosity).
>
> (I bundled the arguments along with the class since that seemed like the 
> most conservative approach. I'm not sure what happens if you have 
> compile-time arguments coming from the different places than the class 
> itself.)
>

All the compile-time arguments are required to come from the same place, 
being all literal or all @GwtCreate arguments.

  Foo createFoo(@GwtCreate Class<? extends Foo> type, @GwtCreate.Param 
String str) {

    // This will compile
    GWT.create(type, str);

    // This will fail
    GWT.create(type, "hello");

    // This will compile
    GWT.create(Foo.class, "hello");
  }


- Andrés
 

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- 
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-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to