From 04d087a48d7e3f72c718168530ada8caf8c03a81 Mon Sep 17 00:00:00 2001 From: Brian Remedios Date: Sat, 23 Sep 2006 14:40:16 +0000 Subject: [PATCH] optimized toArray conversion git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4525 51baf565-9d33-0410-a72c-fc3788e3496d --- .../sourceforge/pmd/cpd/SimpleRenderer.java | 2 +- .../pmd/jaxen/AttributeAxisIterator.java | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/cpd/SimpleRenderer.java b/pmd/src/net/sourceforge/pmd/cpd/SimpleRenderer.java index f8478578b7..fe85ea27c1 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/SimpleRenderer.java +++ b/pmd/src/net/sourceforge/pmd/cpd/SimpleRenderer.java @@ -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); diff --git a/pmd/src/net/sourceforge/pmd/jaxen/AttributeAxisIterator.java b/pmd/src/net/sourceforge/pmd/jaxen/AttributeAxisIterator.java index bf819b6c41..b6af316a20 100644 --- a/pmd/src/net/sourceforge/pmd/jaxen/AttributeAxisIterator.java +++ b/pmd/src/net/sourceforge/pmd/jaxen/AttributeAxisIterator.java @@ -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"); } } \ No newline at end of file