From f53f6594de97943095076d5e194c8ba39cee916c Mon Sep 17 00:00:00 2001 From: David Renz Date: Fri, 15 Apr 2016 15:58:35 +0200 Subject: [PATCH] Formatting and minor changes --- .../pmd/lang/apex/ApexLanguageModule.java | 2 +- .../pmd/lang/apex/ast/ASTUserClass.java | 3 +- .../pmd/lang/apex/ast/ASTUserInterface.java | 3 +- .../pmd/lang/apex/ast/AbstractApexNode.java | 147 ++++++------ .../pmd/lang/apex/ast/ApexParser.java | 5 +- .../pmd/lang/apex/ast/CompilerService.java | 3 +- .../pmd/lang/apex/ast/DumpFacade.java | 6 +- .../pmd/lang/apex/rule/AbstractApexRule.java | 11 +- .../lang/apex/rule/ApexRuleChainVisitor.java | 5 +- .../rule/basic/AvoidLogicInTriggerRule.java | 2 +- .../apex/rule/basic/AvoidSoqlInLoopsRule.java | 2 +- .../rule/codesize/AbstractNcssCountRule.java | 216 +++++++++--------- .../codesize/ExcessiveClassLengthRule.java | 4 +- .../codesize/ExcessivePublicCountRule.java | 2 +- .../design/AvoidDeeplyNestedIfStmtsRule.java | 4 +- .../apex/rule/design/ExcessiveLengthRule.java | 8 - .../naming/VariableNamingConventionsRule.java | 3 +- .../pmd/lang/apex/ast/ApexParserTest.java | 18 +- .../apex/rule/codesize/CodesizeRulesTest.java | 6 +- 19 files changed, 215 insertions(+), 235 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java index 03d33b4fd7..bf5f46bce9 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java @@ -10,7 +10,7 @@ public class ApexLanguageModule extends BaseLanguageModule { public static final String NAME = "Apex"; public static final String TERSE_NAME = "apex"; - public static final String[] EXTENSIONS = {"cls", "trigger"}; + public static final String[] EXTENSIONS = { "cls", "trigger" }; public ApexLanguageModule() { super(NAME, null, TERSE_NAME, ApexRuleChainVisitor.class, EXTENSIONS); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java index f4a373f2bc..d9afc18ac1 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java @@ -25,8 +25,7 @@ public class ASTUserClass extends ApexRootNode { field.setAccessible(true); Identifier name = (Identifier) field.get(node); return name.value; - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } return super.getImage(); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java index c940fee287..a54deb010b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java @@ -25,8 +25,7 @@ public class ASTUserInterface extends ApexRootNode { field.setAccessible(true); Identifier name = (Identifier) field.get(node); return name.value; - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } return super.getImage(); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java index bade8c4971..73a8152e67 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java @@ -20,68 +20,74 @@ public abstract class AbstractApexNode extends AbstractNode i this.node = node; } - void calculateLineNumbers(SourceCodePositioner positioner) { - if (!hasRealLoc()) { - return; - } + void calculateLineNumbers(SourceCodePositioner positioner) { + if (!hasRealLoc()) { + return; + } - RealLoc loc = (RealLoc)node.getLoc(); - int startOffset = loc.startIndex; - int endOffset = loc.endIndex; + RealLoc loc = (RealLoc) node.getLoc(); + int startOffset = loc.startIndex; + int endOffset = loc.endIndex; - this.beginLine = positioner.lineNumberFromOffset(startOffset); - this.beginColumn = positioner.columnFromOffset(this.beginLine, startOffset); - this.endLine = positioner.lineNumberFromOffset(endOffset); - this.endColumn = positioner.columnFromOffset(this.endLine, endOffset) - 1; // end column is inclusive - if (this.endColumn < 0) { - this.endColumn = 0; - } - } + this.beginLine = positioner.lineNumberFromOffset(startOffset); + this.beginColumn = positioner.columnFromOffset(this.beginLine, startOffset); + this.endLine = positioner.lineNumberFromOffset(endOffset); + this.endColumn = positioner.columnFromOffset(this.endLine, endOffset) - 1; // end + // column + // is + // inclusive + if (this.endColumn < 0) { + this.endColumn = 0; + } + } - @Override - public int getBeginLine() { - if (this.beginLine > 0) { - return this.beginLine; - } - Node parent = jjtGetParent(); - if (parent != null) { - return parent.getBeginLine(); - } - throw new RuntimeException("Unable to determine beginning line of Node."); - } - @Override - public int getBeginColumn() { - if (this.beginColumn > 0) { - return this.beginColumn; - } - Node parent = jjtGetParent(); - if (parent != null) { - return parent.getBeginColumn(); - } - throw new RuntimeException("Unable to determine beginning column of Node."); - } - @Override - public int getEndLine() { - if (this.endLine > 0) { - return this.endLine; - } - Node parent = jjtGetParent(); - if (parent != null) { - return parent.getEndLine(); - } - throw new RuntimeException("Unable to determine ending line of Node."); - } - @Override - public int getEndColumn() { - if (this.endColumn > 0) { - return this.endColumn; - } - Node parent = jjtGetParent(); - if (parent != null) { - return parent.getEndColumn(); - } - throw new RuntimeException("Unable to determine ending column of Node."); - } + @Override + public int getBeginLine() { + if (this.beginLine > 0) { + return this.beginLine; + } + Node parent = jjtGetParent(); + if (parent != null) { + return parent.getBeginLine(); + } + throw new RuntimeException("Unable to determine beginning line of Node."); + } + + @Override + public int getBeginColumn() { + if (this.beginColumn > 0) { + return this.beginColumn; + } + Node parent = jjtGetParent(); + if (parent != null) { + return parent.getBeginColumn(); + } + throw new RuntimeException("Unable to determine beginning column of Node."); + } + + @Override + public int getEndLine() { + if (this.endLine > 0) { + return this.endLine; + } + Node parent = jjtGetParent(); + if (parent != null) { + return parent.getEndLine(); + } + throw new RuntimeException("Unable to determine ending line of Node."); + } + + @Override + public int getEndColumn() { + if (this.endColumn > 0) { + return this.endColumn; + } + Node parent = jjtGetParent(); + if (parent != null) { + return parent.getEndColumn(); + } + throw new RuntimeException("Unable to determine ending column of Node."); + } /** * Accept the visitor. * @@ -106,17 +112,14 @@ public abstract class AbstractApexNode extends AbstractNode i try { Loc loc = node.getLoc(); return loc instanceof RealLoc; - } - catch (UnexpectedCodePathException e) { + } catch (UnexpectedCodePathException e) { return false; - } - catch (IndexOutOfBoundsException e) { + } catch (IndexOutOfBoundsException e) { // bug in apex-jorje? happens on some ReferenceExpression nodes return false; - } - catch (NullPointerException e) { - // bug in apex-jorje? - return false; + } catch (NullPointerException e) { + // bug in apex-jorje? + return false; } } @@ -126,10 +129,10 @@ public abstract class AbstractApexNode extends AbstractNode i } public String getLocation() { - if (hasRealLoc()) { - return String.valueOf(node.getLoc()); - } else { - return "no location"; - } + if (hasRealLoc()) { + return String.valueOf(node.getLoc()); + } else { + return "no location"; + } } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java index 2a8ec8ff63..6483797ae0 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java @@ -25,7 +25,7 @@ public class ApexParser { protected final ApexParserOptions parserOptions; private Map suppressMap; - private String suppressMarker = "NOPMD"; // that's the default value + private String suppressMarker = "NOPMD"; public ApexParser(ApexParserOptions parserOptions) { this.parserOptions = parserOptions; @@ -57,8 +57,7 @@ public class ApexParser { ApexNode tree = treeBuilder.build(astRoot); return tree; - } - catch (IOException e) { + } catch (IOException e) { throw new ParseException(e); } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java index c38891dece..a75238883a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java @@ -128,8 +128,7 @@ public class CompilerService { .invoke(CompilerStage.ADDITIONAL_VALIDATE); operation.invoke(compilerContext, unit); } - } - catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/DumpFacade.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/DumpFacade.java index 849d5818d1..92aa17d169 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/DumpFacade.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/DumpFacade.java @@ -22,8 +22,7 @@ public class DumpFacade { this.dump(node, prefix); try { writer.flush(); - } - catch (IOException e) { + } catch (IOException e) { throw new RuntimeException("Problem flushing PrintWriter.", e); } } @@ -35,8 +34,7 @@ public class DumpFacade { visit((ApexNode) node.jjtGetChild(i), data + " "); } return data; - } - else { + } else { return data; } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java index 49c40a7323..3f7eaa127f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java @@ -115,21 +115,14 @@ public abstract class AbstractApexRule extends AbstractRule implements ApexParse for (Object element : nodes) { if (element instanceof ASTUserClass) { visit((ASTUserClass) element, ctx); - } - else if (element instanceof ASTUserInterface) { + } else if (element instanceof ASTUserInterface) { visit((ASTUserInterface) element, ctx); - } - else if (element instanceof ASTUserTrigger) { + } else if (element instanceof ASTUserTrigger) { visit((ASTUserTrigger) element, ctx); } } } - // - // The following APIs are identical to those in ApexParserVisitorAdapter. - // Due to Java single inheritance, it preferred to extend from the more - // complex Rule base class instead of from relatively simple Visitor. - // @Override public Object visit(ApexNode node, Object data) { node.childrenAccept(this, data); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleChainVisitor.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleChainVisitor.java index 35f92a4ced..692c83006f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleChainVisitor.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleChainVisitor.java @@ -18,7 +18,6 @@ import net.sourceforge.pmd.lang.rule.XPathRule; public class ApexRuleChainVisitor extends AbstractRuleChainVisitor { protected void indexNodes(List nodes, RuleContext ctx) { - // Visit Nodes in DFS order Stack stack = new Stack<>(); stack.addAll(nodes); Collections.reverse(stack); @@ -34,11 +33,9 @@ public class ApexRuleChainVisitor extends AbstractRuleChainVisitor { } protected void visit(Rule rule, Node node, RuleContext ctx) { - // Rule better either be a ApexParserVisitor, or a XPathRule if (rule instanceof XPathRule) { ((XPathRule) rule).evaluate(node, ctx); - } - else { + } else { ((ApexNode) node).jjtAccept((ApexParserVisitor) rule, ctx); } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidLogicInTriggerRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidLogicInTriggerRule.java index cc285a276c..889715e392 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidLogicInTriggerRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidLogicInTriggerRule.java @@ -29,7 +29,7 @@ public class AvoidLogicInTriggerRule extends AbstractApexRule { } n = n.jjtGetParent(); } - + return false; } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidSoqlInLoopsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidSoqlInLoopsRule.java index ffd19f1f99..7dee235a3a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidSoqlInLoopsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/basic/AvoidSoqlInLoopsRule.java @@ -40,7 +40,7 @@ public class AvoidSoqlInLoopsRule extends AbstractApexRule { } n = n.jjtGetParent(); } - + return false; } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/AbstractNcssCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/AbstractNcssCountRule.java index 7e4f8df2ec..85111af84d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/AbstractNcssCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/AbstractNcssCountRule.java @@ -24,139 +24,141 @@ import net.sourceforge.pmd.stat.DataPoint; import net.sourceforge.pmd.util.NumericConstants; /** - * Abstract superclass for NCSS counting methods. Counts tokens according to JavaNCSS rules. + * Abstract superclass for NCSS counting methods. Counts tokens according to + * JavaNCSS rules. * * @author ported from Java original of Jason Bennett */ public abstract class AbstractNcssCountRule extends AbstractStatisticalApexRule { - private Class nodeClass; + private Class nodeClass; - /** - * Count the nodes of the given type using NCSS rules. - * - * @param nodeClass class of node to count - */ - protected AbstractNcssCountRule(Class nodeClass) { - this.nodeClass = nodeClass; - } + /** + * Count the nodes of the given type using NCSS rules. + * + * @param nodeClass + * class of node to count + */ + protected AbstractNcssCountRule(Class nodeClass) { + this.nodeClass = nodeClass; + } - @Override - public Object visit(ApexNode node, Object data) { - int numNodes = 0; + @Override + public Object visit(ApexNode node, Object data) { + int numNodes = 0; - for (int i = 0; i < node.jjtGetNumChildren(); i++) { - ApexNode n = (ApexNode) node.jjtGetChild(i); - Integer treeSize = (Integer) n.jjtAccept(this, data); - numNodes += treeSize.intValue(); - } + for (int i = 0; i < node.jjtGetNumChildren(); i++) { + ApexNode n = (ApexNode) node.jjtGetChild(i); + Integer treeSize = (Integer) n.jjtAccept(this, data); + numNodes += treeSize.intValue(); + } - if (this.nodeClass.isInstance(node)) { - // Add 1 to account for base node - numNodes++; - DataPoint point = new DataPoint(); - point.setNode(node); - point.setScore(1.0 * numNodes); - point.setMessage(getMessage()); - addDataPoint(point); - } + if (this.nodeClass.isInstance(node)) { + // Add 1 to account for base node + numNodes++; + DataPoint point = new DataPoint(); + point.setNode(node); + point.setScore(1.0 * numNodes); + point.setMessage(getMessage()); + addDataPoint(point); + } - return Integer.valueOf(numNodes); - } + return Integer.valueOf(numNodes); + } - /** - * Count the number of children of the given Java node. Adds one to count - * the node itself. - * - * @param node java node having children counted - * @param data node data - * @return count of the number of children of the node, plus one - */ - protected Integer countNodeChildren(Node node, Object data) { - Integer nodeCount = null; - int lineCount = 0; - for (int i = 0; i < node.jjtGetNumChildren(); i++) { - nodeCount = (Integer) ((ApexNode) node.jjtGetChild(i)).jjtAccept(this, data); - lineCount += nodeCount.intValue(); - } - return ++lineCount; - } + /** + * Count the number of children of the given node. Adds one to count the + * node itself. + * + * @param node + * node having children counted + * @param data + * node data + * @return count of the number of children of the node, plus one + */ + protected Integer countNodeChildren(Node node, Object data) { + Integer nodeCount = null; + int lineCount = 0; + for (int i = 0; i < node.jjtGetNumChildren(); i++) { + nodeCount = (Integer) ((ApexNode) node.jjtGetChild(i)).jjtAccept(this, data); + lineCount += nodeCount.intValue(); + } + return ++lineCount; + } - @Override - public Object visit(ASTForLoopStatement node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTForLoopStatement node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTForEachStatement node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTForEachStatement node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTDoLoopStatement node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTDoLoopStatement node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTIfBlockStatement node, Object data) { + @Override + public Object visit(ASTIfBlockStatement node, Object data) { - Integer lineCount = countNodeChildren(node, data); - return lineCount; - } - + Integer lineCount = countNodeChildren(node, data); + return lineCount; + } - @Override - public Object visit(ASTIfElseBlockStatement node, Object data) { + @Override + public Object visit(ASTIfElseBlockStatement node, Object data) { - Integer lineCount = countNodeChildren(node, data); - lineCount++; + Integer lineCount = countNodeChildren(node, data); + lineCount++; - return lineCount; - } + return lineCount; + } - @Override - public Object visit(ASTWhileLoopStatement node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTWhileLoopStatement node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTBreakStatement node, Object data) { - return NumericConstants.ONE; - } + @Override + public Object visit(ASTBreakStatement node, Object data) { + return NumericConstants.ONE; + } - @Override - public Object visit(ASTTryCatchFinallyBlockStatement node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTTryCatchFinallyBlockStatement node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTContinueStatement node, Object data) { - return NumericConstants.ONE; - } + @Override + public Object visit(ASTContinueStatement node, Object data) { + return NumericConstants.ONE; + } - @Override - public Object visit(ASTReturnStatement node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTReturnStatement node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTThrowStatement node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTThrowStatement node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTStatement node, Object data) { - return NumericConstants.ONE; - } + @Override + public Object visit(ASTStatement node, Object data) { + return NumericConstants.ONE; + } - @Override - public Object visit(ASTVariableDeclaration node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTVariableDeclaration node, Object data) { + return countNodeChildren(node, data); + } - @Override - public Object visit(ASTMethodCallExpression node, Object data) { - return countNodeChildren(node, data); - } + @Override + public Object visit(ASTMethodCallExpression node, Object data) { + return countNodeChildren(node, data); + } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessiveClassLengthRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessiveClassLengthRule.java index 9ac3f76641..1526f21e14 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessiveClassLengthRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessiveClassLengthRule.java @@ -19,10 +19,10 @@ public class ExcessiveClassLengthRule extends ExcessiveLengthRule { @Override public Object visit(ASTUserClass node, Object data) { - if(node.getNode().getModifiers().getModifiers().not(IS_TEST)) { + if (node.getNode().getModifiers().getModifiers().not(IS_TEST)) { return super.visit(node, data); } - + return data; } } \ No newline at end of file diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessivePublicCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessivePublicCountRule.java index 6f456f0be1..b373c27dc6 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessivePublicCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessivePublicCountRule.java @@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.util.NumericConstants; /** - * @author aglover + * @author ported from Java original of aglover *

* Class Name: ExcessivePublicCount *

diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AvoidDeeplyNestedIfStmtsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AvoidDeeplyNestedIfStmtsRule.java index 52b5bc3833..405486622e 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AvoidDeeplyNestedIfStmtsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AvoidDeeplyNestedIfStmtsRule.java @@ -23,7 +23,7 @@ public class AvoidDeeplyNestedIfStmtsRule extends AbstractApexRule { public Object visit(ASTUserClass node, Object data) { depth = 0; depthLimit = getProperty(PROBLEM_DEPTH_DESCRIPTOR); - + return super.visit(node, data); } @@ -35,7 +35,7 @@ public class AvoidDeeplyNestedIfStmtsRule extends AbstractApexRule { addViolation(data, node); } depth--; - + return data; } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/ExcessiveLengthRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/ExcessiveLengthRule.java index c62c4873cf..4801941c4c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/ExcessiveLengthRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/ExcessiveLengthRule.java @@ -7,14 +7,6 @@ import net.sourceforge.pmd.lang.apex.ast.ApexNode; import net.sourceforge.pmd.lang.apex.rule.AbstractStatisticalApexRule; import net.sourceforge.pmd.stat.DataPoint; -/** - * This is a common super class for things which have excessive length. - *

- * i.e. LongMethod and LongClass rules. - *

- * To implement an ExcessiveLength rule, you pass in the Class of node you want - * to check, and this does the rest for you. - */ public class ExcessiveLengthRule extends AbstractStatisticalApexRule { private Class nodeClass; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/naming/VariableNamingConventionsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/naming/VariableNamingConventionsRule.java index 050cd5c571..0f04fddc52 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/naming/VariableNamingConventionsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/naming/VariableNamingConventionsRule.java @@ -151,8 +151,7 @@ public class VariableNamingConventionsRule extends AbstractApexRule { new Object[] { varName }); } return data; - } - else if (!isFinal) { + } else if (!isFinal) { String normalizedVarName = normalizeVariableName(varName, prefixes, suffixes); if (normalizedVarName.indexOf('_') >= 0) { diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java index 03a4230b95..c5e0465e05 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java @@ -48,10 +48,12 @@ public class ApexParserTest { ApexNode rootNode = parse(code); - assertPosition(rootNode, 1, 14, 6, 2); // whole source code, well from the beginning of the class name + assertPosition(rootNode, 1, 14, 6, 2); // whole source code, well from + // the beginning of the class + // name // Modifier of the class - doesn't work. This node just sees the // identifier ("SimpleClass") - //assertPosition(rootNode.jjtGetChild(0), 1, 1, 1, 6); // "public" + // assertPosition(rootNode.jjtGetChild(0), 1, 1, 1, 6); // "public" // "method1" - starts with identifier until end of its block statement Node method1 = rootNode.jjtGetChild(1); @@ -72,20 +74,20 @@ public class ApexParserTest { @Test public void verifyEndLine() { - + String code = "public class SimpleClass {\n" // line 1 + " public void method1() {\n" // line 2 + " }\n" // line 3 - + " public void method2() {\n" // line 4 + + " public void method2() {\n" // line 4 + " }\n" // line 5 + "}\n"; // line 6 ApexNode rootNode = parse(code); - + Node method1 = rootNode.jjtGetChild(1); assertEquals("Wrong begin line", 2, method1.getBeginLine()); assertEquals("Wrong end line", 3, method1.getEndLine()); - + Node method2 = rootNode.jjtGetChild(2); assertEquals("Wrong begin line", 4, method2.getBeginLine()); assertEquals("Wrong end line", 5, method2.getEndLine()); @@ -103,14 +105,12 @@ public class ApexParserTest { ApexNode rootNode = parse(sourceCode); } } - } - catch (IOException e) { + } catch (IOException e) { Assert.fail(); } } - // TEST HELPER private static void assertPosition(Node node, int beginLine, int beginColumn, int endLine, int endColumn) { diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/codesize/CodesizeRulesTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/codesize/CodesizeRulesTest.java index 701d0d028a..ec7ee8d5d4 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/codesize/CodesizeRulesTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/codesize/CodesizeRulesTest.java @@ -16,8 +16,8 @@ public class CodesizeRulesTest extends SimpleAggregatorTst { addRule(RULESET, "ExcessiveParameterList"); addRule(RULESET, "ExcessivePublicCount"); addRule(RULESET, "StdCyclomaticComplexity"); - addRule(RULESET, "NcssConstructorCount"); - addRule(RULESET, "NcssMethodCount"); - addRule(RULESET, "NcssTypeCount"); + addRule(RULESET, "NcssConstructorCount"); + addRule(RULESET, "NcssMethodCount"); + addRule(RULESET, "NcssTypeCount"); } }