use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.
the class ViewerModel method evaluateXPathExpression.
/**
* Evaluates the given XPath expression against the current tree.
*
* @param xPath
* XPath expression to be evaluated
* @param evaluator
* object which requests the evaluation
*/
public void evaluateXPathExpression(String xPath, Object evaluator) throws ParseException, JaxenException {
try {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("xPath=" + xPath);
LOGGER.finest("evaluator=" + evaluator);
}
XPath xpath = new BaseXPath(xPath, new DocumentNavigator());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("xpath=" + xpath);
LOGGER.finest("rootNode=" + rootNode);
}
try {
evaluationResults = xpath.selectNodes(rootNode);
} catch (Exception e) {
LOGGER.finest("selectNodes problem:");
e.printStackTrace(System.err);
}
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("evaluationResults=" + evaluationResults);
}
fireViewerModelEvent(new ViewerModelEvent(evaluator, ViewerModelEvent.PATH_EXPRESSION_EVALUATED));
} catch (JaxenException je) {
je.printStackTrace(System.err);
throw je;
}
}
use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.
the class DocumentNavigatorTest method testFollowingSiblingAxisIterator.
@Test
public void testFollowingSiblingAxisIterator() {
DocumentNavigator nav = new DocumentNavigator();
Iterator<Node> iter = nav.getFollowingSiblingAxisIterator(rule.primaryExpression.jjtGetChild(0));
assertSame(rule.primaryExpression.jjtGetChild(1), iter.next());
assertFalse(iter.hasNext());
}
use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.
the class DocumentNavigatorTest method testDescendantAxisIterator.
@Test
public void testDescendantAxisIterator() throws UnsupportedAxisException {
DocumentNavigator nav = new DocumentNavigator();
Iterator<?> iter = nav.getDescendantAxisIterator(rule.statement);
Node statementExpression = rule.statement.jjtGetChild(0);
assertSame(statementExpression, iter.next());
Node primaryExpression = statementExpression.jjtGetChild(0);
assertSame(primaryExpression, iter.next());
Node primaryPrefix = primaryExpression.jjtGetChild(0);
assertSame(primaryPrefix, iter.next());
Node primarySuffix = primaryExpression.jjtGetChild(1);
// assertSame(primarySuffix, iter.next());
Node name = primaryPrefix.jjtGetChild(0);
// assertSame(name, iter.next());
Node arguments = primarySuffix.jjtGetChild(0);
// assertSame(arguments, iter.next());
// assertFalse(iter.hasNext());
}
use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.
the class DocumentNavigatorTest method testPrecedingSiblingAxisIterator2.
@Test
public void testPrecedingSiblingAxisIterator2() {
DocumentNavigator nav = new DocumentNavigator();
Iterator<Node> iter = nav.getPrecedingSiblingAxisIterator(rule.primaryExpression.jjtGetChild(0));
assertFalse(iter.hasNext());
}
use of net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator in project pmd by pmd.
the class DocumentNavigatorTest method testFollowingSiblingAxisIterator2.
@Test
public void testFollowingSiblingAxisIterator2() {
DocumentNavigator nav = new DocumentNavigator();
Iterator<Node> iter = nav.getFollowingSiblingAxisIterator(rule.primaryExpression.jjtGetChild(1));
assertFalse(iter.hasNext());
}
Aggregations