/*
(non-Javadoc)

@see
com.ibm.jaggr.service.modules.Resource#walkTree(com.ibm.jaggr.modules
.ResourceVisitor, boolean)
774476
@Override
	public void walkTree(IResourceVisitor visitor) throws IOException {
		if (!exists()) {
			throw new FileNotFoundException(file.getAbsolutePath());
		}
		if (!file.isDirectory()) {
			return;
		}
		recurse(file, visitor, ""); //$NON-NLS-1$
	}
1073616
function ( root ) {
    var walker = new TreeWalker( root, SHOW_TEXT, function () {
            return true;
        }, false ),
        parent, node, index;
    while ( node = walker.nextNode() ) {
        while ( ( index = node.data.indexOf( ZWS ) ) > -1 ) {
            if ( node.length === 1 ) {
                do {
                    parent = node.parentNode;
                    parent.removeChild( node );
                    node = parent;
                    walker.currentNode = parent;
                } while ( isInline( node ) && !getLength( node ) );
                break;
            } else {
                node.deleteData( index, 1 );
            }
        }
    }
}
466035
@Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            varName.visit(v);
            if (catchCondition != null) {
                catchCondition.visit(v);
            }
            body.visit(v);
        }
    }
409335
private void treeWalker(Node node, int level, List<PathQueryMatcher> queryMatchers, List<Node> collector) {
        MatchType matchType = queryMatchers.get(level).match(level, node);
        if(matchType == MatchType.NOT_A_MATCH) {
            // no reason to scan deeper
            //noinspection UnnecessaryReturnStatement
            return;
        } else if(matchType == MatchType.NODE_MATCH) {
            // we have a match
            if(level == queryMatchers.size()-1) {
                // full path match
                collector.add(node);
            } else if(node instanceof Element) {
                // scan deeper
                Element element = (Element) node;
                List<Node> childElements = element.getChildElements();
                for (Node childElement : childElements) {
                    treeWalker(childElement, level+1, queryMatchers, collector);
                }
            }
        } else {
            throw new PathQueryException("Unknown MatchType: " + matchType);
        }
    }
1352600
private ResourcePathNode<D> navigateFrom(ResourcePathNode<D> resourcePath) {

    if (isParentDirectory()) {
      ResourcePathNode<D> result = resourcePath;
      ResourcePathNode<D> segment = this;
      do {
        assert (segment.isParentDirectory());
        if (result.isParentDirectory()) {
          return new ResourcePathNode<>(result, segment.name, segment.data);
        } else {
          result = result.navigateUp();
        }
        segment = segment.parent;
      } while (segment.parent != null);
      return result;
    } else if (this.parent == null) {
      return resourcePath;
    } else {
      return new ResourcePathNode<>(this.parent.navigateFrom(resourcePath), this.name, this.data);
    }
  }
1297338
@Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            if (functionName != null) {
                functionName.visit(v);
            }
            for (AstNode param : getParams()) {
                param.visit(v);
            }
            getBody().visit(v);
            if (!isExpressionClosure) {
                if (memberExprNode != null) {
                    memberExprNode.visit(v);
                }
            }
        }
    }
1097387
private static VisitorResult doTraverse(final WComponent node, final boolean visibleOnly,
			final WComponentTreeVisitor visitor) {
		if (visibleOnly) {
			// Push through Invisible Containers
			// Certain components have their visibility altered to implement custom processing.
			if (node instanceof WInvisibleContainer) {
				WComponent parent = node.getParent();
				// If inside a CardManager, skip the InvisibleContainer and process the visible card.
				if (parent instanceof WCardManager) {
					WComponent visible = ((WCardManager) node.getParent()).getVisible();
					if (visible == null) {
						return VisitorResult.ABORT_BRANCH;
					}
					return doTraverse(visible, visibleOnly, visitor);
				} else if (parent instanceof WWindow) { // If inside a WWindow, only process if it is Active
					// Abort branch if WWindow is not in ACTIVE state
					if (((WWindow) parent).getState() != WWindow.ACTIVE_STATE) {
						return VisitorResult.ABORT_BRANCH;
					}
				}
			} else if (node instanceof WRepeatRoot) {
				// Let be processed.
			} else if (!node.isVisible()) {
				// For most components, we just need to see if they're marked as visible
				return VisitorResult.ABORT_BRANCH;
			}
		}

		VisitorResult result = visitor.visit(node);

		switch (result) {

			case ABORT_BRANCH:
				// Continue processing, but not down this branch
				return VisitorResult.CONTINUE;

			case CONTINUE:
				// Process repeater rows
				if (node instanceof WRepeater) {
					// Get parent repeater
					WRepeater repeater = (WRepeater) node;
					// Get row contexts
					List<UIContext> rowContextList = repeater.getRowContexts();
					WRepeatRoot repeatRoot = (WRepeatRoot) repeater.getRepeatedComponent().getParent();

					for (UIContext rowContext : rowContextList) {
						UIContextHolder.pushContext(rowContext);

						try {
							result = doTraverse(repeatRoot, visibleOnly, visitor);
						} finally {
							UIContextHolder.popContext();
						}

						if (VisitorResult.ABORT.equals(result)) {
							return VisitorResult.ABORT;
						}
					}
				} else if (node instanceof Container) {
					Container container = (Container) node;

					for (int i = 0; i < container.getChildCount(); i++) {
						result = doTraverse(container.getChildAt(i), visibleOnly, visitor);

						if (VisitorResult.ABORT.equals(result)) {
							return VisitorResult.ABORT;
						}
					}
				}

				return VisitorResult.CONTINUE;

			default:
				// Abort entire traversal
				return VisitorResult.ABORT;
		}
	}
1299641
@Override
    public R visitUses(UsesTree node, P p) {
        return defaultAction(node, p);
    }
1310987
@Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            for (XmlFragment frag : fragments) {
                frag.visit(v);
            }
        }
    }
657403
@Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            target.visit(v);
            for (AstNode arg : getArguments()) {
                arg.visit(v);
            }
            if (initializer != null) {
                initializer.visit(v);
            }
        }
    }
1316506
@Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            tryBlock.visit(v);
            for (CatchClause cc : getCatchClauses()) {
                cc.visit(v);
            }
            if (finallyBlock != null) {
                finallyBlock.visit(v);
            }
        }
    }
987885
public static void nodeWalker(NodeList childNodes, NodeElementParser parser) throws ParseException {
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node item = childNodes.item(i);
            String node = item.getNodeName();
            if(item.getNodeType() == Node.ELEMENT_NODE){
                parser.parse(item);
            }
            nodeWalker(item.getChildNodes(), parser);
        }
    }
547391
@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {

		component.removeAll();
		SiteNode node = null;
		if (value instanceof SiteNode) {
			node = (SiteNode) value;
		}
		
		if (node != null) {
	        if( node.isFiltered()) {
	        	// Hide the node
	            setPreferredSize( new Dimension(0, 0) );
	            return this;
	        }

			setPreferredSize(null);	// clears the preferred size, making the node visible
			super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

			// folder / file icons with scope 'target' if relevant
			if (node.isRoot()) {
				component.add(wrap(ROOT_ICON)); // 'World' icon
			} else {
				OverlayIcon icon;
		        if (node.isDataDriven()) {
					if (node.isIncludedInScope() && ! node.isExcludedFromScope()) {
						icon = new OverlayIcon(DATA_DRIVEN_IN_SCOPE_ICON);
					} else {
						icon = new OverlayIcon(DATA_DRIVEN_ICON);
					}
		        } else if (leaf) {
					if (node.isIncludedInScope() && ! node.isExcludedFromScope()) {
						icon = new OverlayIcon(LEAF_IN_SCOPE_ICON);
					} else {
						icon = new OverlayIcon(LEAF_ICON);
					}
				} else {
					if  (expanded) {
						if (node.isIncludedInScope() && ! node.isExcludedFromScope()) {
							icon = new OverlayIcon(FOLDER_OPEN_IN_SCOPE_ICON);
						} else {
							icon = new OverlayIcon(FOLDER_OPEN_ICON);
						}
					} else {
						if (node.isIncludedInScope() && ! node.isExcludedFromScope()) {
							icon = new OverlayIcon(FOLDER_CLOSED_IN_SCOPE_ICON);
						} else {
							icon = new OverlayIcon(FOLDER_CLOSED_ICON);
						}
					}
				}
				if (node.getParent().isRoot() && node.getNodeName().startsWith("https://")) {
					// Add lock icon to site nodes with https
					icon.add(LOCK_OVERLAY_ICON);
				}
				
				component.add(wrap(DisplayUtils.getScaledIcon(icon)));
				
				Alert alert = node.getHighestAlert();
				if (alert != null) {
					component.add(wrap(alert.getIcon()));
				}

				for (ImageIcon ci : node.getCustomIcons()){
					component.add(wrap(DisplayUtils.getScaledIcon(ci)));
				}
				
			}
			setText(node.toString());
			setIcon(null);
			component.add(this);

	        for (SiteMapListener listener : listeners) {
	        	listener.onReturnNodeRendererComponent(this, leaf, node);
	        }
	        return component;
		}

		return this;
	}
25183
@Override
	public void traverse(SchemaVisitor visitor) {
    	visitor.initialize(m_xsdpackageName, m_targetNamespace,m_classes);
    	for (Map.Entry<String,ObjectDescriptor> entry: m_elements.entrySet()) {
    		ObjectDescriptor objectDescriptor = entry.getValue();
    		// get the type and call the visitor for it.
    		objectDescriptor.traverse(visitor);
    	}
    	visitor.terminate();
    }
1060144
@Override
    void scanPaths(final LogNode log) {
        if (skipClasspathElement) {
            return;
        }
        if (scanned.getAndSet(true)) {
            // Should not happen
            throw new IllegalArgumentException("Already scanned classpath element " + toString());
        }

        final String moduleLocationStr = moduleRef.getLocationStr();
        final LogNode subLog = log == null ? null
                : log.log(moduleLocationStr, "Scanning module " + moduleRef.getName());

        try (RecycleOnClose<ModuleReaderProxy, IOException> moduleReaderProxyRecycleOnClose //
                = moduleReaderProxyRecycler.acquireRecycleOnClose()) {
            // Look for whitelisted files in the module.
            List<String> resourceRelativePaths;
            try {
                resourceRelativePaths = moduleReaderProxyRecycleOnClose.get().list();
            } catch (final SecurityException e) {
                if (subLog != null) {
                    subLog.log("Could not get resource list for module " + moduleRef.getName(), e);
                }
                return;
            }
            CollectionUtils.sortIfNotEmpty(resourceRelativePaths);

            String prevParentRelativePath = null;
            ScanSpecPathMatch prevParentMatchStatus = null;
            for (final String relativePath : resourceRelativePaths) {
                // From ModuleReader#find(): "If the module reader can determine that the name locates a
                // directory then the resulting URI will end with a slash ('/')."  But from the documentation
                // for ModuleReader#list(): "Whether the stream of elements includes names corresponding to
                // directories in the module is module reader specific."  We don't have a way of checking if
                // a resource is a directory without trying to open it, unless ModuleReader#list() also decides
                // to put a "/" on the end of resource paths corresponding to directories. Skip directories if
                // they are found, but if they are not able to be skipped, we will have to settle for having
                // some IOExceptions thrown when directories are mistaken for resource files.
                if (relativePath.endsWith("/")) {
                    continue;
                }

                // Whitelist/blacklist classpath elements based on file resource paths
                checkResourcePathWhiteBlackList(relativePath, log);
                if (skipClasspathElement) {
                    return;
                }

                // Get match status of the parent directory of this resource's relative path (or reuse the last
                // match status for speed, if the directory name hasn't changed).
                final int lastSlashIdx = relativePath.lastIndexOf('/');
                final String parentRelativePath = lastSlashIdx < 0 ? "/"
                        : relativePath.substring(0, lastSlashIdx + 1);
                final boolean parentRelativePathChanged = !parentRelativePath.equals(prevParentRelativePath);
                final ScanSpecPathMatch parentMatchStatus = //
                        prevParentRelativePath == null || parentRelativePathChanged
                                ? scanSpec.dirWhitelistMatchStatus(parentRelativePath)
                                : prevParentMatchStatus;
                prevParentRelativePath = parentRelativePath;
                prevParentMatchStatus = parentMatchStatus;

                if (parentMatchStatus == ScanSpecPathMatch.HAS_BLACKLISTED_PATH_PREFIX) {
                    // The parent dir or one of its ancestral dirs is blacklisted
                    if (subLog != null) {
                        subLog.log("Skipping blacklisted path: " + relativePath);
                    }
                    continue;
                }

                // Found non-blacklisted relative path
                if (allResourcePaths.add(relativePath)
                        // If resource is whitelisted
                        && (parentMatchStatus == ScanSpecPathMatch.HAS_WHITELISTED_PATH_PREFIX
                                || parentMatchStatus == ScanSpecPathMatch.AT_WHITELISTED_PATH
                                || (parentMatchStatus == ScanSpecPathMatch.AT_WHITELISTED_CLASS_PACKAGE
                                        && scanSpec.classfileIsSpecificallyWhitelisted(relativePath))
                                || (scanSpec.enableClassInfo && relativePath.equals("module-info.class")))) {
                    // Add whitelisted resource
                    final Resource resource = newResource(relativePath);
                    addWhitelistedResource(resource, parentMatchStatus, subLog);
                }
            }

            // Save last modified time for the module file
            final File moduleFile = moduleRef.getLocationFile();
            if (moduleFile != null && moduleFile.exists()) {
                fileToLastModified.put(moduleFile, moduleFile.lastModified());
            }

        } catch (final IOException e) {
            if (subLog != null) {
                subLog.log("Exception opening module " + moduleRef.getName(), e);
            }
            skipClasspathElement = true;
        }

        finishScanPaths(subLog);
    }
657754
@Override
  public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
    classInfo.checkTypeQueryAnnotation(desc);
    return super.visitAnnotation(desc, visible);
  }
141588
@Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            for (AstNode label : labels) {
                label.visit(v);
            }
            statement.visit(v);
        }
    }