org.pkl.thirdparty.commonmark.node.SourceSpans Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pkl-tools Show documentation
Show all versions of pkl-tools Show documentation
Fat Jar containing pkl-cli, pkl-codegen-java, pkl-codegen-kotlin, pkl-config-java, pkl-core, pkl-doc, and their shaded third-party dependencies.
package org.pkl.thirdparty.commonmark.node;
import java.util.ArrayList;
import java.util.List;
/**
* A list of source spans that can be added to. Takes care of merging adjacent source spans.
*
* @since 0.16.0
*/
public class SourceSpans {
private List sourceSpans;
public static SourceSpans empty() {
return new SourceSpans();
}
public List getSourceSpans() {
return sourceSpans != null ? sourceSpans : List.of();
}
public void addAllFrom(Iterable extends Node> nodes) {
for (Node node : nodes) {
addAll(node.getSourceSpans());
}
}
public void addAll(List other) {
if (other.isEmpty()) {
return;
}
if (sourceSpans == null) {
sourceSpans = new ArrayList<>();
}
if (sourceSpans.isEmpty()) {
sourceSpans.addAll(other);
} else {
int lastIndex = sourceSpans.size() - 1;
SourceSpan a = sourceSpans.get(lastIndex);
SourceSpan b = other.get(0);
if (a.getInputIndex() + a.getLength() == b.getInputIndex()) {
sourceSpans.set(lastIndex, SourceSpan.of(a.getLineIndex(), a.getColumnIndex(), a.getInputIndex(), a.getLength() + b.getLength()));
sourceSpans.addAll(other.subList(1, other.size()));
} else {
sourceSpans.addAll(other);
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy