spoon.javadoc.api.elements.JavadocCommentView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spoon-javadoc Show documentation
Show all versions of spoon-javadoc Show documentation
A javadoc parser for the java source code analysis tool spoon.
package spoon.javadoc.api.elements;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import spoon.javadoc.api.JavadocTagType;
/**
* A slightly more expressive view of a {@code List}.
*/
public class JavadocCommentView {
private final List elements;
public JavadocCommentView(List elements) {
this.elements = List.copyOf(elements);
}
public List getElements() {
return elements;
}
public List getBlockTags() {
return elements.stream()
.filter(it -> it instanceof JavadocBlockTag)
.map(it -> (JavadocBlockTag) it)
.collect(Collectors.toList());
}
public List getBlockTag(JavadocTagType type) {
return getBlockTags().stream()
.filter(it -> type.equals(it.getTagType()))
.collect(Collectors.toList());
}
public List getBlockTagArguments(
JavadocTagType type, Class expectedArgumentClass
) {
return getBlockTag(type).stream()
.flatMap(it -> it.getArgument(expectedArgumentClass).stream())
.collect(Collectors.toList());
}
public List getBody() {
return elements.stream()
.filter(it -> !(it instanceof JavadocBlockTag))
.collect(Collectors.toList());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JavadocCommentView view = (JavadocCommentView) o;
return Objects.equals(elements, view.elements);
}
@Override
public int hashCode() {
return Objects.hash(elements);
}
@Override
public String toString() {
return "JavadocCommentView{" +
"elements=" + elements +
'}';
}
}