01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.xslt.mapper.model;
20:
21: import java.util.HashSet;
22: import java.util.Set;
23: import org.netbeans.modules.xslt.mapper.model.nodes.LiteralCanvasNode;
24: import org.netbeans.modules.xslt.mapper.model.nodes.OperationOrFunctionCanvasNode;
25: import org.netbeans.modules.xslt.mapper.model.nodes.visitor.AbstractNodeVisitor;
26: import org.netbeans.modules.xslt.mapper.model.targettree.AttributeDeclarationNode;
27: import org.netbeans.modules.xslt.mapper.model.targettree.ElementDeclarationNode;
28: import org.netbeans.modules.xslt.mapper.model.targettree.PredicatedSchemaNode;
29: import org.netbeans.modules.xslt.mapper.model.targettree.RuleNode;
30: import org.netbeans.modules.xslt.mapper.model.targettree.SchemaNode;
31:
32: /**
33: * This visitor collects a list of the predicated tree nodes located under
34: * the source tree, which are used by XSLT.
35: * It is intended to delete unused predicates from the source tree.
36: *
37: * The visitor should be applied to the root element of the target tree!
38: *
39: * @author nk160297
40: */
41: public class FindUsedPredicateNodesVisitor extends AbstractNodeVisitor {
42:
43: private HashSet<PredicatedSchemaNode> myResultNodesList = new HashSet<PredicatedSchemaNode>();
44:
45: /**
46: * Returns the set of used predicated nodes.
47: */
48: public Set<PredicatedSchemaNode> getResultList() {
49: return myResultNodesList;
50: }
51:
52: public void visit(ElementDeclarationNode node) {
53: acceptUpstream(node);
54: //
55: acceptDownTree(node);
56: }
57:
58: public void visit(AttributeDeclarationNode node) {
59: acceptUpstream(node);
60: }
61:
62: public void visit(RuleNode node) {
63: acceptUpstream(node);
64: //
65: acceptDownTree(node);
66: }
67:
68: public void visit(OperationOrFunctionCanvasNode node) {
69: acceptUpstream(node);
70: }
71:
72: public void visit(LiteralCanvasNode node) {
73: // Nothing to do here.
74: }
75:
76: public void visit(SchemaNode node) {
77: if (node.isSourceViewNode()) {
78: if (node instanceof PredicatedSchemaNode) {
79: myResultNodesList.add((PredicatedSchemaNode) node);
80: }
81: acceptUpTree(node);
82: }
83: }
84:
85: }
|