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


Java Node.getParentNode方法代码示例

本文整理汇总了Java中com.github.javaparser.ast.Node.getParentNode方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getParentNode方法的具体用法?Java Node.getParentNode怎么用?Java Node.getParentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.javaparser.ast.Node的用法示例。


在下文中一共展示了Node.getParentNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: isIntrospectionRelevantNode

import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
private boolean isIntrospectionRelevantNode(Node node) {
    if (node instanceof Type && node.getParentNode() instanceof MethodDeclaration) {
        return false;
    }

    if (node instanceof Parameter && node.getParentNode() instanceof MethodDeclaration) {
        return false;
    }

    if (!(node instanceof AnnotationExpr) && node.getParentNode() instanceof BaseParameter) {
        return false;
    }

    if (node instanceof NameExpr && node.getParentNode() instanceof AnnotationExpr) {
        return false;
    }

    if (node.getParentNode() instanceof FieldAccessExpr) {
        return false;
    }

    return true;
}
 
开发者ID:hubrick,项目名称:raml-maven-plugin,代码行数:24,代码来源:SpringWebValidatorMojo.java

示例3: findLocalCls

import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
private static ClassInstance findLocalCls(Node n, IClassEnv env) {
	Optional<Node> parent = n.getParentNode();

	while (parent.isPresent() && !(parent.get() instanceof ClassOrInterfaceDeclaration)) {
		parent = parent.get().getParentNode();
	}

	if (!parent.isPresent()) return null;

	return env.getLocalClsByName(((ClassOrInterfaceDeclaration) parent.get()).getName().getIdentifier().replace('.', '/'));
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:12,代码来源:SrcRemapper.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: apply

import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
public String apply(Node node) {
    if (node instanceof NamedNode) {
        String name = ((NamedNode)node).getName();
        Node current = node;
        while (!(current instanceof CompilationUnit)) {
            current = current.getParentNode();
        }

        CompilationUnit compilationUnit = (CompilationUnit) current;

        for (ImportDeclaration importDecl : compilationUnit.getImports()) {
            NameExpr importExpr = importDecl.getName();
            if (importExpr instanceof QualifiedNameExpr) {
                QualifiedNameExpr qualifiedNameExpr = (QualifiedNameExpr) importExpr;
                String className = qualifiedNameExpr.getName();
                if (name.equals(className)) {
                    return qualifiedNameExpr.getQualifier().toString();
                }
            } else if (importDecl.getName().getName().endsWith(SEPARATOR + name)) {
                String importName = importDecl.getName().getName();
                return  importName.substring(0, importName.length() - name.length() -1);
            }
        }

       try {
           Class.forName(JAVA_LANG + "." + name);
           return JAVA_LANG;
       } catch (ClassNotFoundException ex) {
           return compilationUnit.getPackage().getPackageName();
       }
    }
    return null;
}
 
开发者ID:sundrio,项目名称:sundrio,代码行数:34,代码来源:Sources.java

示例6: isInTheCorrectClass

import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
private boolean isInTheCorrectClass(MethodDeclaration methodDeclaration) {
	Node n = methodDeclaration;
	
	String containingClassName = "";
	while (n != null) {
		if (n instanceof ClassOrInterfaceDeclaration) {
			ClassOrInterfaceDeclaration c = (ClassOrInterfaceDeclaration) n;
			containingClassName = c.getName() + "$" + containingClassName;
		}
		n = n.getParentNode();
	}
	
	containingClassName = containingClassName.substring(0, containingClassName.length() - 1);
	return containingClassName.equals(className);
}
 
开发者ID:dodie,项目名称:scott,代码行数:16,代码来源:MethodBoundaryExtractor.java


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