org.pkl.thirdparty.commonmark.parser.SourceLines 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.parser;
import org.pkl.thirdparty.commonmark.node.SourceSpan;
import java.util.ArrayList;
import java.util.List;
/**
* A set of lines ({@link SourceLine}) from the input source.
*
* @since 0.16.0
*/
public class SourceLines {
private final List lines = new ArrayList<>();
public static SourceLines empty() {
return new SourceLines();
}
public static SourceLines of(SourceLine sourceLine) {
SourceLines sourceLines = new SourceLines();
sourceLines.addLine(sourceLine);
return sourceLines;
}
public static SourceLines of(List sourceLines) {
SourceLines result = new SourceLines();
result.lines.addAll(sourceLines);
return result;
}
public void addLine(SourceLine sourceLine) {
lines.add(sourceLine);
}
public List getLines() {
return lines;
}
public boolean isEmpty() {
return lines.isEmpty();
}
public String getContent() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < lines.size(); i++) {
if (i != 0) {
sb.append('\n');
}
sb.append(lines.get(i).getContent());
}
return sb.toString();
}
public List getSourceSpans() {
List sourceSpans = new ArrayList<>();
for (SourceLine line : lines) {
SourceSpan sourceSpan = line.getSourceSpan();
if (sourceSpan != null) {
sourceSpans.add(sourceSpan);
}
}
return sourceSpans;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy