Move addExistingImports from GenActionScriptStreamableTask to ActionScriptUtils

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6641 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Tom Conkling
2011-05-19 00:52:29 +00:00
parent d2dd8c5b5d
commit 3a2d9d4aee
2 changed files with 28 additions and 26 deletions
@@ -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);
}
@@ -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);
}