From: Manuel Carrasco MoƱino Date: Sun, 8 Dec 2013 23:29:01 +0000 (+0100) Subject: JsniBundleGenerator: support for abstract classes X-Git-Tag: release-1.4.0~15^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0aff72f97a6780aedaab38659dc7950f4307ab33;p=gwtquery.git JsniBundleGenerator: support for abstract classes --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java index 342909de..4c4e56b2 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java @@ -42,31 +42,35 @@ import com.google.gwt.user.rebind.SourceWriter; /** * Generates an implementation of a user-defined interface T that * extends {@link JsniBundle}. - * + * * The generated implementation includes hand-written external js-files into * jsni methods so as those files can take advantage of gwt compiler optimizations. - * + * */ public class JsniBundleGenerator extends Generator { public String generate(TreeLogger logger, GeneratorContext context, String requestedClass) throws UnableToCompleteException { - + TypeOracle oracle = context.getTypeOracle(); JClassType clazz = oracle.findType(requestedClass); String packageName = clazz.getPackage().getName(); String className = clazz.getName().replace('.', '_') + "_Impl"; String fullName = packageName + "." + className; - + PrintWriter pw = context.tryCreate(logger, packageName, className); - - if (pw != null) { + if (pw != null) { ClassSourceFileComposerFactory fact = new ClassSourceFileComposerFactory(packageName, className); - fact.addImplementedInterface(requestedClass); + if (clazz.isInterface() != null) { + fact.addImplementedInterface(requestedClass); + } else { + fact.setSuperclass(requestedClass); + } + SourceWriter sw = fact.createSourceWriter(context, pw); - + if (sw != null) { for (JMethod method : clazz.getMethods()) { LibrarySource librarySource = method.getAnnotation(LibrarySource.class); @@ -92,7 +96,7 @@ public class JsniBundleGenerator extends Generator { // Adjust javascript so as we can introduce it in a JSNI comment block without // breaking java syntax. String jsni = parseJavascriptSource(content); - + pw.println(method.toString().replace("abstract", "native") + "/*-{"); pw.println(prepend); pw.println(jsni); @@ -103,9 +107,8 @@ public class JsniBundleGenerator extends Generator { throw new UnableToCompleteException(); } } - - sw.commit(logger); } + sw.commit(logger); } return fullName; @@ -166,7 +169,7 @@ public class JsniBundleGenerator extends Generator { * * The objective is to replace any 'c' comment-ending occurrence to avoid closing * JSNI comment blocks prematurely. - * + * * A Regexp based parser is not reliable, this approach is better and faster. */ // Note: this comment is intentionally using c++ style to allow writing the '*/' sequence.