Hi Isaac,
Looks like you read my mind because this exactly what I've started
experimenting with.
My code now looks like this:
public class JSNIJs {
@Target(ElementType.TYPE)
public @interface JsResource {
String[] resources();
}
}
public class AWrapper {
@JsResource(resources = { "b.js", "a.js" })
private class Js extends JSNIJs {
}
public AWrapper() {
GWT.create(Js.class);
}
}
public class JSNIGenerator extends Generator {
@Override
public String generate(TreeLogger logger, GeneratorContext context,
String typeName) throws UnableToCompleteException {
TypeOracle typeOracle = context.getTypeOracle();
try {
JClassType userType = typeOracle.getType(typeName);
JSNIJs.JsResource resource =
userType.getAnnotation(JSNIJs.JsResource.class);
if( resource == null ) {
logger.log(Type.ERROR, "JSNIJs needs to be
annotated with @JsResource");
throw new UnableToCompleteException();
}
String[] resources = resource.resources();
if( resources.length == 0 ) {
logger.log(Type.ERROR, "@JsResource needs to
hold at least one value");
}
for( String r : resources ) {
OutputStream outStream =
context.tryCreateResource(logger, "test/js/" + r);
if( outStream != null ) {
outStream.write("--- Used
---".getBytes());
context.commitResource(logger,
outStream);
}
}
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "testgen.client.JSNIJs";
}
}
This now writes an JS-Entry for every JS-File found. Ideally I could
write everything to one big fat-File but I couldn't find a way to
append something to a file until now in the generator API.
Thanks for your help.
Tom
On Wed, Dec 23, 2009 at 4:58 AM, Isaac Truett <[email protected]> wrote:
> Tom,
>
>> I thought about using the GWT Code Generation to get informed whenever
>> wrapper classes are used but as far as I understood this code
>> generation only jumps in when I use GWT.create() but this means my
>> Library users need to use GWT.create(AWrapper.class) instead of "new
>> AWrapper()" which is not very natural.
>
> If I understand your issue correctly, I think you could make it work
> by having your AWrapper constructor call
> GWT.create(AWrapperImpl.class) and delegate all of AWrapper's methods
> to the AWrapperImpl. That brings generators into the mix without
> creating a burdensome API.
>
> Make sense?
>
> - Isaac
>
>
> On Tue, Dec 22, 2009 at 3:17 PM, Tom <[email protected]> wrote:
>> Hi,
>>
>> I've been banging my head against something people here might probably
>> be able to help me. I've written a wrapper for a extensive JavaScript
>> Library which itself has a toolchain to optimize JS-Script code by
>> analyzing the used JS-API.
>>
>> As a small example say the js-library has:
>> * a.js
>> * b.js
>> * c.js
>>
>> And my wrappers look like this:
>> -----------8<-----------
>> AWrapper {
>> // ...
>> }
>>
>> BWrapper {
>> // ...
>> }
>>
>> CWrapper {
>> // ...
>> }
>> -----------8<-----------
>>
>> Now my problem is that if I want to use it with GWT I need to findout
>> which Wrapper-Classes the GWT application uses, spit out informations
>> I can feed into the external toolchain to create an optimized JS-
>> Library-Version.
>>
>> I thought about using the GWT Code Generation to get informed whenever
>> wrapper classes are used but as far as I understood this code
>> generation only jumps in when I use GWT.create() but this means my
>> Library users need to use GWT.create(AWrapper.class) instead of "new
>> AWrapper()" which is not very natural.
>>
>> My ideal thing would be to have annotate my Java-Wrappers with
>> something like this:
>>
>> -----------8<-----------
>> @JSResource("a.js")
>> AWrapper {
>> // ...
>> }
>>
>> @JSResource("b.js")
>> BWrapper {
>> // ...
>> }
>>
>> @JSResource("c.js")
>> CWrapper {
>> // ...
>> }
>> -----------8<-----------
>>
>> And somehow plug myself into the GWT-Compiler toolchain and get
>> informed when ever such a class is visited similar to what would
>> happen when I use GWT.create(). Does anybody have an idea or a
>> document, example source I can read though myself?
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "Google Web Toolkit" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.