Java Doc for TreeWizard.java in  » Parser » antlr-3.0.1 » org » antlr » runtime » tree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » antlr 3.0.1 » org.antlr.runtime.tree 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.antlr.runtime.tree.TreeWizard

TreeWizard
public class TreeWizard (Code)
Build and navigate trees with this object. Must know about the names of tokens so you have to pass in a map or array of token names (from which this class can build the map). I.e., Token DECL means nothing unless the class can translate it to a token type. In order to create nodes and navigate, this class needs a TreeAdaptor. This class can build a token type -> node index for repeated use or for iterating over the various nodes with a particular type. This class works in conjunction with the TreeAdaptor rather than moving all this functionality into the adaptor. An adaptor helps build and navigate trees using methods. This class helps you do it with string patterns like "(A B C)". You can create a tree from that pattern or match subtrees against it.

Inner Class :public interface ContextVisitor
Inner Class :abstract public static class Visitor implements ContextVisitor
Inner Class :public static class TreePattern extends CommonTree
Inner Class :public static class WildcardTreePattern extends TreePattern
Inner Class :public static class TreePatternTreeAdaptor extends CommonTreeAdaptor

Field Summary
protected  TreeAdaptoradaptor
    
protected  MaptokenNameToTypeMap
    

Constructor Summary
public  TreeWizard(TreeAdaptor adaptor)
    
public  TreeWizard(TreeAdaptor adaptor, Map tokenNameToTypeMap)
    
public  TreeWizard(TreeAdaptor adaptor, String[] tokenNames)
    
public  TreeWizard(String[] tokenNames)
    

Method Summary
protected static  boolean_equals(Object t1, Object t2, TreeAdaptor adaptor)
    
protected  void_index(Object t, Map m)
    
protected  boolean_parse(Object t1, TreePattern t2, Map labels)
     Do the work for parse.
protected  void_visit(Object t, Object parent, int childIndex, int ttype, ContextVisitor visitor)
    
public  MapcomputeTokenTypes(String[] tokenNames)
     Compute a Map that is an inverted index of tokenNames (which maps int token types to names).
public  Objectcreate(String pattern)
     Create a tree or node from the indicated tree pattern that closely follows ANTLR tree grammar tree element syntax: (root child1 ...
public static  booleanequals(Object t1, Object t2, TreeAdaptor adaptor)
     Compare t1 and t2; return true if token types/text, structure match exactly. The trees are examined in their entirety so that (A B) does not match (A B C) nor (A (B C)).
public  booleanequals(Object t1, Object t2)
     Compare type, structure, and text of two trees, assuming adaptor in this instance of a TreeWizard.
public  Listfind(Object t, int ttype)
    
public  Listfind(Object t, String pattern)
     Return a List of subtrees matching pattern.
public  ObjectfindFirst(Object t, int ttype)
    
public  ObjectfindFirst(Object t, String pattern)
    
public  intgetTokenType(String tokenName)
     Using the map of token names to token types, return the type.
public  Mapindex(Object t)
     Walk the entire tree and make a node name to nodes mapping. For now, use recursion but later nonrecursive version may be more efficient.
public  booleanparse(Object t, String pattern, Map labels)
     Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels on the various nodes and '.' (dot) as the node/subtree wildcard, return true if the pattern matches and fill the labels Map with the labels pointing at the appropriate nodes.
public  booleanparse(Object t, String pattern)
    
public  voidvisit(Object t, int ttype, ContextVisitor visitor)
     Visit every ttype node in t, invoking the visitor.
public  voidvisit(Object t, String pattern, ContextVisitor visitor)
     For all subtrees that match the pattern, execute the visit action.

Field Detail
adaptor
protected TreeAdaptor adaptor(Code)



tokenNameToTypeMap
protected Map tokenNameToTypeMap(Code)




Constructor Detail
TreeWizard
public TreeWizard(TreeAdaptor adaptor)(Code)



TreeWizard
public TreeWizard(TreeAdaptor adaptor, Map tokenNameToTypeMap)(Code)



TreeWizard
public TreeWizard(TreeAdaptor adaptor, String[] tokenNames)(Code)



TreeWizard
public TreeWizard(String[] tokenNames)(Code)




Method Detail
_equals
protected static boolean _equals(Object t1, Object t2, TreeAdaptor adaptor)(Code)



_index
protected void _index(Object t, Map m)(Code)
Do the work for index



_parse
protected boolean _parse(Object t1, TreePattern t2, Map labels)(Code)
Do the work for parse. Check to see if the t2 pattern fits the structure and token types in t1. Check text if the pattern has text arguments on nodes. Fill labels map with pointers to nodes in tree matched against nodes in pattern with labels.



_visit
protected void _visit(Object t, Object parent, int childIndex, int ttype, ContextVisitor visitor)(Code)
Do the recursive work for visit



computeTokenTypes
public Map computeTokenTypes(String[] tokenNames)(Code)
Compute a Map that is an inverted index of tokenNames (which maps int token types to names).



create
public Object create(String pattern)(Code)
Create a tree or node from the indicated tree pattern that closely follows ANTLR tree grammar tree element syntax: (root child1 ... child2). You can also just pass in a node: ID Any node can have a text argument: ID[foo] (notice there are no quotes around foo--it's clear it's a string). nil is a special name meaning "give me a nil node". Useful for making lists: (nil A B C) is a list of A B C.



equals
public static boolean equals(Object t1, Object t2, TreeAdaptor adaptor)(Code)
Compare t1 and t2; return true if token types/text, structure match exactly. The trees are examined in their entirety so that (A B) does not match (A B C) nor (A (B C)). // TODO: allow them to pass in a comparator TODO: have a version that is nonstatic so it can use instance adaptor I cannot rely on the tree node's equals() implementation as I make no constraints at all on the node types nor interface etc...



equals
public boolean equals(Object t1, Object t2)(Code)
Compare type, structure, and text of two trees, assuming adaptor in this instance of a TreeWizard.



find
public List find(Object t, int ttype)(Code)
Return a List of tree nodes with token type ttype



find
public List find(Object t, String pattern)(Code)
Return a List of subtrees matching pattern.



findFirst
public Object findFirst(Object t, int ttype)(Code)



findFirst
public Object findFirst(Object t, String pattern)(Code)



getTokenType
public int getTokenType(String tokenName)(Code)
Using the map of token names to token types, return the type.



index
public Map index(Object t)(Code)
Walk the entire tree and make a node name to nodes mapping. For now, use recursion but later nonrecursive version may be more efficient. Returns Map where the List is of your AST node type. The Integer is the token type of the node. TODO: save this index so that find and visit are faster



parse
public boolean parse(Object t, String pattern, Map labels)(Code)
Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels on the various nodes and '.' (dot) as the node/subtree wildcard, return true if the pattern matches and fill the labels Map with the labels pointing at the appropriate nodes. Return false if the pattern is malformed or the tree does not match. If a node specifies a text arg in pattern, then that must match for that node in t. TODO: what's a better way to indicate bad pattern? Exceptions are a hassle



parse
public boolean parse(Object t, String pattern)(Code)



visit
public void visit(Object t, int ttype, ContextVisitor visitor)(Code)
Visit every ttype node in t, invoking the visitor. This is a quicker version of the general visit(t, pattern) method. The labels arg of the visitor action method is never set (it's null) since using a token type rather than a pattern doesn't let us set a label.



visit
public void visit(Object t, String pattern, ContextVisitor visitor)(Code)
For all subtrees that match the pattern, execute the visit action. The implementation uses the root node of the pattern in combination with visit(t, ttype, visitor) so nil-rooted patterns are not allowed. Patterns with wildcard roots are also not allowed.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.