Search in sources :

Example 16 with JXPathContext

use of org.apache.commons.jxpath.JXPathContext in project freud by LMAX-Exchange.

the class MethodCallJdom method getMethodName.

@SuppressWarnings("unchecked")
public String getMethodName() {
    if (methodName == null) {
        final Attribute idAttr = methodCallElement.getAttribute(JdomTreeAdaptor.ID_ATTR);
        if (idAttr != null) {
            methodName = idAttr.getValue();
            instanceReferences = EMPTY_ARRAY;
        } else {
            JXPathContext context = JXPathContext.newContext(methodCallElement);
            final List<Element> identElementList = context.selectNodes("//" + JavaSourceTokenType.IDENT.getName());
            Collections.sort(identElementList, JdomTreePositionComparator.getInstance());
            final int methodNameIndex = identElementList.size() - 1;
            methodName = identElementList.get(methodNameIndex).getText();
            instanceReferences = new String[methodNameIndex];
            for (int i = 0, size = instanceReferences.length; i < size; i++) {
                instanceReferences[i] = identElementList.get(i).getText();
            }
        }
    }
    return methodName;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 17 with JXPathContext

use of org.apache.commons.jxpath.JXPathContext in project freud by LMAX-Exchange.

the class MethodDeclarationJdom method getImplementation.

public CodeBlock getImplementation() {
    if (methodCodeBlock == null) {
        try {
            JXPathContext context = JXPathContext.newContext(methodDeclElement);
            Element codeBlockElement = (Element) context.selectSingleNode("/" + JavaSourceTokenType.BLOCK_SCOPE.getName());
            methodCodeBlock = CodeBlockJdom.createMethodImplementation(codeBlockElement, this, classDeclaration);
        } catch (JXPathException e) {
            return null;
        }
    }
    return methodCodeBlock;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) JXPathException(org.apache.commons.jxpath.JXPathException)

Example 18 with JXPathContext

use of org.apache.commons.jxpath.JXPathContext in project opennms by OpenNMS.

the class JsonCollectorArrayIT method testXpath.

@Test
@SuppressWarnings("unchecked")
public void testXpath() throws Exception {
    JSONObject json = MockDocumentBuilder.getJSONDocument();
    JXPathContext context = JXPathContext.newContext(json);
    Iterator<Pointer> itr = context.iteratePointers("/elements[4]/it");
    Assert.assertTrue(itr.hasNext());
    Assert.assertEquals(itr.next().getValue(), "works");
    Assert.assertFalse(itr.hasNext());
}
Also used : JSONObject(net.sf.json.JSONObject) JXPathContext(org.apache.commons.jxpath.JXPathContext) Pointer(org.apache.commons.jxpath.Pointer) Test(org.junit.Test)

Example 19 with JXPathContext

use of org.apache.commons.jxpath.JXPathContext in project galley by Commonjava.

the class JXPathUtils method newContext.

public static JXPathContext newContext(final Node node) {
    final JXPathContext ctx = JXPathContext.newContext(node);
    ctx.setLenient(true);
    ctx.setFunctions(new ClassFunctions(ResolveFunctions.class, "ext"));
    return ctx;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) ClassFunctions(org.apache.commons.jxpath.ClassFunctions)

Aggregations

JXPathContext (org.apache.commons.jxpath.JXPathContext)19 Element (org.jdom.Element)12 List (java.util.List)6 JXPathException (org.apache.commons.jxpath.JXPathException)6 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)3 JSONObject (net.sf.json.JSONObject)3 Pointer (org.apache.commons.jxpath.Pointer)3 Test (org.junit.Test)3 Collections.emptyList (java.util.Collections.emptyList)2 JavaSourceTokenType (org.freud.analysed.javasource.parser.JavaSourceTokenType)2 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Stack (java.util.Stack)1 ExpressionEvaluationException (org.apache.camel.ExpressionEvaluationException)1 ClassFunctions (org.apache.commons.jxpath.ClassFunctions)1 CssRule (org.freud.analysed.css.rule.CssRule)1 CssDeclaration (org.freud.analysed.css.rule.declaration.CssDeclaration)1 Annotation (org.freud.analysed.javasource.Annotation)1 ClassDeclaration (org.freud.analysed.javasource.ClassDeclaration)1