本文整理汇总了Java中com.github.javaparser.ast.CompilationUnit.getChildrenNodes方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.getChildrenNodes方法的具体用法?Java CompilationUnit.getChildrenNodes怎么用?Java CompilationUnit.getChildrenNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.getChildrenNodes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertCommentsInCu
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
* Comments are attributed to the thing the comment and are removed from
* allComments.
*/
private static void insertCommentsInCu(CompilationUnit cu, CommentsCollection commentsCollection){
if (commentsCollection.size()==0) return;
// I should sort all the direct children and the comments, if a comment is the first thing then it
// a comment to the CompilationUnit
// FIXME if there is no package it could be also a comment to the following class...
// so I could use some heuristics in these cases to distinguish the two cases
List<Comment> comments = commentsCollection.getAll();
PositionUtils.sortByBeginPosition(comments);
List<Node> children = cu.getChildrenNodes();
PositionUtils.sortByBeginPosition(children);
if (cu.getPackage()!=null && (children.isEmpty() || PositionUtils.areInOrder(comments.get(0), children.get(0)))){
cu.setComment(comments.get(0));
comments.remove(0);
}
insertCommentsInNode(cu,comments);
}
示例2: insertComments
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
* Comments are attributed to the thing they comment and are removed from
* the comments.
*/
private void insertComments(CompilationUnit cu, TreeSet<Comment> comments) {
if (comments.isEmpty())
return;
/* I should sort all the direct children and the comments, if a comment
is the first thing then it
a comment to the CompilationUnit */
// FIXME if there is no package it could be also a comment to the following class...
// so I could use some heuristics in these cases to distinguish the two
// cases
List<Node> children = cu.getChildrenNodes();
PositionUtils.sortByBeginPosition(children);
Comment firstComment = comments.iterator().next();
if (cu.getPackage() != null
&& (children.isEmpty() || PositionUtils.areInOrder(
firstComment, children.get(0)))) {
cu.setComment(firstComment);
comments.remove(firstComment);
}
}
示例3: insertCommentsInCu
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
* Comments are attributed to the thing the comment and are removed from
* allComments.
*/
private static void insertCommentsInCu(CompilationUnit cu, CommentsCollection commentsCollection){
if (commentsCollection.size()==0) return;
// I should sort all the direct children and the comments, if a comment is the first thing then it
// a comment to the CompilationUnit
// FIXME if there is no package it could be also a comment to the following class...
// so I could use some heuristics in these cases to distinguish the two cases
List<Comment> comments = commentsCollection.getAll();
PositionUtils.sortByBeginPosition(comments);
List<Node> children = cu.getChildrenNodes();
PositionUtils.sortByBeginPosition(children);
if (cu.getPackage()!=null && (children.size()==0 || PositionUtils.areInOrder(comments.get(0), children.get(0)))){
cu.setComment(comments.get(0));
comments.remove(0);
}
insertCommentsInNode(cu,comments);
}
示例4: main
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
public static void main(String[] args) throws ParseException, IOException {
String fileName = "C:\\Users\\KYJ\\JAVA_FX\\gagoyleWorkspace\\VisualFxVoEditor\\src\\main\\java\\com\\kyj\\fx\\voeditor\\visual\\main\\model\\vo\\ClassPathEntry.java";
FileInputStream in = new FileInputStream(fileName);
CompilationUnit cu;
try {
// parse the file
cu = JavaParser.parse(in);
} finally {
in.close();
}
PackageDeclaration packageDeclaration = cu.getPackage();
// System.out.println(packageDeclaration.getName().toString());
// System.out.println();
// System.out.println(String.format("package name : %s",
// packageDeclaration.getName().getName()));
ClassMeta classMeta = new ClassMeta("");
classMeta.setPackageName(packageDeclaration.getName().toString());
ArrayList<FieldMeta> fields = new ArrayList<FieldMeta>();
VoEditor voEditor = new VoEditor(classMeta, fields);
List<Node> childrenNodes = cu.getChildrenNodes();
for (Node n : childrenNodes) {
}
new MethodVisitor().visit(cu, null);
}
示例5: getBody
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
public static BodyDeclaration getBody(CompilationUnit cu) {
List<Node> nodes = cu.getChildrenNodes();
for (Node node : nodes) {
if (node instanceof BodyDeclaration) {
return (BodyDeclaration) node;
}
}
return null;
}