1 16 package com.google.gwt.i18n.rebind; 17 18 import com.google.gwt.core.ext.TreeLogger; 19 import com.google.gwt.core.ext.UnableToCompleteException; 20 import com.google.gwt.core.ext.typeinfo.JMethod; 21 import com.google.gwt.user.rebind.AbstractGeneratorClassCreator; 22 23 import java.util.MissingResourceException ; 24 25 28 class ConstantsMapMethodCreator extends AbstractLocalizableMethodCreator { 29 34 public ConstantsMapMethodCreator(AbstractGeneratorClassCreator classCreator) { 35 super(classCreator); 36 } 37 38 45 public void createMethodFor(TreeLogger logger, JMethod method, 46 final String value) throws UnableToCompleteException { 47 String methodName = method.getName(); 48 49 if (method.getParameters().length > 0) { 50 error( 51 logger, 52 methodName 53 + " cannot have parameters; extend Messages instead if you need to create parameterized messages"); 54 } 55 enableCache(); 57 println("java.util.Map args = (java.util.Map) cache.get(" 59 + wrap(methodName) + ");"); 60 println("if (args == null){"); 62 indent(); 63 println("args = new com.google.gwt.i18n.client.impl.ConstantMap();"); 64 String [] args = ConstantsStringArrayMethodCreator.split(value); 65 66 for (int i = 0; i < args.length; i++) { 67 try { 68 String key = args[i]; 69 String keyValue = getResources().getString(key); 70 println("args.put(" + wrap(key) + ", " + wrap(keyValue) + ");"); 71 } catch (MissingResourceException e) { 72 String msg = "While implementing map for " + method.getName() 73 + "(), could not find key '" + args[i] + "'"; 74 throw error(logger, msg); 75 } 76 } 77 println("cache.put(" + wrap(methodName) + ", args);"); 78 println("}; "); 79 outdent(); 80 println("return args;"); 81 } 82 } 83 | Popular Tags |