use of com.google.idea.blaze.base.projectview.section.sections.ItemOrTextBlock in project intellij by bazelbuild.
the class ListSectionParser method parse.
@Nullable
@Override
public final ListSection<T> parse(ProjectViewParser parser, ParseContext parseContext) {
if (parseContext.atEnd()) {
return null;
}
String name = getName();
if (!parseContext.current().text.equals(name + ':')) {
return null;
}
parseContext.consume();
ImmutableList.Builder<ItemOrTextBlock<T>> builder = ImmutableList.builder();
boolean correctIndentationRun = true;
List<ItemOrTextBlock<T>> savedTextBlocks = Lists.newArrayList();
while (!parseContext.atEnd()) {
boolean isIndented = parseContext.current().indent == SectionParser.INDENT;
if (!isIndented && correctIndentationRun) {
parseContext.savePosition();
}
correctIndentationRun = isIndented;
ItemOrTextBlock<T> itemOrTextBlock = null;
TextBlock textBlock = TextBlockSection.parseTextBlock(parseContext);
if (textBlock != null) {
itemOrTextBlock = new ItemOrTextBlock<>(textBlock);
} else if (isIndented) {
T item = parseItem(parser, parseContext);
if (item != null) {
parseContext.consume();
itemOrTextBlock = new ItemOrTextBlock<>(item);
}
}
if (itemOrTextBlock == null) {
break;
}
if (isIndented) {
builder.addAll(savedTextBlocks);
builder.add(itemOrTextBlock);
savedTextBlocks.clear();
parseContext.clearSavedPosition();
} else {
savedTextBlocks.add(new ItemOrTextBlock<>(textBlock));
}
}
parseContext.resetToSavedPosition();
ImmutableList<ItemOrTextBlock<T>> items = builder.build();
if (items.isEmpty()) {
parseContext.addError(String.format("Empty section: '%s'", name));
}
return new ListSection<>(key, items);
}
Aggregations