本文整理汇总了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);
}
}
示例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;
}
示例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('.', '/'));
}
示例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: 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;
}
示例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);
}