From 0aff72f97a6780aedaab38659dc7950f4307ab33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Mon, 9 Dec 2013 00:29:01 +0100 Subject: [PATCH] JsniBundleGenerator: support for abstract classes --- .../gwt/query/rebind/JsniBundleGenerator.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) 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. -- 2.39.5