optimized toArray conversion

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4525 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Brian Remedios
2006-09-23 14:40:16 +00:00
parent 785b64e8e6
commit 04d087a48d
2 changed files with 14 additions and 12 deletions

View File

@ -53,7 +53,7 @@ public class SimpleRenderer implements Renderer {
if (perl5Util != null) { // trimming wanted?
List list = new ArrayList();
perl5Util.split(list, PMD.EOL, source, 0);
String[] lines = (String[])list.toArray(new String[] {});
String[] lines = (String[])list.toArray(new String[list.size()]);
int trimDepth = StringUtil.maxCommonLeadingWhitespaceForAll(lines);
if (trimDepth > 0) {
lines = StringUtil.trimStartOn(lines, trimDepth);

View File

@ -51,7 +51,7 @@ public class AttributeAxisIterator implements Iterator {
Method[] preFilter = contextNode.getClass().getMethods();
List postFilter = new ArrayList();
for (int i = 0; i < preFilter.length; i++) {
if (isAttribute(preFilter[i])) {
if (isAttributeAccessor(preFilter[i])) {
postFilter.add(new MethodWrapper(preFilter[i]));
}
}
@ -84,21 +84,23 @@ public class AttributeAxisIterator implements Iterator {
if (position == methodWrappers.length) {
return null;
}
MethodWrapper m = methodWrappers[position];
position++;
MethodWrapper m = methodWrappers[position++];
return new Attribute(node, m.name, m.method);
}
protected boolean isAttribute(Method method) {
protected boolean isAttributeAccessor(Method method) {
String methodName = method.getName();
return (Integer.TYPE == method.getReturnType() || Boolean.TYPE == method.getReturnType() || String.class == method.getReturnType())
&& (method.getParameterTypes().length == 0)
&& (Void.TYPE != method.getReturnType())
&& !method.getName().startsWith("jjt")
&& !method.getName().equals("toString")
&& !method.getName().equals("getScope")
&& !method.getName().equals("getClass")
&& !method.getName().equals("getTypeNameNode")
&& !method.getName().equals("getImportedNameNode")
&& !method.getName().equals("hashCode");
&& !methodName.startsWith("jjt")
&& !methodName.equals("toString")
&& !methodName.equals("getScope")
&& !methodName.equals("getClass")
&& !methodName.equals("getTypeNameNode")
&& !methodName.equals("getImportedNameNode")
&& !methodName.equals("hashCode");
}
}