use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.
the class PLSQLRuleChainVisitor method indexNodes.
@Override
protected void indexNodes(List<Node> nodes, RuleContext ctx) {
LOGGER.entering(CLASS_NAME, "indexNodes");
PLSQLParserVisitor plsqlParserVistor = new PLSQLParserVisitorAdapter() {
// Perform a visitation of the AST to index nodes which need
// visiting by type
@Override
public Object visit(PLSQLNode node, Object data) {
indexNode(node);
return super.visit(node, data);
}
};
for (int i = 0; i < nodes.size(); i++) {
plsqlParserVistor.visit((ASTInput) nodes.get(i), ctx);
}
LOGGER.exiting(CLASS_NAME, "indexNodes");
}
use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.
the class AbstractNcssCountRule method countNodeChildren.
/**
* Count the number of children of the given PLSQL node. Adds one to count
* the node itself.
*
* @param node
* PLSQL 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) ((PLSQLNode) node.jjtGetChild(i)).jjtAccept(this, data);
lineCount += nodeCount.intValue();
}
return ++lineCount;
}
use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.
the class AbstractNcssCountRule method visit.
@Override
public Object visit(PLSQLNode node, Object data) {
int numNodes = 0;
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
PLSQLNode n = (PLSQLNode) node.jjtGetChild(i);
Integer treeSize = (Integer) n.jjtAccept(this, data);
numNodes += treeSize.intValue();
}
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("Checking candidate " + node.getClass().getCanonicalName() + " against target class " + nodeClass.getCanonicalName() + " with " + numNodes + " nodes");
}
if (this.nodeClass.isInstance(node)) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Matched candidate " + node.getClass().getCanonicalName() + " against target class " + nodeClass.getCanonicalName());
}
// 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 (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Running score is " + point.getScore());
}
}
return Integer.valueOf(numNodes);
}
use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.
the class NcssObjectCountRule method visit.
/**
* Override super.visit(PLSQLNode, Object) for ASTProgramUnit nodes, only
* adding DataPoints for Schema-level Functions and Procedures
*/
@Override
public Object visit(ASTProgramUnit node, Object data) {
int numNodes = 0;
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
PLSQLNode n = (PLSQLNode) node.jjtGetChild(i);
Integer treeSize = (Integer) n.jjtAccept(this, data);
numNodes += treeSize.intValue();
}
// instances should result in DataPoints
if (node instanceof OracleObject && node.jjtGetParent() instanceof ASTGlobal) {
// 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 (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Running score is " + point.getScore());
}
}
return Integer.valueOf(numNodes);
}
use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.
the class NameFinder method checkForNameChild.
private void checkForNameChild(Node node) {
if (node.getImage() != null) {
add(new PLSQLNameOccurrence((PLSQLNode) node, node.getImage()));
}
if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTName) {
ASTName grandchild = (ASTName) node.jjtGetChild(0);
for (StringTokenizer st = new StringTokenizer(grandchild.getImage(), "."); st.hasMoreTokens(); ) {
add(new PLSQLNameOccurrence(grandchild, st.nextToken()));
}
}
if (node instanceof ASTPrimarySuffix) {
ASTPrimarySuffix suffix = (ASTPrimarySuffix) node;
if (suffix.isArguments()) {
PLSQLNameOccurrence occurrence = names.get(names.size() - 1);
occurrence.setIsMethodOrConstructorInvocation();
ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0);
occurrence.setArgumentCount(args.getArgumentCount());
}
// else if (suffix.jjtGetNumChildren() == 1
// && suffix.jjtGetChild(0) instanceof ASTMemberSelector)
// {
// add(new NameOccurrence((SimpleNode)suffix.jjtGetChild(0),
// suffix.jjtGetChild(0).getImage()));
// }
}
}
Aggregations