Search in sources :

Example 11 with JXPathContext

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

the class AnnotationJdom method getAnnotationValueForElement.

private String getAnnotationValueForElement(final Element element) {
    final JXPathContext context = JXPathContext.newContext(element);
    final Element expr = (Element) context.selectSingleNode("/" + JavaSourceTokenType.EXPR.name() + "/*");
    if (expr != null) {
        return expr.getText();
    } else {
        final List<Element> exprList = context.selectNodes("//" + JavaSourceTokenType.EXPR.name() + "/*");
        StringBuilder sb = new StringBuilder("{");
        for (Element item : exprList) {
            sb.append(item.getText()).append(",");
        }
        sb.setCharAt(sb.length() - 1, '}');
        return sb.toString();
    }
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element)

Example 12 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)

Example 13 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 14 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 15 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)

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