List of usage examples for com.google.gwt.core.ext.typeinfo JPackage getTypes
JClassType[] getTypes();
From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private void generateLookups() { p("Map<String, Type> types = new HashMap<String, Type>();"); TypeOracle typeOracle = context.getTypeOracle(); JPackage[] packages = typeOracle.getPackages(); // gather all types from wanted packages for (JPackage p : packages) { for (JClassType t : p.getTypes()) { gatherTypes(t.getErasedType(), types); }// w ww . j a va 2 s. c o m } gatherTypes(typeOracle.findType("java.util.List").getErasedType(), types); gatherTypes(typeOracle.findType("java.util.ArrayList").getErasedType(), types); gatherTypes(typeOracle.findType("java.util.HashMap").getErasedType(), types); gatherTypes(typeOracle.findType("java.util.Map").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.String").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Boolean").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Byte").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Long").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Character").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Short").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Integer").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Float").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.CharSequence").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Double").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Object").getErasedType(), types); // sort the types so the generated output will be stable between runs Collections.sort(types, new Comparator<JType>() { public int compare(JType o1, JType o2) { return o1.getQualifiedSourceName().compareTo(o2.getQualifiedSourceName()); } }); // generate Type lookup generator methods. int id = 0; for (JType t : types) { String typeGen = createTypeGenerator(t); p("private void c" + (id++) + "() {"); p(typeGen); p("}\n"); } // generate constructor that calls all the type generators // that populate the map. p("public " + simpleName + "() {"); for (int i = 0; i < id; i++) { p("c" + i + "();"); } p("}"); // sort the stubs so the generated output will be stable between runs Collections.sort(setterGetterStubs, new Comparator<SetterGetterStub>() { @Override public int compare(SetterGetterStub o1, SetterGetterStub o2) { return new Integer(o1.setter).compareTo(o2.setter); } }); // generate field setters/getters for (SetterGetterStub stub : setterGetterStubs) { String stubSource = generateSetterGetterStub(stub); if (stubSource.equals("")) stub.unused = true; p(stubSource); } // sort the stubs so the generated output will be stable between runs Collections.sort(methodStubs, new Comparator<MethodStub>() { @Override public int compare(MethodStub o1, MethodStub o2) { return new Integer(o1.methodId).compareTo(o2.methodId); } }); // generate methods for (MethodStub stub : methodStubs) { String stubSource = generateMethodStub(stub); if (stubSource.equals("")) stub.unused = true; p(stubSource); } logger.log(Type.INFO, types.size() + " types reflected"); }
From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private void generateLookups() { TypeOracle typeOracle = context.getTypeOracle(); JPackage[] packages = typeOracle.getPackages(); // gather all types from wanted packages for (JPackage p : packages) { for (JClassType t : p.getTypes()) { gatherTypes(t.getErasedType(), types); }/*from w w w . j a va2 s .c o m*/ } // gather all types from explicitly requested packages try { ConfigurationProperty prop = context.getPropertyOracle() .getConfigurationProperty("gdx.reflect.include"); for (String s : prop.getValues()) { JClassType type = typeOracle.findType(s); if (type != null) gatherTypes(type.getErasedType(), types); } } catch (BadPropertyValueException e) { } gatherTypes(typeOracle.findType("java.util.List").getErasedType(), types); gatherTypes(typeOracle.findType("java.util.ArrayList").getErasedType(), types); gatherTypes(typeOracle.findType("java.util.HashMap").getErasedType(), types); gatherTypes(typeOracle.findType("java.util.Map").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.String").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Boolean").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Byte").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Long").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Character").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Short").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Integer").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Float").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.CharSequence").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Double").getErasedType(), types); gatherTypes(typeOracle.findType("java.lang.Object").getErasedType(), types); // sort the types so the generated output will be stable between runs Collections.sort(types, new Comparator<JType>() { public int compare(JType o1, JType o2) { return o1.getQualifiedSourceName().compareTo(o2.getQualifiedSourceName()); } }); // generate Type lookup generator methods. for (JType t : types) { p(createTypeGenerator(t)); } // generate reusable parameter objects parameterInitialization(); // sort the stubs so the generated output will be stable between runs Collections.sort(setterGetterStubs, new Comparator<SetterGetterStub>() { @Override public int compare(SetterGetterStub o1, SetterGetterStub o2) { return new Integer(o1.setter).compareTo(o2.setter); } }); // generate field setters/getters for (SetterGetterStub stub : setterGetterStubs) { String stubSource = generateSetterGetterStub(stub); if (stubSource.equals("")) stub.unused = true; p(stubSource); } // sort the stubs so the generated output will be stable between runs Collections.sort(methodStubs, new Comparator<MethodStub>() { @Override public int compare(MethodStub o1, MethodStub o2) { return new Integer(o1.methodId).compareTo(o2.methodId); } }); // generate methods for (MethodStub stub : methodStubs) { String stubSource = generateMethodStub(stub); if (stubSource.equals("")) stub.unused = true; p(stubSource); } logger.log(Type.INFO, types.size() + " types reflected"); }
From source file:com.mvp4g.rebind.AnnotationScanner.java
License:Apache License
public static Map<Class<? extends Annotation>, List<JClassType>> scan(TreeLogger logger, TypeOracle typeOracle, Class<? extends Annotation>[] annotationClasses) { Map<Class<? extends Annotation>, List<JClassType>> annotationMap = new HashMap<Class<? extends Annotation>, List<JClassType>>(); for (Class<? extends Annotation> c : annotationClasses) { annotationMap.put(c, new ArrayList<JClassType>()); }/* w w w . j av a 2 s .c o m*/ int nbClasses = 0; Date start = new Date(); for (JPackage pack : typeOracle.getPackages()) { for (JClassType type : pack.getTypes()) { for (Class<? extends Annotation> c : annotationClasses) { if (type.getAnnotation(c) != null) { annotationMap.get(c).add(type); } } } nbClasses += pack.getTypes().length; } Date end = new Date(); logger.log(TreeLogger.INFO, nbClasses + " classes scanned in " + Long.toString(end.getTime() - start.getTime()) + " ms."); return annotationMap; }
From source file:org.parallax3d.parallax.platforms.gwt.generator.SourceBundleFactoryGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { PrintWriter pw = context.tryCreate(logger, "org.parallax3d.parallax.platforms.gwt.preloader", "SourceBundleFactoryImpl"); if (pw != null) { // write package, imports, whatever pw.append("package org.parallax3d.parallax.platforms.gwt.preloader;"); pw.append("import org.parallax3d.parallax.system.SourceBundle;"); pw.append("import org.parallax3d.parallax.system.SourceBundleFactory;"); pw.append("import com.google.gwt.core.client.GWT;"); pw.append("import org.parallax3d.parallax.system.FastMap;"); // iterates over all the classes to find those with EntryPointWidget annotation TypeOracle oracle = context.getTypeOracle(); JPackage[] packages = oracle.getPackages(); System.out.println(" Start classpath text bundles generation "); FastMap<JClassType> genClasses = new FastMap<>(); for (JPackage pack : packages) { for (JClassType classtype : pack.getTypes()) { for (JClassType nestedClass : classtype.getNestedTypes()) { String cls = generateStaticInstance(oracle, logger, context, nestedClass); if (cls != null) genClasses.put(cls, nestedClass); }/*from ww w. j a v a 2 s . c om*/ String cls = generateStaticInstance(oracle, logger, context, classtype); if (cls != null) genClasses.put(cls, classtype); } } System.out.println(" " + genClasses.size() + " bundles have been generated"); // import generated classes for (String genClass : genClasses.keySet()) pw.append("import " + genClass + ";"); // the class pw.append("public class SourceBundleFactoryImpl implements SourceBundleFactory {"); pw.append(" private static final FastMap<SourceBundle> MAP = new FastMap<SourceBundle>(){{"); for (Map.Entry<String, JClassType> entry : genClasses.entrySet()) pw.append(" put(\"" + entry.getValue().getQualifiedSourceName() + "\", new " + entry.getKey() + "() );"); pw.append(" }};"); // get method pw.append(" public <T> T get(Class<? extends SourceBundle> classLiteral) {"); pw.append(" if (MAP.containsKey(classLiteral.getCanonicalName())) {"); pw.append(" return (T) MAP.get(classLiteral.getCanonicalName());"); pw.append(" }"); pw.append(" return null;"); pw.append(" }"); // method pw.append("}"); // class context.commit(logger, pw); } // return the name of the generated class return "org.parallax3d.parallax.platforms.gwt.preloader.SourceBundleFactoryImpl"; }
From source file:org.parallax3d.parallax.tests.generator.ParallaxTestCasesGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { PrintWriter pw = context.tryCreate(logger, "org.parallax3d.parallax.tests", "ParallaxTestCasesImpl"); if (pw != null) { // write package, imports, whatever pw.append("package org.parallax3d.parallax.tests;"); pw.append("import org.parallax3d.parallax.system.FastMap;"); pw.append("import java.util.ArrayList;"); pw.append("import java.util.Arrays;"); pw.append("import java.util.List;"); // iterates over all the classes to find those with EntryPointWidget annotation TypeOracle oracle = context.getTypeOracle(); JPackage[] packages = oracle.getPackages(); System.out.println(" Start GWT test generation "); List<JClassType> classes = new ArrayList<>(); JClassType testClass = oracle.findType(ParallaxTest.class.getName()); for (JPackage pack : packages) for (JClassType classtype : pack.getTypes()) if (classtype != testClass && testClass.isAssignableFrom(classtype)) classes.add(classtype); System.out.println(" " + classes.size() + " test cases found"); // the class pw.append("public class ParallaxTestCasesImpl implements ParallaxTestCases {"); pw.append(" static final FastMap<List<ParallaxTest>> byGroup = new FastMap<>();"); pw.append(" static final FastMap<ParallaxTest> byToken = new FastMap<>();"); pw.append(" static final List<ParallaxTest> all = new ArrayList<ParallaxTest>() {{"); for (JClassType cls : classes) pw.append(" add( new " + cls.getQualifiedSourceName() + "() );"); pw.append(" }};"); pw.append(" static {"); pw.append(" for (ParallaxTest test : all) {"); pw.append(" byToken.put(test.getContentWidgetToken(), test);"); pw.append(" String group = getProposalGroupName(test.getClass().getName());"); pw.append(" if (byGroup.containsKey(group)) byGroup.get(group).add(test);"); pw.append(//from w ww . jav a2 s .c om " else { List<ParallaxTest> tests = new ArrayList<>(); tests.add(test); byGroup.put(group, tests);}"); pw.append(" }"); pw.append(" }"); // get method pw.append(" private static String getProposalGroupName(String cls) {"); pw.append( " String name = cls.substring(0, cls.lastIndexOf(\".\") ).replace(\"org.parallax3d.parallax.tests.cases\",\"\");"); pw.append(" if(name.length() == 0) name = \"Unspecified\";"); pw.append(" else name = name.substring(1);"); pw.append(" return Character.toString(name.charAt(0)).toUpperCase() + name.substring(1);"); pw.append(" }"); // method pw.append(" public FastMap<List<ParallaxTest>> getAllTests() { return byGroup; }"); // method pw.append( " public ParallaxTest getContentWidgetForToken(String token) { return byToken.get(token); }"); // method pw.append("}"); // class context.commit(logger, pw); } // return the name of the generated class return "org.parallax3d.parallax.tests.ParallaxTestCasesImpl"; }
From source file:org.pentaho.mantle.rebind.CommandExecGenerator.java
License:Open Source License
private void generateMethods(SourceWriter sourceWriter) { sourceWriter.println();/* w w w . j a va2 s .c om*/ sourceWriter.println( "public native String getParameterString(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native Integer getParameterInteger(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native Boolean getParameterBoolean(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println("public native Float getParameterFloat(final String paramName," + "final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println("public native Double getParameterDouble(final String paramName, " + "final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native Long getParameterLong(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println("public native Short getParameterShort(final String paramName," + "final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter .println("public void execute(final String commandName, final JavaScriptObject parameterMap) { "); sourceWriter.indent(); try { // find Command implementors ArrayList<JClassType> implementingTypes = new ArrayList<JClassType>(); JPackage pack = typeOracle.getPackage(CommandExec.class.getPackage().getName()); JClassType commandSourceType = typeOracle.getType(Command.class.getName()); for (JClassType type : pack.getTypes()) { if (type.isAssignableTo(commandSourceType)) { implementingTypes.add(type); } } sourceWriter.println("if(false){}"); // placeholder for (JClassType implementingType : implementingTypes) { if (implementingType.isAbstract()) { continue; } sourceWriter.println( "else if(commandName.equals(\"" + implementingType.getSimpleSourceName() + "\")){"); sourceWriter.indent(); sourceWriter.println( implementingType.getName() + " command = new " + implementingType.getName() + "();"); for (JMethod eventMethod : implementingType.getMethods()) { if (eventMethod.isPublic() && !eventMethod.isStatic() && eventMethod.isConstructor() == null && eventMethod.getName().startsWith("set")) { String propertyName = eventMethod.getName().substring(3); propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1); String simpleType = implementingType.getField(propertyName).getType().getSimpleSourceName(); if ("string".equalsIgnoreCase(simpleType)) { sourceWriter.println("command." + eventMethod.getName() + "(getParameterString(\"" + propertyName + "\", parameterMap));"); } else if ("integer".equalsIgnoreCase(simpleType)) { sourceWriter.println("command." + eventMethod.getName() + "(getParameterInteger(\"" + propertyName + "\", parameterMap));"); } else if ("float".equalsIgnoreCase(simpleType)) { sourceWriter.println("command." + eventMethod.getName() + "(getParameterFloat(\"" + propertyName + "\", parameterMap));"); } else if ("double".equalsIgnoreCase(simpleType)) { sourceWriter.println("command." + eventMethod.getName() + "(getParameterDouble(\"" + propertyName + "\", parameterMap));"); } else if ("long".equalsIgnoreCase(simpleType)) { sourceWriter.println("command." + eventMethod.getName() + "(getParameterLong(\"" + propertyName + "\", parameterMap));"); } else if ("short".equalsIgnoreCase(simpleType)) { sourceWriter.println("command." + eventMethod.getName() + "(getParameterShort(\"" + propertyName + "\", parameterMap));"); } else if ("boolean".equalsIgnoreCase(simpleType)) { sourceWriter.println("command." + eventMethod.getName() + "(getParameterBoolean(\"" + propertyName + "\", parameterMap));"); } } } sourceWriter.println("command.execute();"); sourceWriter.outdent(); sourceWriter.println("}"); } } catch (Exception e) { // record to logger that Map generation threw an exception logger.log(TreeLogger.ERROR, "Error generating BindingContext!!!", e); } sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.pentaho.mantle.rebind.EventBusUtilGenerator.java
License:Open Source License
private void generateMethods(SourceWriter sourceWriter) { sourceWriter.println(//from www .j a v a 2 s. co m "public native void invokeEventBusJSO(final JavaScriptObject jso, final String parameterJSON)"); sourceWriter.println("/*-{"); sourceWriter.indent(); // unfortunately, we can obtain pairs like {"a":"undefined"} or even {"a":undefined} // the latter will crash the procedure, so let's try to clean up the string // by removing pairs with 'undefined' sourceWriter.println("var tmp = parameterJSON" // replace ("a":undefined) and ("a":"undefined") with empty space + ".replace(/\\\"[\\w]+\\\"\\:[ ]*(\\\")?undefined(\\\")?(,)?/g, '')" // remove doubled commas + ".replace(/,[ ]*,/, ',')" // remove leading and trailing commas + ".replace(/\\{[ ]*,/, '{')" + ".replace(/,[ ]*\\}/, '}');"); sourceWriter.println("var p = JSON.parse(tmp);"); sourceWriter.println("jso.call(this, p)"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native String getParameterString(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native Integer getParameterInteger(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native Boolean getParameterBoolean(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println("public native Float getParameterFloat(final String paramName, " + "final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native Double getParameterDouble(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println( "public native Long getParameterLong(final String paramName, final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); sourceWriter.println(); sourceWriter.println("public native Short getParameterShort(final String paramName, " + "final JavaScriptObject parameterMap)"); sourceWriter.println("/*-{"); sourceWriter.indent(); sourceWriter.println("return parameterMap[paramName];"); sourceWriter.outdent(); sourceWriter.println("}-*/;"); // ********************* // FIRE EVENT // ********************* sourceWriter.println(); sourceWriter .println("public void fireEvent(final String eventType, final JavaScriptObject parameterMap) { "); sourceWriter.indent(); try { // find Command implementors ArrayList<JClassType> implementingTypes = new ArrayList<JClassType>(); JPackage pack = typeOracle.getPackage(EventBusUtil.class.getPackage().getName()); JClassType eventSourceType = typeOracle.getType(GwtEvent.class.getName()); for (JClassType type : pack.getTypes()) { if (type.isAssignableTo(eventSourceType)) { implementingTypes.add(type); } } sourceWriter.println("if(false){}"); // placeholder for (JClassType implementingType : implementingTypes) { sourceWriter .println("else if(eventType.equals(\"" + implementingType.getSimpleSourceName() + "\")){"); sourceWriter.indent(); sourceWriter .println(implementingType.getName() + " event = new " + implementingType.getName() + "();"); for (JMethod eventMethod : implementingType.getMethods()) { if (eventMethod.isPublic() && !eventMethod.isStatic() && eventMethod.isConstructor() == null && eventMethod.getName().startsWith("set")) { String propertyName = eventMethod.getName().substring(3); propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1); String simpleType = implementingType.getField(propertyName).getType().getSimpleSourceName(); if ("string".equalsIgnoreCase(simpleType)) { sourceWriter.println("event." + eventMethod.getName() + "(getParameterString(\"" + propertyName + "\", parameterMap));"); } else if ("integer".equalsIgnoreCase(simpleType)) { sourceWriter.println("event." + eventMethod.getName() + "(getParameterInteger(\"" + propertyName + "\", parameterMap));"); } else if ("float".equalsIgnoreCase(simpleType)) { sourceWriter.println("event." + eventMethod.getName() + "(getParameterFloat(\"" + propertyName + "\", parameterMap));"); } else if ("double".equalsIgnoreCase(simpleType)) { sourceWriter.println("event." + eventMethod.getName() + "(getParameterDouble(\"" + propertyName + "\", parameterMap));"); } else if ("long".equalsIgnoreCase(simpleType)) { sourceWriter.println("event." + eventMethod.getName() + "(getParameterLong(\"" + propertyName + "\", parameterMap));"); } else if ("short".equalsIgnoreCase(simpleType)) { sourceWriter.println("event." + eventMethod.getName() + "(getParameterShort(\"" + propertyName + "\", parameterMap));"); } else if ("boolean".equalsIgnoreCase(simpleType)) { sourceWriter.println("event." + eventMethod.getName() + "(getParameterBoolean(\"" + propertyName + "\", parameterMap));"); } } } sourceWriter.println("EVENT_BUS.fireEvent(event);"); sourceWriter.outdent(); sourceWriter.println("}"); } } catch (Exception e) { // record to logger that Map generation threw an exception logger.log(TreeLogger.ERROR, "Error generating BindingContext!!!", e); } sourceWriter.outdent(); sourceWriter.println("}"); // ********************* // ADD HANDLER // ********************* sourceWriter.println(); sourceWriter.println( "public HandlerRegistration addHandler(final String eventType, final JavaScriptObject handler) { "); sourceWriter.indent(); try { // find Command implementors JPackage pack = typeOracle.getPackage(EventBusUtil.class.getPackage().getName()); JClassType eventSourceType = typeOracle.getType(GwtEvent.class.getName()); sourceWriter.println("if(false){return null;}"); // placeholder for (JClassType type : pack.getTypes()) { if (type.isAssignableTo(eventSourceType)) { addHandlerElseCondition(sourceWriter, type); } } } catch (Exception e) { // record to logger that Map generation threw an exception logger.log(TreeLogger.ERROR, "Error generating BindingContext!!!", e); } sourceWriter.indent(); sourceWriter.println("return null;"); sourceWriter.outdent(); sourceWriter.println("}"); }