Using A Visitor
See original GitHub issuein your visitor example:
Node node = parser.parse("...");
MyVisitor visitor = new MyVisitor();
node.accept(visitor);
class MyVisitor extends AbstractVisitor {
@Override
public void visit(Paragraph paragraph) {
// Do something with paragraph (override other methods for other nodes):
System.out.println(paragraph);
// Descend into children:
visitChildren(paragraph);
}
}
What should be printed to System out? Because I tried on a few things and when visiting both headers and paragraphs all it prints is the type folowed by curly braces like this:
INFO: Visit:(p)- Paragraph{}
I thought maybe it would print out the contents of the node? How do I get to the content of the node?
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Visitor - Refactoring.Guru
The Visitor pattern lets you execute an operation over a set of objects with different classes by having a visitor object implement several...
Read more >Visitor Design Pattern in Java - Baeldung
A quick and practical overview of the Visitor design pattern in Java. ... First of all, the client uses a Visitor implementation and...
Read more >Visitor Design Pattern - SourceMaking
Each visit() method accepts a single argument - a pointer or reference to an original Element derived class. Each operation to be supported...
Read more >Visitor design pattern - GeeksforGeeks
Visitor design pattern is one of the behavioral design patterns. It is used when we have to perform an operation on a group...
Read more >Design Patterns - Visitor Pattern - Tutorialspoint
In Visitor pattern, we use a visitor class which changes the executing algorithm of an element class. By this way, execution algorithm of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @pcj, that’s right. Maybe we should change the example to something more meaningful. Maybe visiting all links and printing the destination? Any other ideas?
Good idea, changed the example now: https://github.com/atlassian/commonmark-java#use-a-visitor-to-process-parsed-nodes