Search in sources :

Example 31 with JXPathContext

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

the class JavaSourceJdom method parseImportDeclaration.

private List<ImportDeclaration> parseImportDeclaration() {
    try {
        final JXPathContext context = JXPathContext.newContext(root);
        final List importNodes = context.selectNodes("/" + JAVA_SOURCE_ROOT_ELEMENT_NAME + "/" + JavaSourceTokenType.IMPORT.name());
        importDeclarations = new ArrayList<ImportDeclaration>(importNodes.size());
        for (Object importNode : importNodes) {
            importDeclarations.add(new ImportDeclarationJdom((Element) importNode));
        }
    } catch (JXPathException e) {
        importDeclarations = emptyList();
    }
    return importDeclarations;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) ImportDeclaration(org.freud.analysed.javasource.ImportDeclaration) JXPathException(org.apache.commons.jxpath.JXPathException) Collections.emptyList(java.util.Collections.emptyList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 32 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 33 with JXPathContext

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

the class ClassDeclarationJdom method getInnerClassDeclarationByNameMap.

@SuppressWarnings("unchecked")
public Map<String, ClassDeclaration> getInnerClassDeclarationByNameMap() {
    if (innerClassDeclarationByNameMap == null) {
        JXPathContext context = JXPathContext.newContext(classDeclElement);
        innerClassDeclarationByNameMap = new LinkedHashMap<String, ClassDeclaration>();
        for (JavaSourceTokenType tokenType : POSSIBLE_CLASS_DECLARATION_TYPES) {
            final String tokenName = tokenType.getName();
            List<Element> innerClassElementList = context.selectNodes("/" + CLASS_TOP_LEVEL_SCOPE.getName() + "/" + tokenName);
            for (Element innerClassElement : innerClassElementList) {
                ClassDeclaration innerClass = new ClassDeclarationJdom(innerClassElement, DeclarationType.valueOf(tokenName), this);
                innerClassDeclarationByNameMap.put(innerClass.getName(), innerClass);
            }
        }
    }
    return innerClassDeclarationByNameMap;
}
Also used : ClassDeclaration(org.freud.analysed.javasource.ClassDeclaration) JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) JavaSourceTokenType(org.freud.analysed.javasource.parser.JavaSourceTokenType)

Example 34 with JXPathContext

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

the class ClassDeclarationJdom method getMethodDeclarationListByNameMap.

// TODO   Block getStaticBlock();
public Map<String, List<MethodDeclaration>> getMethodDeclarationListByNameMap() {
    if (methodDeclarationListByNameMap == null) {
        JXPathContext context = JXPathContext.newContext(classDeclElement);
        methodDeclarationListByNameMap = new LinkedHashMap<String, List<MethodDeclaration>>();
        getMethodDeclarationListByNameMap(context);
    }
    return methodDeclarationListByNameMap;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) List(java.util.List) LinkedList(java.util.LinkedList)

Example 35 with JXPathContext

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

the class CssJdomParser method parseCssRules.

@SuppressWarnings("unchecked")
static Iterable<CssRule> parseCssRules(final Reader reader) throws RecognitionException, IOException {
    List<CssRule> cssRuleList = new ArrayList<CssRule>();
    Document root = parseCssToDocument(reader);
    JXPathContext context = JXPathContext.newContext(root.getRootElement());
    List<Element> cssRuleElementList = (List<Element>) context.selectNodes("/RULE");
    for (Element element : cssRuleElementList) {
        final CssRuleJdom cssRuleJdom = new CssRuleJdom(element, 0);
        cssRuleList.add(cssRuleJdom);
        for (int i = 1; i < cssRuleJdom.getNumberOfCommaSeparatedSelectorLists(); i++) {
            cssRuleList.add(new CssRuleJdom(element, i));
        }
    }
    return cssRuleList;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) CssRule(org.freud.analysed.css.rule.CssRule) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.jdom.Document)

Aggregations

JXPathContext (org.apache.commons.jxpath.JXPathContext)37 Element (org.jdom.Element)12 JXPathException (org.apache.commons.jxpath.JXPathException)7 List (java.util.List)6 ArrayList (java.util.ArrayList)4 Document (org.w3c.dom.Document)4 Node (org.w3c.dom.Node)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 JXPathInvalidSyntaxException (org.apache.commons.jxpath.JXPathInvalidSyntaxException)3 Pointer (org.apache.commons.jxpath.Pointer)3 HttpResponse (org.apache.http.HttpResponse)3 StatusLine (org.apache.http.StatusLine)3 HttpClient (org.apache.http.client.HttpClient)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 Test (org.junit.Test)3 ModelJXPathContext (org.openforis.idm.model.expression.internal.ModelJXPathContext)3