Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade javaparser-core to 3.23.0 #1106

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions DB/src/main/java/com/github/javaparser/ExpressionParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.javaparser;

import com.github.javaparser.ast.expr.Expression;

import java.io.IOException;
import java.io.StringReader;

/**
* Helpful class which parses expressions and performs extra "this is exactly one expression" validation
*/
public class ExpressionParser {
public static Expression parseExpression(String expression) {
StringReader sr = new StringReader(expression);
ParseResult<Expression> result = new JavaParser().parse(ParseStart.EXPRESSION, Providers.provider(sr));
if (!result.isSuccessful()) {
throw new IllegalArgumentException(
"Invalid expression " + expression + ": " + result.getProblems().toString());
}

Expression expr = result.getResult().orElse(null);

// let's be certain the string reader was drained; or else we might not have parsed what we thought we did
try {
int test;
while ((test = sr.read()) != -1) {
if (!Character.isWhitespace(test)) {
throw new IllegalArgumentException(
"Invalid expression " + expression + " was already terminated after " + expr);
}
}
sr.close();
} catch (IOException ignored) {
}
return expr;
}
}

Large diffs are not rendered by default.

Loading