@Override public Map<String, ResultType> parseStatements( List<String> statements, Collection<String> importedClasses, @Nullable ClassLoaderContext classLoaderContext ) throws ParseException { StringBuilder codeBuilder = new StringBuilder( "class X {" ); codeBuilder.append( "void run() {" ); for (String statement : statements) { codeBuilder.append( statement ); } codeBuilder.append( "} }" ); List<Statement> parsedStatements; try { CompilationUnit compilationUnit = JavaParser.parse( new StringReader( codeBuilder.toString() ), false ); MethodDeclaration methodDeclaration = ( MethodDeclaration ) compilationUnit .getTypes().get( 0 ) .getMembers().get( 0 ); parsedStatements = methodDeclaration.getBody().getStmts(); } catch ( com.github.javaparser.ParseException e ) { throw new ParseException( e.getMessage(), 0 ); } return resultTypes( new TypeDiscoverer( importedClasses, classLoaderContext ) .getTypesByVariableName( parsedStatements ) ); }
public static BlockStmt mergeBlock(BlockStmt one, BlockStmt two) { if (isAllNull(one, two)) return null; BlockStmt blockStmt = null; if (isAllNotNull(one, two)) { blockStmt = new BlockStmt(); blockStmt.setComment(mergeSelective(one.getComment(), two.getComment())); blockStmt.setStmts(mergeListInOrder(one.getStmts(), two.getStmts())); } else { blockStmt = findFirstNotNull(one, two); } return blockStmt; }
@Override public ResultType visit( MethodDeclaration declaration, MethodDeclaration arg ) { List<Statement> statements = declaration.getBody().getStmts();
continue; for (Statement stmt : method.getBody().getStmts()) { if (!(stmt instanceof ReturnStmt)) { continue;
continue; for (Statement stmt : method.getBody().getStmts()) { if (!(stmt instanceof ReturnStmt)) { continue;