Java Javascript Mozilla Library parentOfAnyTypes(AstNode node, Set types, boolean isStrict)

Here you can find the source of parentOfAnyTypes(AstNode node, Set types, boolean isStrict)

Description

return nearest parent node whose type is one of specified ones.

License

Open Source License

Parameter

Parameter Description
isStrict if true, raise exception when no element is found. Otherwise just return null.

Declaration

public static AstNode parentOfAnyTypes(AstNode node, Set<Class> types, boolean isStrict) 

Method Source Code


//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;
    }
}

Related

  1. numberArg(Object[] args, int pos)
  2. objArg(Object[] args, int pos, Class type, boolean required)
  3. objectToXMLString(Object xml)
  4. omitLineBreak(AstNode node)
  5. oneLineStringOf(AstNode node)
  6. parentOfType(AstNode node, Class type)
  7. prototypeCast(Scriptable s, Class type)
  8. removeLinkFromXhtml(Object xhtml, String link)
  9. runWithAllOptimizationLevels(final ContextAction action)