use of com.github.javaparser.ParserConfiguration in project drools by kiegroup.
the class DroolsMvelParserTest method testLineBreakAtTheEndOfStatementWithoutSemicolon.
@Test
public void testLineBreakAtTheEndOfStatementWithoutSemicolon() {
String expr = "{ Person p2 = new Person(\"John\");\n" + // a line break at the end of the statement without a semicolon
" p2.age = 30\n" + "insert(p2);\n }";
MvelParser mvelParser = new MvelParser(new ParserConfiguration(), true);
ParseResult<BlockStmt> r = mvelParser.parse(GeneratedMvelParser::BlockParseStart, new StringProvider(expr));
BlockStmt blockStmt = r.getResult().get();
assertEquals("Should parse 3 statements", 3, blockStmt.getStatements().size());
}
use of com.github.javaparser.ParserConfiguration in project checker-framework by typetools.
the class JavaParserUtil method parseExpression.
/**
* Parses the {@code expression} and returns an {@code Expression} that represents it.
*
* <p>This is like {@code StaticJavaParser.parseExpression}, but it does not lead to memory leaks
* because it creates a new instance of JavaParser each time it is invoked. Re-using {@code
* StaticJavaParser} causes memory problems because it retains too much memory.
*
* @param expression the expression string
* @param languageLevel the language level to use when parsing the Java source
* @return the parsed expression
* @throws ParseProblemException if the expression has parser errors
*/
public static Expression parseExpression(String expression, LanguageLevel languageLevel) {
// The ParserConfiguration accumulates data each time parse is called, so create a new one each
// time. There's no method to set the ParserConfiguration used by a JavaParser, so a JavaParser
// has to be created each time.
ParserConfiguration configuration = new ParserConfiguration();
configuration.setLanguageLevel(languageLevel);
configuration.setStoreTokens(false);
configuration.setLexicalPreservationEnabled(false);
configuration.setAttributeComments(false);
configuration.setDetectOriginalLineSeparator(false);
JavaParser javaParser = new JavaParser(configuration);
ParseResult<Expression> parseResult = javaParser.parseExpression(expression);
if (parseResult.isSuccessful() && parseResult.getResult().isPresent()) {
return parseResult.getResult().get();
} else {
throw new ParseProblemException(parseResult.getProblems());
}
}
use of com.github.javaparser.ParserConfiguration in project flow by vaadin.
the class OpenAPIObjectGenerator method createParserConfiguration.
private ParserConfiguration createParserConfiguration() {
typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false));
if (typeResolverClassLoader != null) {
typeSolver.add(new ClassLoaderTypeSolver(typeResolverClassLoader));
}
JavaSymbolSolver symbolResolver = new JavaSymbolSolver(typeSolver);
return new ParserConfiguration().setSymbolResolver(symbolResolver);
}
use of com.github.javaparser.ParserConfiguration in project flow by vaadin.
the class OpenAPIObjectGenerator method init.
private void init() {
if (javaSourcePaths == null || configuration == null) {
throw new IllegalStateException("Java source path and configuration should not be null");
}
openApiModel = createBasicModel();
nonEndpointMap = new HashMap<>();
endpointExposedMap = new HashMap<>();
qualifiedNameToPath = new HashMap<>();
pathItems = new TreeMap<>();
usedTypes = new HashMap<>();
generatedSchema = new HashSet<>();
endpointsJavadoc = new HashMap<>();
schemaGenerator = new SchemaGenerator(this);
needsDeferrableImport = false;
ParserConfiguration parserConfiguration = createParserConfiguration();
javaSourcePaths.stream().map(path -> new SourceRoot(path, parserConfiguration)).forEach(sourceRoot -> parseSourceRoot(sourceRoot, this::findEndpointExposed));
javaSourcePaths.stream().map(path -> new SourceRoot(path, parserConfiguration)).forEach(sourceRoot -> parseSourceRoot(sourceRoot, this::process));
for (Map.Entry<String, GeneratorType> entry : new ArrayList<>(usedTypes.entrySet())) {
List<Schema> schemas = createSchemasFromQualifiedNameAndType(entry.getKey(), entry.getValue());
schemas.forEach(schema -> {
if (qualifiedNameToPath.get(schema.getName()) != null) {
schema.addExtension(EXTENSION_VAADIN_FILE_PATH, qualifiedNameToPath.get(schema.getName()));
}
openApiModel.getComponents().addSchemas(schema.getName(), schema);
});
}
addTagsInformation();
}
Aggregations