From 3a2d9d4aee4c7b7ec4af0022b7c8276c1010777d Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Thu, 19 May 2011 00:52:29 +0000 Subject: [PATCH] Move addExistingImports from GenActionScriptStreamableTask to ActionScriptUtils git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6641 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/tools/ActionScriptUtils.java | 27 +++++++++++++++++++ .../tools/GenActionScriptStreamableTask.java | 27 +------------------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java b/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java index 96b18fa31..8cf75f1b6 100644 --- a/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java +++ b/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java @@ -24,6 +24,8 @@ package com.threerings.presents.tools; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.io.File; @@ -37,6 +39,26 @@ import com.threerings.util.StreamableHashSet; public class ActionScriptUtils { + /** + * Adds an existing ActionScript file's imports to the given ImportSet. + * @param asFile a String containing the contents of an ActionScript file + */ + public static void addExistingImports (String asFile, ImportSet imports) + { + // Discover the location of the 'public class' declaration. + // We won't search past there. + Matcher m = AS_PUBLIC_CLASS_DECL.matcher(asFile); + int searchTo = asFile.length(); + if (m.find()) { + searchTo = m.start(); + } + + m = AS_IMPORT.matcher(asFile.substring(0, searchTo)); + while (m.find()) { + imports.add(m.group(3)); + } + } + public static String addImportAndGetShortType (Class type, boolean isField, ImportSet imports) { @@ -249,4 +271,9 @@ public class ActionScriptUtils } protected static final Splitter DOT_SPLITTER = Splitter.on('.'); + + protected static final Pattern AS_PUBLIC_CLASS_DECL = Pattern.compile("^public class(.*)$", + Pattern.MULTILINE); + protected static final Pattern AS_IMPORT = Pattern.compile("^(\\s*)import(\\s+)([^;]*);", + Pattern.MULTILINE); } diff --git a/src/main/java/com/threerings/presents/tools/GenActionScriptStreamableTask.java b/src/main/java/com/threerings/presents/tools/GenActionScriptStreamableTask.java index d7ce9b296..c5b187991 100644 --- a/src/main/java/com/threerings/presents/tools/GenActionScriptStreamableTask.java +++ b/src/main/java/com/threerings/presents/tools/GenActionScriptStreamableTask.java @@ -27,9 +27,6 @@ import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.apache.tools.ant.Project; import com.google.common.base.Charsets; @@ -100,7 +97,7 @@ public class GenActionScriptStreamableTask extends GenTask // it a pain to keep additional imports out of the GENERATED PREAMBLE section of // class, so we just merge all the imports we find. if (existing != null) { - addExistingImports(existing, imports); + ActionScriptUtils.addExistingImports(existing, imports); } boolean isDObject = DObject.class.isAssignableFrom(sclass); @@ -163,23 +160,6 @@ public class GenActionScriptStreamableTask extends GenTask } } - protected static void addExistingImports (String asFile, ImportSet imports) - throws Exception - { - // Discover the location of the 'public class' declaration. - // We won't search past there. - Matcher m = AS_PUBLIC_CLASS_DECL.matcher(asFile); - int searchTo = asFile.length(); - if (m.find()) { - searchTo = m.start(); - } - - m = AS_IMPORT.matcher(asFile.substring(0, searchTo)); - while (m.find()) { - imports.add(m.group(3)); - } - } - protected static class ASField { public final String name; @@ -230,9 +210,4 @@ public class GenActionScriptStreamableTask extends GenTask /** The path to our ActionScript source files. */ protected File _asroot; - - protected static final Pattern AS_PUBLIC_CLASS_DECL = Pattern.compile("^public class(.*)$", - Pattern.MULTILINE); - protected static final Pattern AS_IMPORT = Pattern.compile("^(\\s*)import(\\s+)([^;]*);", - Pattern.MULTILINE); }