ZOMG, Narya now perfectly passes our coding standards as enforced by

CheckStyle. The checks are slightly looser than I'd like but way better than
nothing and we get a bunch of other useful warnings like shadowed names and
other handy bits.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5253 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-07-22 14:36:54 +00:00
parent 5c4ab96880
commit 0a893e1de1
33 changed files with 159 additions and 124 deletions
@@ -78,17 +78,18 @@ public class ActionScriptSource
definition = definition.substring(0, definition.length()-1) + " = " + initValue + ";";
}
public void setComment (String comment) {
if (comment.indexOf("@Override") != -1) {
comment = comment.replaceAll("@Override ?", "");
comment = comment.replaceFirst("// //", "//"); // handle // @Override // comment
public void setComment (String newComment) {
if (newComment.indexOf("@Override") != -1) {
newComment = newComment.replaceAll("@Override ?", "");
// handle // @Override // comment
newComment = newComment.replaceFirst("// //", "//");
definition = "override " + definition;
}
// trim blank lines from start
while (comment.startsWith("\n")) {
comment = comment.substring(1);
while (newComment.startsWith("\n")) {
newComment = newComment.substring(1);
}
this.comment = StringUtil.isBlank(comment) ? "" : comment;
comment = StringUtil.isBlank(newComment) ? "" : newComment;
}
public void write (PrintWriter writer) {
@@ -1035,6 +1036,7 @@ public class ActionScriptSource
return true;
}
/** Denotes various phases of class file parsing. */
protected static enum Mode { PREAMBLE, IMPORTS, CLASSCOMMENT, CLASSDECL,
CLASSBODY, METHODBODY, POSTCLASS, POSTPKG };
@@ -56,7 +56,6 @@ public class GenActionScriptBundlesTask extends Task
@Override
public void execute ()
throws BuildException
{
// boilerplate
for (FileSet fs : _filesets) {
@@ -86,7 +86,7 @@ public class GenActionScriptTask extends Task
* Performs the actual work of the task.
*/
@Override
public void execute () throws BuildException
public void execute ()
{
try {
_velocity = VelocityUtil.createEngine();
@@ -80,7 +80,7 @@ public class GenDObjectTask extends Task
}
@Override
public void execute () throws BuildException
public void execute ()
{
if (_cloader == null) {
String errmsg = "This task requires a 'classpathref' attribute " +
@@ -101,6 +101,12 @@ public class GenServiceTask extends InvocationTask
listener.equals(((ServiceListener)other).listener);
}
@Override
public int hashCode ()
{
return listener.getName().hashCode();
}
public String getName ()
{
String name = GenUtil.simpleName(listener);
@@ -55,7 +55,7 @@ public class GenStreamableTask extends Task
}
@Override
public void execute () throws BuildException
public void execute ()
{
for (FileSet fs : _filesets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
@@ -31,17 +31,17 @@ import com.samskivert.util.ComparableArrayList;
import com.samskivert.util.StringUtil;
/**
* Manages a set of strings to be used as a set of imports. Provides useful functions for
* Manages a set of strings to be used as a set of imports. Provides useful functions for
* manipulating the set and sorts results.
*
* <p>Some methods in this class use a variable length String parameter 'replace'. This is a
* convenience for easily specifying multiple find/replace pairs. For example, to replace "Foo"
* with "Bar" and "123" with "ABC", a function can be called with the 4 arguments "Foo", "Bar",
*
* <p>Some methods in this class use a variable length String parameter 'replace'. This is a
* convenience for easily specifying multiple find/replace pairs. For example, to replace "Foo"
* with "Bar" and "123" with "ABC", a function can be called with the 4 arguments "Foo", "Bar",
* "123", "ABC" for the String... replace argument.
*
* <p>A few methods also use a "pattern" string parameter that is used to match a class name.
* This is a dumbed down regular expression (to avoid many \.) where "*" means .* and no other
* characters have special meaning. The pattern is also implicitly enclosed with ^$ so that the
*
* <p>A few methods also use a "pattern" string parameter that is used to match a class name.
* This is a dumbed down regular expression (to avoid many \.) where "*" means .* and no other
* characters have special meaning. The pattern is also implicitly enclosed with ^$ so that the
* pattern must match the class name in its entirity. Callers will mostly use this to specify a
* prefix like "something*" or a suffix like "*something".
*/
@@ -75,9 +75,9 @@ public class ImportSet
{
_imports.addAll(other._imports);
}
/**
* Adds a class' name to the imports but first performs the given list of search/replaces as
* Adds a class' name to the imports but first performs the given list of search/replaces as
* described above.
* @param clazz the class whose name is munged and added
* @param replace array of pairs to search/replace on the name before adding
@@ -85,8 +85,8 @@ public class ImportSet
public void addMunged (Class<?> clazz, String... replace)
{
String name = clazz.getName();
for (int i = 0 ; i < replace.length; i+=2) {
name = name.replace(replace[i], replace[i + 1]);
for (int ii = 0; ii < replace.length; ii += 2) {
name = name.replace(replace[ii], replace[ii+1]);
}
_imports.add(name);
}
@@ -98,7 +98,7 @@ public class ImportSet
newset.addAll(this);
return newset;
}
/**
* Gets rid of primitive and java.lang imports.
*/
@@ -109,13 +109,12 @@ public class ImportSet
String name = i.next();
if (name.indexOf('.') == -1) {
i.remove();
}
else if (name.startsWith("java.lang")) {
} else if (name.startsWith("java.lang")) {
i.remove();
}
}
}
/**
* Gets rid of array imports.
*/
@@ -123,7 +122,7 @@ public class ImportSet
{
return removeAll("[*");
}
/**
* Remove all classes that are in the same package.
* @param pkg package to remove
@@ -133,13 +132,13 @@ public class ImportSet
Iterator<String> i = _imports.iterator();
while (i.hasNext()) {
String name = i.next();
if (name.startsWith(pkg) &&
if (name.startsWith(pkg) &&
name.indexOf('.', pkg.length() + 1) == -1) {
i.remove();
}
}
}
/**
* Replaces inner class imports (those with a '$') with an import of the parent class.
*/
@@ -155,12 +154,12 @@ public class ImportSet
declarers.add(name.substring(0, dollar));
}
}
addAll(declarers);
}
/**
* Replace all inner classes' separator characters ('$') with an underscore ('_') for use
* Replace all inner classes' separator characters ('$') with an underscore ('_') for use
* when generating ActionScript.
*/
public void translateInnerClasses ()
@@ -175,10 +174,10 @@ public class ImportSet
inner.add(name.replace("$", "_"));
}
}
addAll(inner);
}
/**
* Inserts imports for the non-primitive classes contained in all array imports.
*/
@@ -194,7 +193,7 @@ public class ImportSet
arrayTypes.add(name.substring(bracket + 2, name.length() - 1));
}
}
addAll(arrayTypes);
}
@@ -220,7 +219,7 @@ public class ImportSet
}
/**
* Re-adds the most recently popped import to the set. If a null value was pushed, does
* Re-adds the most recently popped import to the set. If a null value was pushed, does
* nothing.
* @throws IndexOutOfBoundsException if there is nothing to pop
*/
@@ -231,7 +230,7 @@ public class ImportSet
_imports.add(front);
}
}
/**
* Removes the name of a class from the imports.
* @param clazz the class whose name should be removed
@@ -240,9 +239,9 @@ public class ImportSet
{
_imports.remove(clazz.getName());
}
/**
* Replaces any import exactly each find string with the corresponding replace string.
* Replaces any import exactly each find string with the corresponding replace string.
* See the description above.
* @param replace array of pairs for search/replace
*/
@@ -282,12 +281,12 @@ public class ImportSet
}
return removed;
}
/**
* Adds a new munged import for each existing import that matches a pattern. The new entry is
* a copy of the old entry but modified according to the given find/replace pairs (see
* Adds a new munged import for each existing import that matches a pattern. The new entry is
* a copy of the old entry but modified according to the given find/replace pairs (see
* description above).
* @param pattern to qualify imports to duplicate
* @param pattern to qualify imports to duplicate
* @param replace pairs to find/replace on the new import
*/
public void duplicateAndMunge (String pattern, String... replace)
@@ -301,7 +300,7 @@ public class ImportSet
}
for (String name : toMunge) {
String newname = name;
for (int i = 0; i < replace.length; i+=2) {
for (int i = 0; i < replace.length; i += 2) {
newname = newname.replace(replace[i], replace[i + 1]);
}
_imports.add(newname);
@@ -336,8 +335,7 @@ public class ImportSet
StringBuilder pattern = new StringBuilder();
pattern.append("^");
while (true)
{
while (true) {
String[] parts = _splitter.split(input, 2);
pattern.append(Pattern.quote(parts[0]));
if (parts.length == 1) {
@@ -347,8 +345,7 @@ public class ImportSet
String wildcard = input.substring(length, length + 1);
if (wildcard.equals("*")) {
pattern.append(".*");
}
else {
} else {
System.err.println("Bad wildcard " + wildcard);
}
input = parts[1];
@@ -360,6 +357,6 @@ public class ImportSet
protected HashSet<String> _imports = new HashSet<String>();
protected List<String> _pushed = new ArrayList<String>();
protected static Pattern _splitter = Pattern.compile("\\*");
}
@@ -80,7 +80,7 @@ public class InstrumentStreamableTask extends Task
}
@Override
public void execute () throws BuildException
public void execute ()
{
// configure our ClassPool with our classpath
for (Path path : _paths) {
@@ -311,7 +311,7 @@ public class InstrumentStreamableTask extends Task
if (field.getType().isPrimitive()) {
return body;
} else {
return "if (ins.readBoolean()) {\n" +
return "if (ins.readBoolean()) {\n" +
" " + body + "\n" +
" } else {\n" +
" " + field.getName() + " = null;\n" +
@@ -326,7 +326,7 @@ public abstract class InvocationTask extends Task
}
@Override
public void execute () throws BuildException
public void execute ()
{
if (_cloader == null) {
String errmsg = "This task requires a 'classpathref' attribute " +