本文整理汇总了Java中com.github.javaparser.ast.Node.accept方法的典型用法代码示例。如果您正苦于以下问题:Java Node.accept方法的具体用法?Java Node.accept怎么用?Java Node.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.Node
的用法示例。
在下文中一共展示了Node.accept方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printOrphanCommentsBeforeThisChildNode
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
private void printOrphanCommentsBeforeThisChildNode(final Node node){
if (node instanceof Comment) return;
Node parent = node.getParentNode();
if (parent==null) return;
List<Node> everything = new LinkedList<Node>();
everything.addAll(parent.getChildrenNodes());
sortByBeginPosition(everything);
int positionOfTheChild = -1;
for (int i=0;i<everything.size();i++){
if (everything.get(i)==node) positionOfTheChild=i;
}
if (positionOfTheChild==-1) throw new RuntimeException("My index not found!!! "+node);
int positionOfPreviousChild = -1;
for (int i=positionOfTheChild-1;i>=0 && positionOfPreviousChild==-1;i--){
if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i;
}
for (int i=positionOfPreviousChild+1;i<positionOfTheChild;i++){
Node nodeToPrint = everything.get(i);
if (!(nodeToPrint instanceof Comment)) throw new RuntimeException("Expected comment, instead "+nodeToPrint.getClass()+". Position of previous child: "+positionOfPreviousChild+", position of child "+positionOfTheChild);
nodeToPrint.accept(this,null);
}
}
示例2: printOrphanCommentsBeforeThisChildNode
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
private void printOrphanCommentsBeforeThisChildNode(final Node node) {
if (configuration.isIgnoreComments()) return;
if (node instanceof Comment) return;
Node parent = node.getParentNode().orElse(null);
if (parent == null) return;
List<Node> everything = new LinkedList<>();
everything.addAll(parent.getChildNodes());
sortByBeginPosition(everything);
int positionOfTheChild = -1;
for (int i = 0; i < everything.size(); i++) {
if (everything.get(i) == node) positionOfTheChild = i;
}
if (positionOfTheChild == -1) {
throw new AssertionError("I am not a child of my parent.");
}
int positionOfPreviousChild = -1;
for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) {
if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i;
}
for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) {
Node nodeToPrint = everything.get(i);
if (!(nodeToPrint instanceof Comment))
throw new RuntimeException(
"Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: "
+ positionOfPreviousChild + ", position of child " + positionOfTheChild);
nodeToPrint.accept(this, null);
}
}
示例3: visit
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
@Override
public final void visit(EnumDeclaration ctx, Object arg) {
if (!componentStackContainsMethod()) {
final Component enumCmp = createComponent(ctx, OOPSourceModelConstants.ComponentType.ENUM);
enumCmp.setComponentName(generateComponentName(ctx.getNameAsString()));
enumCmp.setImports(currentImports);
enumCmp.setName(ctx.getNameAsString());
enumCmp.setAccessModifiers(resolveJavaParserModifiers(ctx.getModifiers()));
pointParentsToGivenChild(enumCmp);
if (ctx.getComment().isPresent()) {
enumCmp.setComment(ctx.getComment().get().toString());
}
for (final AnnotationExpr annot : ctx.getAnnotations()) {
populateAnnotation(enumCmp, annot);
}
componentStack.push(enumCmp);
for (final Node node : ctx.getChildNodes()) {
if (node instanceof FieldDeclaration || node instanceof MethodDeclaration
|| node instanceof ConstructorDeclaration || node instanceof ClassOrInterfaceDeclaration
|| node instanceof EnumDeclaration || node instanceof EnumConstantDeclaration) {
node.accept(this, arg);
}
}
completeComponent();
}
}
示例4: printOrphanCommentsBeforeThisChildNode
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
public void printOrphanCommentsBeforeThisChildNode(final Node node) {
if (node instanceof Comment) {
return;
}
Node parent = node.getParentNode();
if (parent == null) {
return;
}
List<Node> everything = new LinkedList<Node>();
everything.addAll(parent.getChildrenNodes());
sortByBeginPosition(everything);
int positionOfTheChild = -1;
for (int i = 0; i < everything.size(); i++) {
if (everything.get(i) == node) {
positionOfTheChild = i;
}
}
if (positionOfTheChild == -1) {
throw new RuntimeException("My index not found!!! " + node);
}
int positionOfPreviousChild = -1;
for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) {
if (!(everything.get(i) instanceof Comment)) {
positionOfPreviousChild = i;
}
}
for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) {
Node nodeToPrint = everything.get(i);
if (!(nodeToPrint instanceof Comment)) {
throw new RuntimeException("Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: " + positionOfPreviousChild + ", position of child " + positionOfTheChild);
}
nodeToPrint.accept(this, null);
}
}
示例5: build
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
Script build() throws ScriptException {
for (Node node : nodes) {
node.accept(visitor, null);
}
try {
StubBuilder stubBuilder = new StubBuilder(classLoader);
Importer importer = new Importer(importNodes, classLoader);
prelude = importer.getPrelude();
bindings = Binder.getBindings(stubBuilder.build());
} catch (IOException | CannotCompileException | InstantiationException | IllegalAccessException e) {
throw new ScriptException(e);
}
return Script.this;
}
示例6: getTypeConcrete
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
/**
* Should return more like a TypeApplication: a TypeDeclaration and possible typeParametersValues or array
* modifiers.
*
* @return
*/
private Type getTypeConcrete(Node node, boolean solveLambdas) {
if (node == null) throw new IllegalArgumentException();
return node.accept(typeExtractor, solveLambdas);
}
示例7: getTypeConcrete
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
/**
* Should return more like a TypeApplication: a TypeDeclaration and possible typeParametersValues or array
* modifiers.
*
* @return
*/
private ResolvedType getTypeConcrete(Node node, boolean solveLambdas) {
if (node == null) throw new IllegalArgumentException();
return node.accept(typeExtractor, solveLambdas);
}