Search in sources :

Example 1 with TextBlock

use of com.google.idea.blaze.base.projectview.section.sections.TextBlock in project intellij by bazelbuild.

the class ProjectViewParserTest method testCommentsAreParsed.

@Test
public void testCommentsAreParsed() throws Exception {
    projectViewStorageManager.add(".blazeproject", "# comment", "directories:", "  # another comment", "  java/com/google", "  # comment", "  java/com/google/android", "");
    projectViewParser.parseProjectView(new File(".blazeproject"));
    errorCollector.assertNoIssues();
    ProjectViewSet projectViewSet = projectViewParser.getResult();
    ProjectViewSet.ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
    ProjectView projectView = projectViewFile.projectView;
    assertThat(projectView.getSectionsOfType(TextBlockSection.KEY).get(0).getTextBlock()).isEqualTo(new TextBlock(ImmutableList.of("# comment")));
    assertThat(projectView.getSectionsOfType(DirectorySection.KEY).get(0).items()).containsExactly(new DirectoryEntry(new WorkspacePath("java/com/google"), true), new DirectoryEntry(new WorkspacePath("java/com/google/android"), true));
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) File(java.io.File) TextBlock(com.google.idea.blaze.base.projectview.section.sections.TextBlock) Test(org.junit.Test)

Example 2 with TextBlock

use of com.google.idea.blaze.base.projectview.section.sections.TextBlock 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);
}
Also used : ItemOrTextBlock(com.google.idea.blaze.base.projectview.section.sections.ItemOrTextBlock) ImmutableList(com.google.common.collect.ImmutableList) ItemOrTextBlock(com.google.idea.blaze.base.projectview.section.sections.ItemOrTextBlock) TextBlock(com.google.idea.blaze.base.projectview.section.sections.TextBlock) Nullable(javax.annotation.Nullable)

Aggregations

TextBlock (com.google.idea.blaze.base.projectview.section.sections.TextBlock)2 ImmutableList (com.google.common.collect.ImmutableList)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)1 ItemOrTextBlock (com.google.idea.blaze.base.projectview.section.sections.ItemOrTextBlock)1 File (java.io.File)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1