Search in sources :

Example 6 with Element

use of org.jdom.Element in project freud by LMAX-Exchange.

the class JavaSourceJdom method parsePackagePath.

///////////////////////////////////////////////////////////////////////////////////////////////////////
public static String[] parsePackagePath(final Element element) {
    SortedSet<Element> packagePathElementSortedSet = new TreeSet<Element>(JdomTreePositionComparator.getInstance());
    for (Iterator iterator = element.getDescendants(new ElementFilter(JavaSourceTokenType.IDENT.getName())); iterator.hasNext(); ) {
        packagePathElementSortedSet.add((Element) iterator.next());
    }
    boolean endsWithDotStar = (element.getChild(JavaSourceTokenType.DOTSTAR.getName()) != null);
    final String[] packagePath = new String[(endsWithDotStar) ? packagePathElementSortedSet.size() + 1 : packagePathElementSortedSet.size()];
    int i = 0;
    for (Element pathElement : packagePathElementSortedSet) {
        packagePath[i++] = pathElement.getTextTrim();
    }
    if (endsWithDotStar) {
        packagePath[i] = "*";
    }
    return packagePath;
}
Also used : TreeSet(java.util.TreeSet) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) Iterator(java.util.Iterator) JdomTreeAdaptor.documentToString(org.freud.core.parser.JdomTreeAdaptor.documentToString)

Example 7 with Element

use of org.jdom.Element in project freud by LMAX-Exchange.

the class JavaSourceJdom method parsePackageDeclaration.

private PackageDeclaration parsePackageDeclaration() {
    try {
        JXPathContext context = JXPathContext.newContext(root);
        packageDeclaration = new PackageDeclarationJdom((Element) context.selectSingleNode("/" + JAVA_SOURCE_ROOT_ELEMENT_NAME + "/" + JavaSourceTokenType.PACKAGE.name()));
    } catch (JXPathException e) {
        packageDeclaration = new PackageDeclarationJdom();
    }
    return packageDeclaration;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) JXPathException(org.apache.commons.jxpath.JXPathException)

Example 8 with Element

use of org.jdom.Element in project freud by LMAX-Exchange.

the class JavaSourceJdom method parseType.

public static String parseType(final Element element) {
    final Element typeElement = element.getChild(JavaSourceTokenType.TYPE.getName());
    if (typeElement == null) {
        //void
        return JavaSourceTokenType.VOID.name().toLowerCase();
    }
    Element qualifiedType = typeElement.getChild(JavaSourceTokenType.QUALIFIED_TYPE_IDENT.getName());
    if (qualifiedType != null) {
        return qualifiedType.getChildText(JavaSourceTokenType.IDENT.getName());
    } else {
        //primitive type
        List<Element> children = typeElement.getChildren();
        return children.get(0).getText();
    }
}
Also used : Element(org.jdom.Element)

Example 9 with Element

use of org.jdom.Element in project freud by LMAX-Exchange.

the class JavaSourceJdom method parseAnnotations.

//////////////////////////////////////////////////////////////////////////////////////////////////
public static List<Annotation> parseAnnotations(final Element element) {
    final List<Annotation> annotations;
    JXPathContext context = JXPathContext.newContext(element);
    List annotationList = context.selectNodes("/" + JavaSourceTokenType.MODIFIER_LIST.getName() + "/" + JavaSourceTokenType.AT.getName());
    annotations = new ArrayList<Annotation>(annotationList.size());
    for (Object annotationElement : annotationList) {
        annotations.add(new AnnotationJdom((Element) annotationElement));
    }
    return annotations;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) Collections.emptyList(java.util.Collections.emptyList) ArrayList(java.util.ArrayList) List(java.util.List) Annotation(org.freud.analysed.javasource.Annotation)

Example 10 with Element

use of org.jdom.Element 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)

Aggregations

Element (org.jdom.Element)1236 NotNull (org.jetbrains.annotations.NotNull)103 Nullable (org.jetbrains.annotations.Nullable)98 IOException (java.io.IOException)81 ArrayList (java.util.ArrayList)76 List (java.util.List)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)67 Document (org.jdom.Document)67 File (java.io.File)64 JDOMException (org.jdom.JDOMException)53 PsiElement (com.intellij.psi.PsiElement)44 SAXBuilder (org.jdom.input.SAXBuilder)40 Attribute (org.jdom.Attribute)32 Iterator (java.util.Iterator)31 InvalidDataException (com.intellij.openapi.util.InvalidDataException)30 WriteExternalException (com.intellij.openapi.util.WriteExternalException)30 THashMap (gnu.trove.THashMap)30 XMLOutputter (org.jdom.output.XMLOutputter)27 JpsElement (org.jetbrains.jps.model.JpsElement)24 NonNls (org.jetbrains.annotations.NonNls)22