diff --git a/language-antlr-utils/src/main/java/de/jplag/antlr/ContextDelegateVisitor.java b/language-antlr-utils/src/main/java/de/jplag/antlr/ContextDelegateVisitor.java index d1f102ff3..6c8bf10ae 100644 --- a/language-antlr-utils/src/main/java/de/jplag/antlr/ContextDelegateVisitor.java +++ b/language-antlr-utils/src/main/java/de/jplag/antlr/ContextDelegateVisitor.java @@ -4,9 +4,19 @@ import org.antlr.v4.runtime.ParserRuleContext; +/** + * Delegates visiting a {@link ParserRuleContext} to a different {@link ContextVisitor} derived by the given mapper + * function + * @param The original antlr type visited + * @param The target {@link ParserRuleContext} to visit instead + */ public class ContextDelegateVisitor extends DelegateVisitor { private final ContextVisitor contextVisitor; + /** + * @param delegate The visitor to delegate to + * @param mapper The mapper function used to derive the target antlr context + */ public ContextDelegateVisitor(ContextVisitor delegate, Function mapper) { super(delegate, mapper); this.contextVisitor = delegate; diff --git a/language-antlr-utils/src/main/java/de/jplag/antlr/DelegateVisitor.java b/language-antlr-utils/src/main/java/de/jplag/antlr/DelegateVisitor.java index 1e4d679cb..465a7363f 100644 --- a/language-antlr-utils/src/main/java/de/jplag/antlr/DelegateVisitor.java +++ b/language-antlr-utils/src/main/java/de/jplag/antlr/DelegateVisitor.java @@ -2,33 +2,59 @@ import java.util.function.Function; +/** + * Delegates visiting of a given antlr entity to a visitor for a different antlr entity. + * @param The original antlr type visited + * @param The target antlr type + */ public class DelegateVisitor { private final AbstractVisitor delegate; protected final Function mapper; private boolean mapOnExit; + /** + * @param delegate The target visitor to use + * @param mapper The mapper function used to derive the target entity + */ public DelegateVisitor(AbstractVisitor delegate, Function mapper) { this.delegate = delegate; this.mapper = mapper; this.mapOnExit = false; } + /** + * Delegates entering the original context + * @param parentData The data of the original visitor + */ public void delegateEnter(HandlerData parentData) { if (!this.mapOnExit) { this.delegate.enter(parentData.derive(this.mapper)); } } + /** + * Makes this visitor map exit events to enter events. Used mostly for mapping exit events to terminal nodes, which only + * provide enter events + */ public void mapOnExit() { this.mapOnExit = true; } + /** + * Delegates exiting the original context + * @param parentData The data of the original visitor + */ public void delegateExit(HandlerData parentData) { if (this.mapOnExit) { this.delegate.enter(parentData.derive(this.mapper)); } } + /** + * Checks if the target entity is present in the given antlr entity + * @param entity The original antlr entity + * @return is present + */ public boolean isPresent(T entity) { try { return this.mapper.apply(entity) != null; diff --git a/languages/golang/src/main/java/de/jplag/golang/GoListener.java b/languages/golang/src/main/java/de/jplag/golang/GoListener.java index cee4693e0..e68ebde6b 100644 --- a/languages/golang/src/main/java/de/jplag/golang/GoListener.java +++ b/languages/golang/src/main/java/de/jplag/golang/GoListener.java @@ -125,6 +125,10 @@ import de.jplag.golang.grammar.GoParser.TypeSwitchStmtContext; import de.jplag.golang.grammar.GoParser.VarDeclContext; +/** + * Provides token extraction rules for {@link GoLanguage} Based on an older implementation of the language module; see + * JPlagGoListener.java in the history. + */ public class GoListener extends AbstractAntlrListener { public GoListener() { metaDeclarations();