use of com.github.javaparser.ParseProblemException in project vue-gwt by Axellience.
the class TemplateParser method processJavaExpression.
/**
* Process the given string as a Java expression.
* @param expressionString A valid Java expression
* @return A processed expression, should be placed in the HTML in place of the original
* expression
*/
private TemplateExpression processJavaExpression(String expressionString) {
Expression expression;
try {
expression = JavaParser.parseExpression(expressionString);
} catch (ParseProblemException parseException) {
logger.error("Couldn't parse Expression, make sure it is valid Java.", expressionString);
throw parseException;
}
resolveTypesUsingImports(expression);
resolveStaticMethodsUsingImports(expression);
checkMethodNames(expression);
// Find the parameters used by the expression
List<VariableInfo> expressionParameters = new LinkedList<>();
findExpressionParameters(expression, expressionParameters);
// If there is a cast first, we use this as the type of our expression
if (currentProp == null)
expression = getTypeFromCast(expression);
// Update the expression as it might have been changed
expressionString = expression.toString();
// Add the resulting expression to our result
return result.addExpression(expressionString, currentExpressionReturnType, currentProp == null, expressionParameters);
}
use of com.github.javaparser.ParseProblemException in project structr by structr.
the class ParseJavaFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
try {
if (!(arrayHasLengthAndAllElementsNotNull(sources, 1) && sources[0] instanceof String)) {
return null;
}
try {
final SecurityContext securityContext = ctx.getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
// Parse string as Java code
final String resultJson = new GsonBuilder().setPrettyPrinting().create().toJson(new JavaParserModule(app).parse((String) sources[0]).get());
return resultJson;
} catch (final ParseProblemException ex) {
logException(caller, ex, sources);
}
} catch (final IllegalArgumentException e) {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
return "";
}
use of com.github.javaparser.ParseProblemException in project structr by structr.
the class StructrJavaTypeSolver method parse.
private void parse(final Folder folder) {
for (final File file : folder.getFiles()) {
final String fileName = file.getName();
if (StringUtils.isNotEmpty(fileName) && fileName.endsWith(".java") && !(fileName.endsWith("ackage-info.java"))) {
final String fileContent = file.getFavoriteContent();
try {
final CompilationUnit cu = JavaParser.parse(fileContent);
index.add(cu);
cuCount++;
} catch (final ParseProblemException ex) {
logger.warn("Couldn't parse " + fileName, ex);
}
}
}
folder.getFolders().forEach((subfolder) -> {
parse(subfolder);
});
}
use of com.github.javaparser.ParseProblemException in project checker-framework by typetools.
the class ToIndexFileConverter method convert.
/**
* Augment given scene with information from stubfile, reading stubs from input stream and
* writing JAIF to output stream.
*
* @param scene the initial scene
* @param in stubfile contents
* @param out JAIF representing augmented scene
* @throws ParseException
* @throws DefException
*/
private static void convert(AScene scene, InputStream in, OutputStream out) throws IOException, DefException, ParseException {
StubUnit iu;
try {
iu = JavaParser.parseStubUnit(in);
} catch (ParseProblemException e) {
iu = null;
ErrorReporter.errorAbort("ToIndexFileConverter: exception from JavaParser.parseStubUnit for InputStream." + System.lineSeparator() + "Problem message with problems encountered: " + e.getMessage());
}
extractScene(iu, scene);
try (Writer w = new BufferedWriter(new OutputStreamWriter(out))) {
IndexFileWriter.write(scene, w);
}
}
use of com.github.javaparser.ParseProblemException in project javaparser by javaparser.
the class SourceRoot method parse.
/**
* Parses a .java files under the source root and returns its CompilationUnit. It keeps track of the parsed file so
* you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you don't
* need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you might
* want to use the parse method with a callback.
*
* @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
* @throws ParseProblemException when something went wrong.
*/
public CompilationUnit parse(String startPackage, String filename) {
assertNotNull(startPackage);
assertNotNull(filename);
try {
final ParseResult<CompilationUnit> result = tryToParse(startPackage, filename);
if (result.isSuccessful()) {
return result.getResult().get();
}
throw new ParseProblemException(result.getProblems());
} catch (IOException e) {
throw new ParseProblemException(e);
}
}
Aggregations