Skip to content

Commit

Permalink
Return a default value in the visitor
Browse files Browse the repository at this point in the history
I am not sure I like forcing users to provide the default value.
  • Loading branch information
I-Al-Istannen committed Jun 14, 2022
1 parent 6c3efea commit 7478193
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main/java/spoon/javadoc/external/elements/JavadocVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,60 @@
*/
public interface JavadocVisitor<T> {

/**
* @return the default value to return if a visit method is not overwritten
*/
T defaultValue();

/**
* @param tag the inline tag to visit
* @return a return value
* @implNote the default implementation always returns null and visits all arguments
* @implNote the default implementation visits all arguments
*/
default T visitInlineTag(JavadocInlineTag tag) {
for (JavadocElement element : tag.getElements()) {
element.accept(this);
}
return null;
return defaultValue();
}

/**
* @param tag the block tag to visit
* @return a return value
* @implNote the default implementation always returns null and visits all elements
* @implNote the default implementation visits all elements
*/
default T visitBlockTag(JavadocBlockTag tag) {
for (JavadocElement element : tag.getElements()) {
element.accept(this);
}
return null;
return defaultValue();
}

/**
* @param snippet the snippet tag to visit
* @return a return value
* @implNote the default implementation always returns null and visits all elements
* @implNote the default implementation visits all elements
*/
default T visitSnippet(JavadocSnippetTag snippet) {
for (JavadocElement element : snippet.getElements()) {
element.accept(this);
}
return null;
return defaultValue();
}

/**
* @param text the javadoc text to visit
* @return a return value
* @implNote the default implementation always returns null
*/
default T visitText(JavadocText text) {
return null;
return defaultValue();
}

/**
* @param reference the javadoc reference to visit
* @return a return value
* @implNote the default implementation always returns null
*/
default T visitReference(JavadocReference reference) {
return null;
return defaultValue();
}
}

0 comments on commit 7478193

Please sign in to comment.