All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spoon.javadoc.api.elements.JavadocCommentView Maven / Gradle / Ivy

There is a newer version: 11.1.1-beta-14
Show newest version
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 +
		       '}';
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy