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;
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations