本文整理匯總了Java中com.github.javaparser.ast.CompilationUnit.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java CompilationUnit.toString方法的具體用法?Java CompilationUnit.toString怎麽用?Java CompilationUnit.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.javaparser.ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mergeContent
import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
public static String mergeContent(CompilationUnit one, CompilationUnit two) throws Exception {
// 包聲明不同,返回null
if (!one.getPackage().equals(two.getPackage())) return null;
CompilationUnit cu = new CompilationUnit();
// add package declaration to the compilation unit
PackageDeclaration pd = new PackageDeclaration();
pd.setName(one.getPackage().getName());
cu.setPackage(pd);
// check and merge file comment;
Comment fileComment = mergeSelective(one.getComment(), two.getComment());
cu.setComment(fileComment);
// check and merge imports
List<ImportDeclaration> ids = mergeListNoDuplicate(one.getImports(), two.getImports());
cu.setImports(ids);
// check and merge Types
List<TypeDeclaration> types = mergeTypes(one.getTypes(), two.getTypes());
cu.setTypes(types);
return cu.toString();
}
示例2: merge
import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
/**
* Util method to make source merge more convenient
*
* @param first merge params, specifically for the existing source
* @param second merge params, specifically for the new source
* @return merged result
* @throws ParseException cannot parse the input params
*/
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();
}