Search in sources :

Example 1 with JavaSourceTokenType

use of org.freud.analysed.javasource.parser.JavaSourceTokenType in project freud by LMAX-Exchange.

the class JavaSourceJdom method parseClassDeclaration.

///////////////////////////////////////////////////////////////////////////////////////////////////////
private ClassDeclaration parseClassDeclaration() {
    JXPathContext context = JXPathContext.newContext(root);
    for (JavaSourceTokenType tokenType : POSSIBLE_CLASS_DECLARATION_TYPES) {
        try {
            final String tokenName = tokenType.name();
            final Element element = (Element) context.selectSingleNode("/" + JAVA_SOURCE_ROOT_ELEMENT_NAME + "/" + tokenName);
            if (element != null) {
                classDeclaration = new ClassDeclarationJdom(element, getDeclarationType(tokenType), null);
            }
        } catch (JXPathException e) {
        // ignore and try another path
        }
    }
    if (classDeclaration == null) {
        throw new IllegalStateException("Internal: could not find class declaration in: " + this);
    }
    return classDeclaration;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) JXPathException(org.apache.commons.jxpath.JXPathException) JavaSourceTokenType(org.freud.analysed.javasource.parser.JavaSourceTokenType) JdomTreeAdaptor.documentToString(org.freud.core.parser.JdomTreeAdaptor.documentToString)

Example 2 with JavaSourceTokenType

use of org.freud.analysed.javasource.parser.JavaSourceTokenType 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)

Aggregations

JXPathContext (org.apache.commons.jxpath.JXPathContext)2 JavaSourceTokenType (org.freud.analysed.javasource.parser.JavaSourceTokenType)2 Element (org.jdom.Element)2 JXPathException (org.apache.commons.jxpath.JXPathException)1 ClassDeclaration (org.freud.analysed.javasource.ClassDeclaration)1 JdomTreeAdaptor.documentToString (org.freud.core.parser.JdomTreeAdaptor.documentToString)1