public static String merge ( String first , String second ) throws ParseException { JavaParser . setDoNotAssignCommentsPreceedingEmptyLines ( false ) ; CompilationUnit cu1 = JavaParser . parse ( new StringReader ( first ) , true ) ; CompilationUnit cu2 = JavaParser . parse ( new StringReader ( second ) , true ) ; AbstractMerger < CompilationUnit > merger = AbstractMerger . getMerger ( CompilationUnit . class ) ; CompilationUnit result = merger . merge ( cu1 , cu2 ) ; return result . toString ( ) ; }
Util method to make source merge more convenient