[plsql] Fix PMD dogfood issues

This commit is contained in:
Andreas Dangel
2022-02-03 12:49:31 +01:00
parent c172920011
commit 0d43acc11a
4 changed files with 14 additions and 22 deletions

View File

@ -53,7 +53,7 @@ public abstract class AbstractNcssCountRule<T extends PLSQLNode> extends Abstrac
return 1 + (Integer) node.jjtAccept(new NcssVisitor(), null);
}
private static class NcssVisitor extends PLSQLParserVisitorAdapter {
private static final class NcssVisitor extends PLSQLParserVisitorAdapter {
@Override
public Object visitPlsqlNode(PLSQLNode node, Object data) {

View File

@ -6,11 +6,11 @@ package net.sourceforge.pmd.lang.plsql.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.Stack;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.plsql.ast.ASTCaseStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTCaseWhenClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTConditionalOrExpression;
@ -65,16 +65,11 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
private boolean showClassesComplexity = true;
private boolean showMethodsComplexity = true;
private static class Entry {
private Node node;
private static final class Entry {
private int decisionPoints = 1;
public int highestDecisionPoints;
public int methodCount;
private Entry(Node node) {
this.node = node;
}
public void bumpDecisionPoints() {
decisionPoints++;
}
@ -88,7 +83,7 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
}
}
private Stack<Entry> entryStack = new Stack<>();
private Deque<Entry> entryStack = new ArrayDeque<>();
public CyclomaticComplexityRule() {
definePropertyDescriptor(REPORT_LEVEL_DESCRIPTOR);
@ -231,7 +226,7 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
public Object visit(ASTPackageBody node, Object data) {
LOGGER.entering(CLASS_NAME, "visit(ASTPackageBody)");
entryStack.push(new Entry(node));
entryStack.push(new Entry());
super.visit(node, data);
Entry classEntry = entryStack.pop();
if (LOGGER.isLoggable(Level.FINEST)) {
@ -252,7 +247,7 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
public Object visit(ASTTriggerUnit node, Object data) {
LOGGER.entering(CLASS_NAME, "visit(ASTTriggerUnit)");
entryStack.push(new Entry(node));
entryStack.push(new Entry());
super.visit(node, data);
Entry classEntry = entryStack.pop();
if (LOGGER.isLoggable(Level.FINEST)) {
@ -282,7 +277,7 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
@Override
public Object visit(ASTProgramUnit node, Object data) {
LOGGER.entering(CLASS_NAME, "visit(ASTProgramUnit)");
entryStack.push(new Entry(node));
entryStack.push(new Entry());
super.visit(node, data);
Entry methodEntry = entryStack.pop();
if (LOGGER.isLoggable(Level.FINEST)) {
@ -324,7 +319,7 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
@Override
public Object visit(ASTTypeMethod node, Object data) {
LOGGER.entering(CLASS_NAME, "visit(ASTTypeMethod)");
entryStack.push(new Entry(node));
entryStack.push(new Entry());
super.visit(node, data);
Entry methodEntry = entryStack.pop();
if (LOGGER.isLoggable(Level.FINEST)) {
@ -357,7 +352,7 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
@Override
public Object visit(ASTTriggerTimingPointSection node, Object data) {
LOGGER.entering(CLASS_NAME, "visit(ASTTriggerTimingPointSection)");
entryStack.push(new Entry(node));
entryStack.push(new Entry());
super.visit(node, data);
Entry methodEntry = entryStack.pop();
if (LOGGER.isLoggable(Level.FINE)) {

View File

@ -85,10 +85,6 @@ public class PLSQLNameOccurrence implements NameOccurrence {
* if (isStandAlonePostfix(primaryExpression)) { return true; }
*/
if (primaryExpression.getNumChildren() <= 1) {
return false;
}
/*
* if (!(primaryExpression.getChild(1) instanceof
* ASTAssignmentOperator)) { return false; }
@ -98,7 +94,7 @@ public class PLSQLNameOccurrence implements NameOccurrence {
* if (isCompoundAssignment(primaryExpression)) { return false; }
*/
return !isPartOfQualifiedName() /* and not is an array type */;
return primaryExpression.getNumChildren() > 1 && !isPartOfQualifiedName() /* and not is an array type */;
}
/*

View File

@ -4,7 +4,8 @@
package net.sourceforge.pmd.lang.plsql.symboltable;
import java.util.Stack;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -47,7 +48,7 @@ public class ScopeAndDeclarationFinder extends PLSQLParserVisitorAdapter {
* A stack of scopes reflecting the scope hierarchy when a node is visited.
* This is used to set the parents of the created scopes correctly.
*/
private Stack<Scope> scopes = new Stack<>();
private Deque<Scope> scopes = new ArrayDeque<>();
/**
* Sets the scope of a node and adjusts the scope stack accordingly. The