本文整理了Java中com.github.javaparser.ast.CompilationUnit.<init>()
方法的一些代码示例,展示了CompilationUnit.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.<init>()
方法的具体详情如下:
包路径:com.github.javaparser.ast.CompilationUnit
类名称:CompilationUnit
方法名:<init>
暂无
代码示例来源:origin: kawasima/enkan
@Override
public void execute(PathResolver pathResolver) throws Exception {
CompilationUnit cu = new CompilationUnit();
String basePackage = BasePackageDetector.detect();
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr(basePackage + "form")));
ClassOrInterfaceDeclaration formClass = new ClassOrInterfaceDeclaration(
ModifierSet.PUBLIC, false, CaseConverter.pascalCase(tableName) + "Form");
ASTHelper.addTypeDeclaration(cu, formClass);
formClass.setExtends(Collections.singletonList(
new ClassOrInterfaceType("FormBase")
));
fields.stream()
.filter(f -> !f.isId())
.forEach(f -> ASTHelper.addMember(formClass, fieldDeclaration(f)));
fields.stream()
.filter(f -> !f.isId())
.forEach(f -> ASTHelper.addMember(formClass, getterDeclaration(f)));
fields.stream()
.filter(f -> !f.isId())
.forEach(f -> ASTHelper.addMember(formClass, setterDeclaration(f)));
try (Writer writer = new OutputStreamWriter(pathResolver.destinationAsStream(destination))) {
writer.write(cu.toString());
}
}
代码示例来源:origin: kawasima/enkan
@Override
public void execute(PathResolver pathResolver) throws Exception {
CompilationUnit cu = new CompilationUnit();
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("db.migration")));
List<ImportDeclaration> imports = new ArrayList<>();
代码示例来源:origin: com.reprezen.jsonoverlay/jsonoverlay
public String format() {
CompilationUnit cu = new CompilationUnit();
if (fileComment != null) {
cu.addOrphanComment(new JavadocComment(fileComment));
}
cu.setPackageDeclaration(pkg);
for (String imp : imports) {
cu.addImport(imp);
}
cu.addType(type);
for (Member member : gatherFinalMembers(members, cu)) {
type.addMember(member.getDeclaration());
}
return cu.toString();
}
代码示例来源:origin: beihaifeiwu/dolphin
@Override
public CompilationUnit doMerge(CompilationUnit first, CompilationUnit second) {
CompilationUnit unit = new CompilationUnit();
unit.setPackage(mergeSingle(first.getPackage(), second.getPackage()));
unit.setImports(mergeCollections(first.getImports(), second.getImports()));
unit.setTypes(mergeCollections(first.getTypes(), second.getTypes()));
return unit;
}
代码示例来源:origin: ftomassetti/analyze-java-code-examples
public static void main(String[] args) {
CompilationUnit compilationUnit = new CompilationUnit();
compilationUnit.setPackageDeclaration("my.example.javaparser");
代码示例来源:origin: beihaifeiwu/dolphin
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();
}
内容来源于网络,如有侵权,请联系作者删除!