From ae6e8f1bdb97675ac71289a760c154baea29d1eb Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 12 Nov 2007 19:37:08 +0000 Subject: [PATCH] We need to scan up the hierarchy so that if we're overriding a renamed method (e.g toString(StringBuffer)) we use the properly renamed version (e.g. toStringBuffer(StringBuffer)) when generating our ActionScript. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4870 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/tools/ActionScriptSource.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/java/com/threerings/presents/tools/ActionScriptSource.java b/src/java/com/threerings/presents/tools/ActionScriptSource.java index a22fad444..3d67f6dd7 100644 --- a/src/java/com/threerings/presents/tools/ActionScriptSource.java +++ b/src/java/com/threerings/presents/tools/ActionScriptSource.java @@ -367,6 +367,7 @@ public class ActionScriptSource list.add(mem); } + METHODS: for (Method method : jclass.getDeclaredMethods()) { int mods = method.getModifiers(); ArrayList list; @@ -379,15 +380,28 @@ public class ActionScriptSource } String name = method.getName(); - ActionScript asa = method.getAnnotation(ActionScript.class); - if (asa != null) { - if (asa.omit()) { - continue; + + // we have to scan our parent classes for annotations because we may be overriding this + // method and we want to "inherit" annotations + Class cclass = jclass; + do { + try { + Method cmethod = cclass.getMethod(name, method.getParameterTypes()); + ActionScript asa = cmethod.getAnnotation(ActionScript.class); + if (asa != null) { + if (asa.omit()) { + continue METHODS; + } + if (!StringUtil.isBlank(asa.name())) { + name = asa.name(); + } + } + } catch (NoSuchMethodException nsme) { + // thanks Java for insisting on using exceptions for a potentially expected + // code path; fall through and try the superclass } - if (!StringUtil.isBlank(asa.name())) { - name = asa.name(); - } - } + cclass = cclass.getSuperclass(); + } while (cclass != null); // if this is an auto-generated reader or writer method, skip it if (name.startsWith("readField_") || name.startsWith("writeField_")) {