use of net.sourceforge.pmd.lang.plsql.ast.ASTStatement in project pmd by pmd.
the class StatementAndBraceFinder method addForExpressionNode.
/*
* The method handles the special "for" loop. It creates always an
* expression node even if the loop looks like for(;;).
*/
// TODO: dfa implementation in plsql is incomplete
@SuppressWarnings("PMD.UnusedFormalParameter")
private void addForExpressionNode(Node node, Structure dataFlow) {
ASTForStatement parent = (ASTForStatement) node.jjtGetParent();
boolean hasExpressionChild = false;
for (int i = 0; i < parent.jjtGetNumChildren(); i++) {
if (parent.jjtGetChild(i) instanceof ASTExpression) {
hasExpressionChild = true;
}
}
if (!hasExpressionChild) {
if (node instanceof ASTStatement) {
/*
* if (!hasForInitNode && !hasForUpdateNode) {
* dataFlow.createNewNode(node);
* dataFlow.pushOnStack(NodeType.FOR_EXPR, dataFlow.getLast());
* }
*/
}
}
}
use of net.sourceforge.pmd.lang.plsql.ast.ASTStatement in project pmd by pmd.
the class StatementAndBraceFinder method visit.
// ----------------------------------------------------------------------------
// BRANCH OUT
@Override
public Object visit(ASTStatement node, Object data) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("entry ASTStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn() + " -> " + node.getClass().getCanonicalName());
}
if (!(data instanceof Structure)) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("immediate return ASTStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
}
return data;
}
Structure dataFlow = (Structure) data;
if (node.jjtGetParent() instanceof ASTForStatement) {
ASTForStatement st = (ASTForStatement) node.jjtGetParent();
if (node.equals(st.getFirstChildOfType(ASTStatement.class))) {
addForExpressionNode(node, dataFlow);
dataFlow.pushOnStack(NodeType.FOR_BEFORE_FIRST_STATEMENT, dataFlow.getLast());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("pushOnStack FOR_BEFORE_FIRST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
}
}
} else if (node.jjtGetParent() instanceof ASTLoopStatement) {
ASTLoopStatement st = (ASTLoopStatement) node.jjtGetParent();
if (node.equals(st.getFirstChildOfType(ASTStatement.class))) {
dataFlow.pushOnStack(NodeType.DO_BEFORE_FIRST_STATEMENT, dataFlow.getLast());
dataFlow.createNewNode(node.jjtGetParent());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("pushOnStack DO_BEFORE_FIRST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
}
}
}
super.visit(node, data);
if (node.jjtGetParent() instanceof ASTElseClause) {
List<ASTStatement> allStatements = node.jjtGetParent().findChildrenOfType(ASTStatement.class);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("ElseClause has " + allStatements.size() + " Statements ");
}
/*
* //Restrict to the last Statement of the Else Clause if (node ==
* allStatements.get(allStatements.size()-1) ) { if
* (node.jjtGetParent().jjtGetParent() instanceof ASTCaseStatement)
* { dataFlow.pushOnStack(NodeType.SWITCH_LAST_DEFAULT_STATEMENT,
* dataFlow.getLast()); LOGGER.finest(
* "pushOnStack (Else-Below Case) SWITCH_LAST_DEFAULT_STATEMENT: line "
* + node.getBeginLine() +", column " + node.getBeginColumn()); }
* /*SRT else // if (node == node.jjtGetParent() instanceof
* ASTElseClause) { {
* dataFlow.pushOnStack(NodeType.ELSE_LAST_STATEMENT,
* dataFlow.getLast()); LOGGER.finest(
* "pushOnStack (Else-Below If) ELSE_LAST_STATEMENT: line " +
* node.getBeginLine() +", column " + node.getBeginColumn()); }
*/
// }
} else if (node.jjtGetParent() instanceof ASTWhileStatement) {
ASTWhileStatement statement = (ASTWhileStatement) node.jjtGetParent();
List<ASTStatement> children = statement.findChildrenOfType(ASTStatement.class);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("(LastChildren): size " + children.size());
}
ASTStatement lastChild = children.get(children.size() - 1);
// the FOR Statment
if (node.equals(lastChild)) {
dataFlow.pushOnStack(NodeType.WHILE_LAST_STATEMENT, dataFlow.getLast());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("pushOnStack WHILE_LAST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
}
}
} else if (node.jjtGetParent() instanceof ASTForStatement) {
ASTForStatement statement = (ASTForStatement) node.jjtGetParent();
List<ASTStatement> children = statement.findChildrenOfType(ASTStatement.class);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("(LastChildren): size " + children.size());
}
ASTStatement lastChild = children.get(children.size() - 1);
// the FOR Statment
if (node.equals(lastChild)) {
dataFlow.pushOnStack(NodeType.FOR_END, dataFlow.getLast());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("pushOnStack (LastChildStatemnt) FOR_END: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
}
}
} else if (node.jjtGetParent() instanceof ASTLabelledStatement) {
dataFlow.pushOnStack(NodeType.LABEL_LAST_STATEMENT, dataFlow.getLast());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("pushOnStack LABEL_LAST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
}
}
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("exit ASTStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn() + " -> " + node.getClass().getCanonicalName() + " ->-> " + node.jjtGetParent().getClass().getCanonicalName());
}
return data;
}
Aggregations