Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EBrader committed Apr 22, 2024
1 parent cc810ed commit 47ff7fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* Converts an APath to an XPath-query
*
* <p>
* Created by pieter.bos on 11/05/16.
*/
public class APathToXPathConverter {
Expand All @@ -29,11 +29,11 @@ public class APathToXPathConverter {

public static String convertQueryToXPath(String query, String firstNodeName) {
String convertedQuery = convertWithAntlr(query);
if(convertedQuery.equals("/")) {
if (convertedQuery.equals("/")) {
return "/" + firstNodeName;
} else if(query.startsWith("//")) {
} else if (query.startsWith("//")) {
return convertedQuery;
} else if(query.startsWith("/")) {
} else if (query.startsWith("/")) {
return "/" + firstNodeName + convertedQuery;
} else {
return convertedQuery;
Expand All @@ -52,57 +52,14 @@ public static String convertWithAntlr(String query) {

}

// public static void handleOrExpression(StringBuilder output, OrExprContext orExprContext) {
// boolean firstAndExpr= true;
// for(AndExprContext andExprContext:orExprContext.andExpr()) {
// if(!firstAndExpr) {
// output.append(" or ");
// }
// handleAndExpression(output, andExprContext);
// firstAndExpr = false;
// }
// }
//
// public static void handleAndExpression(StringBuilder output, AndExprContext andExprContext) {
// boolean firstEqualityExpr = true;
// for(EqualityExprContext equalityExprContext:andExprContext.equalityExpr()) {
// if(!firstEqualityExpr) {
// output.append(" and ");
// }
// handleEqualityExpression(output, equalityExprContext);
// firstEqualityExpr = false;
// }
// }
//
// private static void handleEqualityExpression(StringBuilder output, EqualityExprContext equalityExprContext) {
// for(int i = 0; i < equalityExprContext.getChildCount(); i++) {
// ParseTree child = equalityExprContext.getChild(i);
// if(child instanceof RelationalExprContext) {
// handleRelationalExpression(output, (RelationalExprContext) child);
// } else {
// output.append(child.getText());
// }
// }
// }
//
// private static void handleRelationalExpression(StringBuilder output, RelationalExprContext relationalExpContext) {
// for(int i = 0; i < relationalExpContext.getChildCount(); i++) {
// ParseTree child = relationalExpContext.getChild(i);
// if(child instanceof AdditiveExprContext) {
// //handleAdditiveExprContext(output, (AdditiveExprContext) child);
// } else {
// output.append(child.getText());
// }
// }
// }

/**
* Converts and ANTLR ParseTree of the XPath grammar to APath String output
* Adds the output to the given StringBuilder.
*
* <p>
* Simple approach that writes every element, adding some whitespace where needed, and converting just a few elements
* @param output the output to write to
* @param tree the parse tree
*
* @param output the output to write to
* @param tree the parse tree
* @param inPredicate whether we are inside or outside a predicate
*/
private static void writeTree(StringBuilder output, ParseTree tree, boolean inPredicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class APathToXPathConverterTest {

@Test
public void rootPath() throws Exception {
public void rootPath() {
assertConvertedQuery("/composition", "/");
assertConvertedQuery("//", "//");
}
Expand Down

0 comments on commit 47ff7fb

Please sign in to comment.