From 3c340a6033e60dd2a385dc148fb1dcf837e057a6 Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Wed, 6 Jul 2011 19:08:08 +0000 Subject: [PATCH] Extend AS boxing functionality to also allow getting the imports togetherf git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6675 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/tools/GenUtil.java | 64 +++++++++++++------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/threerings/presents/tools/GenUtil.java b/src/main/java/com/threerings/presents/tools/GenUtil.java index 8e0fb9ee6..2ae9bf9bf 100644 --- a/src/main/java/com/threerings/presents/tools/GenUtil.java +++ b/src/main/java/com/threerings/presents/tools/GenUtil.java @@ -146,25 +146,18 @@ public class GenUtil extends com.samskivert.util.GenUtil */ public static String boxASArgument (Class clazz, String name) { - if (clazz == Boolean.TYPE) { - return "langBoolean.valueOf(" + name + ")"; - } else if (clazz == Byte.TYPE) { - return "Byte.valueOf(" + name + ")"; - } else if (clazz == Character.TYPE) { - return "Character.valueOf(" + name + ")"; - } else if (clazz == Short.TYPE) { - return "Short.valueOf(" + name + ")"; - } else if (clazz == Integer.TYPE) { - return "Integer.valueOf(" + name + ")"; - } else if (clazz == Long.TYPE) { - return name; // Long is left as is - } else if (clazz == Float.TYPE) { - return "Float.valueOf(" + name + ")"; - } else if (clazz == Double.TYPE) { - return "Double.valueOf(" + name + ")"; - } else { - return name; - } + return boxASArgumentAndGatherImports(clazz, name, new ImportSet()); + } + + /** + * Calculates the set of imports required for the code to box the given class in actionscript. + * For example, for int, Integer.class will be returned. + */ + public static ImportSet getASBoxImports (Class clazz) + { + ImportSet imports = new ImportSet(); + boxASArgumentAndGatherImports(clazz, "foo", imports); + return imports; } /** @@ -277,4 +270,37 @@ public class GenUtil extends com.samskivert.util.GenUtil anno += ")"; return anno; } + + protected static String boxASArgumentAndGatherImports (Class clazz, String name, + ImportSet imports) + { + if (clazz == Boolean.TYPE) { + imports.add(Boolean.class); + return "langBoolean.valueOf(" + name + ")"; + } else if (clazz == Byte.TYPE) { + imports.add(Byte.class); + return "Byte.valueOf(" + name + ")"; + } else if (clazz == Character.TYPE) { + imports.add(Character.class); + return "Character.valueOf(" + name + ")"; + } else if (clazz == Short.TYPE) { + imports.add(Short.class); + return "Short.valueOf(" + name + ")"; + } else if (clazz == Integer.TYPE) { + imports.add(Integer.class); + return "Integer.valueOf(" + name + ")"; + } else if (clazz == Long.TYPE) { + imports.add(Long.class); + return name; // Long is left as is + } else if (clazz == Float.TYPE) { + imports.add(Float.class); + return "Float.valueOf(" + name + ")"; + } else if (clazz == Double.TYPE) { + imports.add(Double.class); + return "Double.valueOf(" + name + ")"; + } else { + imports.add(name); + return name; + } + } }