diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java index c9a67bb9cb..c2bdf71f42 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java @@ -16,7 +16,6 @@ import net.sourceforge.pmd.lang.apex.ast.ASTReturnStatement; import net.sourceforge.pmd.lang.apex.ast.ASTStatement; import net.sourceforge.pmd.lang.apex.ast.ASTThrowStatement; import net.sourceforge.pmd.lang.apex.ast.ASTTryCatchFinallyBlockStatement; -import net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration; import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement; import net.sourceforge.pmd.lang.apex.ast.ApexNode; import net.sourceforge.pmd.lang.apex.rule.AbstractStatisticalApexRule; @@ -158,13 +157,8 @@ public abstract class AbstractNcssCountRule extends AbstractStatisticalApexRule return NumericConstants.ONE; } - @Override - public Object visit(ASTVariableDeclaration node, Object data) { - return countNodeChildren(node, data); - } - @Override public Object visit(ASTMethodCallExpression node, Object data) { - return countNodeChildren(node, data); + return NumericConstants.ONE; } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java index b661ef862d..64cffecd52 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java @@ -144,6 +144,13 @@ public class ApexOpenRedirectRule extends AbstractApexRule { } } + private void addVariable(AbstractApexNode node) { + ASTVariableExpression variable = node.getFirstChildOfType(ASTVariableExpression.class); + if (variable != null) { + listOfStringLiteralVariables.add(Helper.getFQVariableName(variable)); + } + } + /** * Traverses all new declarations to find PageReferences * diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/complexity/xml/NcssMethodCount.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/complexity/xml/NcssMethodCount.xml index 6879b0d3c7..ccc0fd10d2 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/complexity/xml/NcssMethodCount.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/complexity/xml/NcssMethodCount.xml @@ -103,5 +103,28 @@ public class Foo { } ]]> + + Github issue #183 - lines are counted properly + 10 + 0 + +@isTest +private class AcceptanceTests_Test { + @isTest + private static void test() { + // Setup + Opportunity o1 = new Opportunity() + .add(new Contact().foo(1) .bar(1).year(2012) .bar(1).price(5) .vol(100)) + .add(new Contact().foo(1) .bar(2).year(2013) .bar(1).price(5) .vol(110)) + .add(new Contact().foo(1) .bar(3).year(2014) .bar(1).price(5) .vol(120)) + .add(new Contact().foo(1) .bar(4).year(2015) .bar(1).price(5) .vol(130)) + .persist(); + + // Verify + System.assert(attribute()); + } +} + + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 362a0b79c4..a5c0e129bf 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -218,6 +218,8 @@ to avoid XSS attacks. * [#1542](https://sourceforge.net/p/pmd/bugs/1542/): \[java] CPD throws an NPE when parsing enums with -ignore-identifiers * apex-apexunit * [#1543](https://sourceforge.net/p/pmd/bugs/1543/): \[apex] ApexUnitTestClassShouldHaveAsserts assumes APEX is case sensitive +* apex-complexity + * [#183](https://github.com/pmd/pmd/issues/183): \[apex] NCSS Method length is incorrect when using method chaining * Java * [#1545](https://sourceforge.net/p/pmd/bugs/1545/): \[java] Symbol Table fails to resolve inner classes * java-design