From ed51df08071faea35229c9640d934500cc257f36 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 4 Oct 2006 21:25:16 +0000 Subject: [PATCH] Add Hashable for classes that override hashCode(); strip out *Codes interfaces because we can't do that in ActionScript; properly handle static var and non-static const. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4404 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/tools/ActionScriptSource.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/java/com/threerings/presents/tools/ActionScriptSource.java b/src/java/com/threerings/presents/tools/ActionScriptSource.java index ce73a6523..dd5e21123 100644 --- a/src/java/com/threerings/presents/tools/ActionScriptSource.java +++ b/src/java/com/threerings/presents/tools/ActionScriptSource.java @@ -149,13 +149,14 @@ public class ActionScriptSource builder.append("private "); } - // are we static const or variable? + // are we static? if (Modifier.isStatic(mods)) { - builder.append("static const "); - } else { - builder.append("var "); + builder.append("static "); } + // const or variable? + builder.append(Modifier.isFinal(mods) ? "const " : "var "); + // next comes the name builder.append(field.getName()).append(" :"); @@ -300,9 +301,13 @@ public class ActionScriptSource // note our implemented interfaces ArrayList ifaces = new ArrayList(); for (Class iclass : jclass.getInterfaces()) { + // we cannot use the FooCodes interface pattern in ActionScript so + // we just have to nix it + if (iclass.getName().endsWith("Codes")) { + continue; + } ifaces.add(toSimpleName(iclass.getName())); } - implementedInterfaces = ifaces.toArray(new String[ifaces.size()]); // convert the field members for (Field field : jclass.getDeclaredFields()) { @@ -367,6 +372,14 @@ public class ActionScriptSource mem.definition = decl; } } + + // if we override hashCode() then add Hashable to our interfaces + if (getMember(publicMethods, "hashCode") != null) { + ifaces.add("Hashable"); + } + + // finally turn our implemented interfaces into an array + implementedInterfaces = ifaces.toArray(new String[ifaces.size()]); } public void absorbJava (File jsource)