Merge pull request #4497 from adangel/apex-excessive-public-count

[apex] Improve ExcessivePublicCount message
This commit is contained in:
Juan Martín Sotuyo Dodero authored and GitHub committed 2023-04-22 10:34:44 -03:00
commit c138fbb441
6 files changed
+39 -10

No files matched your search

@@ -52,4 +52,8 @@ public class ExcessivePublicCountRule extends AbstractCounterCheckRule<ASTUserCl
return publicFields + publicMethods;
}
@Override
protected Object[] getViolationParameters(ASTUserClass node, int metric, int limit) {
return new Object[] { node.getSimpleName(), metric, limit };
}
}
@@ -31,7 +31,7 @@ public class NcssMethodCountRule extends AbstractNcssCountRule<ASTMethod> {
}
@Override
protected Object[] getViolationParameters(ASTMethod node, int metric) {
return new Object[]{ node.getImage(), metric };
protected Object[] getViolationParameters(ASTMethod node, int metric, int limit) {
return new Object[]{ node.getImage(), metric, limit };
}
}
@@ -48,9 +48,8 @@ public abstract class AbstractCounterCheckRule<T extends ApexNode<?>> extends Ab
protected abstract int defaultReportLevel();
protected Object[] getViolationParameters(T node, int metric) {
return new Object[] {metric};
protected Object[] getViolationParameters(T node, int metric, int limit) {
return new Object[] {metric, limit};
}
@@ -70,8 +69,9 @@ public abstract class AbstractCounterCheckRule<T extends ApexNode<?>> extends Ab
if (!isIgnored(t)) {
int metric = getMetric(t);
if (metric >= getProperty(reportLevel)) {
addViolation(data, node, getViolationParameters(t, metric));
int limit = getProperty(reportLevel);
if (metric >= limit) {
addViolation(data, node, getViolationParameters(t, metric, limit));
}
}
@@ -281,7 +281,7 @@ public void addPerson(Date birthdate, BodyMeasurements measurements, int ssn) {
<rule name="ExcessivePublicCount"
language="apex"
since="5.5.0"
message="This class has a bunch of public methods and attributes"
message="The class {0} has {1} public methods and attributes (limit: {2})"
class="net.sourceforge.pmd.lang.apex.rule.design.ExcessivePublicCountRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_design.html#excessivepubliccount">
<description>
@@ -340,7 +340,7 @@ public class Foo extends Bar {
<rule name="NcssMethodCount"
language="apex"
since="5.5.0"
message="The method ''{0}()'' has an NCSS line count of {1}"
message="The method ''{0}()'' has an NCSS line count of {1} (limit: {2})"
class="net.sourceforge.pmd.lang.apex.rule.design.NcssMethodCountRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_design.html#ncssmethodcount">
<description>
@@ -113,4 +113,29 @@ public class SomeClass {
}
]]></code>
</test-code>
<test-code>
<description>class with inner classes</description>
<rule-property name="minimum">1</rule-property>
<expected-problems>2</expected-problems>
<expected-linenumbers>1,5</expected-linenumbers>
<expected-messages>
<message>The class OuterClass has 2 public methods and attributes (limit: 1)</message>
<message>The class InnerClass has 4 public methods and attributes (limit: 1)</message>
</expected-messages>
<code><![CDATA[
public class OuterClass {
public int outerField1;
public int outerField2;
public class InnerClass {
public String field1;
public int field2;
public void method1() { }
public void method2() { }
}
}
]]></code>
</test-code>
</test-data>
@@ -71,7 +71,7 @@ public class Foo {
<rule-property name="minimum">13</rule-property>
<expected-problems>1</expected-problems>
<expected-messages>
<message>The method 'foo()' has an NCSS line count of 13</message>
<message>The method 'foo()' has an NCSS line count of 13 (limit: 13)</message>
</expected-messages>
<code-ref id="long-method"/>
</test-code>