From 4c2e242261e9d9622a7cbfdb201690944792f2d7 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 5 Oct 2006 00:30:32 +0000 Subject: [PATCH] More jiggery pokery to create blank TypedArray instances of the proper type when we encounter the pattern "new SomeClass[0]". Le whee! git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4410 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/tools/ActionScriptSource.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/java/com/threerings/presents/tools/ActionScriptSource.java b/src/java/com/threerings/presents/tools/ActionScriptSource.java index b2b3292aa..edc9cbb28 100644 --- a/src/java/com/threerings/presents/tools/ActionScriptSource.java +++ b/src/java/com/threerings/presents/tools/ActionScriptSource.java @@ -61,9 +61,19 @@ public class ActionScriptSource } public void setInitialValue (String initValue) { + // if we're a typed array and we're being set to "new Something[0]" + // then convert that + if (definition.indexOf("TypedArray") != -1) { + Matcher m = ARRAYINIT.matcher(initValue); + if (m.matches()) { + initValue = "TypedArray.create(" + m.group(1) + ")"; + } + } + // do not-very-smart array conversion initValue = initValue.replaceAll("\\{", "["); initValue = initValue.replaceAll("\\}", "]"); + // stick the initial value before the semicolon definition = definition.substring(0, definition.length()-1) + " = " + initValue + ";"; @@ -988,4 +998,6 @@ public class ActionScriptSource ".*(?:public|protected)" + "(?:\\s+/\\*\\s*abstract\\s*\\*/)?" + "\\s+function\\s+([a-zA-Z]\\w*) \\(.*"); + + protected static Pattern ARRAYINIT = Pattern.compile("new (\\w+)\\[0\\]"); }