Here you can find the source of parentOfAnyTypes(AstNode node, Set
Parameter | Description |
---|---|
isStrict | if true, raise exception when no element is found. Otherwise just return null. |
public static AstNode parentOfAnyTypes(AstNode node, Set<Class> types, boolean isStrict)
//package com.java2s; //License from project: Open Source License import org.mozilla.javascript.ast.AstNode; import java.util.Set; public class Main { /**/*from w ww.j a va 2s .c o m*/ * return nearest parent node whose type is one of specified ones. * @param isStrict if true, raise exception when no element is found. Otherwise just return null. */ public static AstNode parentOfAnyTypes(AstNode node, Set<Class> types, boolean isStrict) { AstNode originalCopy = node; while (node != null) { for (Class type : types) { if (type.isInstance(node)) { return node; } } node = node.getParent(); } if (isStrict) { throw new IllegalArgumentException("Cannot find parent of type " + types + " from " + originalCopy.toSource() + "(" + originalCopy.getClass().getSimpleName() + ")"); } return null; } }