martin-g commented on a change in pull request #1341:
URL: https://github.com/apache/avro/pull/1341#discussion_r711794865
##########
File path:
lang/java/compiler/src/test/java/org/apache/avro/compiler/schema/TestSchemas.java
##########
@@ -38,36 +59,11 @@
+ "
{\"name\":\"methodName\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}\n"
+ " ]}},\n" + "
{\"name\":\"node\",\"type\":\"SampleNode\"}]}}}" + "]}";
- private static class PrintingVisitor implements SchemaVisitor {
-
- @Override
- public SchemaVisitorAction visitTerminal(Schema terminal) {
- System.out.println("Terminal: " + terminal.getFullName());
- return SchemaVisitorAction.CONTINUE;
- }
-
- @Override
- public SchemaVisitorAction visitNonTerminal(Schema terminal) {
- System.out.println("NONTerminal start: " + terminal.getFullName());
- return SchemaVisitorAction.CONTINUE;
- }
-
- @Override
- public SchemaVisitorAction afterVisitNonTerminal(Schema terminal) {
- System.out.println("NONTerminal end: " + terminal.getFullName());
- return SchemaVisitorAction.CONTINUE;
- }
-
- @Override
- public Object get() {
- return null;
- }
Review comment:
One could also override the methods, print and call super:
```
CloningVisitor cv = new CloningVisitor(recSchema) {
@Override
public SchemaVisitorAction visitTerminal(Schema terminal) {
System.out.println("Terminal: " + terminal.getFullName());
return super.visitTerminal(terminal);
}
// ...
};
```
But if you need to do this at many places then it becomes ugly. Having
around `PrintingVisitor` make is as easy as `Schemas.visit(recSchema, new
PrintingVisitor());`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]