From bef2183dc7174bc37a3adf46a0d666264f3ba155 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Barisich Date: Fri, 19 Jul 2013 12:02:37 -0300 Subject: [PATCH 1/2] ConsecutiveAppendsShouldReuse rule --- .../xml/ConsecutiveAppendsShouldReuse.xml | 187 ++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveAppendsShouldReuse.xml diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveAppendsShouldReuse.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveAppendsShouldReuse.xml new file mode 100644 index 0000000000..55c8c8d93a --- /dev/null +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveAppendsShouldReuse.xml @@ -0,0 +1,187 @@ + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 2 + + + + + 2 + + + + + 0 + + + From 3cb34969eb122a2c55a6580364ca1478300e7ab9 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Barisich Date: Fri, 19 Jul 2013 12:05:24 -0300 Subject: [PATCH 2/2] ConsecutiveAppendsShouldReuse rule --- .../main/resources/rulesets/java/strings.xml | 52 +++++++++++++++++++ .../java/rule/strings/StringsRulesTest.java | 1 + 2 files changed, 53 insertions(+) diff --git a/pmd/src/main/resources/rulesets/java/strings.xml b/pmd/src/main/resources/rulesets/java/strings.xml index 668e83518a..c5cbaba164 100644 --- a/pmd/src/main/resources/rulesets/java/strings.xml +++ b/pmd/src/main/resources/rulesets/java/strings.xml @@ -147,6 +147,58 @@ sb.append('a'); // use this instead + + +Consecutively calls to StringBuffer/StringBuilder .append must reuse the target object. This will improve the performance. + + 3 + + + + + + + + + + + +