当前位置: 首页>>代码示例>>Java>>正文


Java Node.accept方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:24,代码来源:DumpVisitor.java

示例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);
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:30,代码来源:SrcRemapper.java

示例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();
    }
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:28,代码来源:JavaTreeListener.java

示例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);
    }
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:36,代码来源:ASTDumpVisitor.java

示例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;

        }
 
开发者ID:Nosorog,项目名称:nosorog-core,代码行数:22,代码来源:Script.java

示例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);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:11,代码来源:JavaParserFacade.java

示例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);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:11,代码来源:JavaParserFacade.java


注:本文中的com.github.javaparser.ast.Node.accept方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。