Search in sources :

Example 1 with DocumentNavigator

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;
    }
}
Also used : BaseXPath(org.jaxen.BaseXPath) XPath(org.jaxen.XPath) BaseXPath(org.jaxen.BaseXPath) JaxenException(org.jaxen.JaxenException) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) JaxenException(org.jaxen.JaxenException) ParseException(net.sourceforge.pmd.lang.ast.ParseException)

Example 2 with DocumentNavigator

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());
}
Also used : Node(net.sourceforge.pmd.lang.ast.Node) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Example 3 with DocumentNavigator

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());
}
Also used : Node(net.sourceforge.pmd.lang.ast.Node) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Example 4 with DocumentNavigator

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());
}
Also used : Node(net.sourceforge.pmd.lang.ast.Node) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Example 5 with DocumentNavigator

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());
}
Also used : Node(net.sourceforge.pmd.lang.ast.Node) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Aggregations

DocumentNavigator (net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator)13 Test (org.junit.Test)11 Node (net.sourceforge.pmd.lang.ast.Node)9 BaseXPath (org.jaxen.BaseXPath)3 ParseException (net.sourceforge.pmd.lang.ast.ParseException)1 Attribute (net.sourceforge.pmd.lang.ast.xpath.Attribute)1 DataFlowNode (net.sourceforge.pmd.lang.dfa.DataFlowNode)1 JaxenException (org.jaxen.JaxenException)1 XPath (org.jaxen.XPath)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1