use of com.google.idea.blaze.base.projectview.section.SectionParser in project intellij by bazelbuild.
the class ProjectViewDocumentationProvider method generateDoc.
@Nullable
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
SectionParser section = getSection(element);
if (section == null) {
return null;
}
StringBuilder builder = new StringBuilder();
String quickDocs = section.quickDocs();
if (quickDocs != null) {
builder.append(wrapInTag("<p>" + section.quickDocs(), "code"));
}
String url = getUrlFor(element.getProject(), section, false);
if (url != null) {
builder.append(String.format("<p><b>External documentation</b>:<br><a href=\"%s\">%s</a>", url, url));
}
return wrapInTag(wrapInTag(builder.toString(), "body"), "html");
}
use of com.google.idea.blaze.base.projectview.section.SectionParser in project intellij by bazelbuild.
the class ProjectViewParser method parseProjectView.
private void parseProjectView(ParseContext parseContext) {
ImmutableList.Builder<Section<?>> sections = ImmutableList.builder();
List<SectionParser> sectionParsers = Sections.getParsers();
while (!parseContext.atEnd()) {
Section section = null;
for (SectionParser sectionParser : sectionParsers) {
section = sectionParser.parse(this, parseContext);
if (section != null) {
sections.add(section);
break;
}
}
if (section == null) {
if (parseContext.current().indent != 0) {
parseContext.addError(String.format("Invalid indentation on line: '%s'", parseContext.current().text));
skipSection(parseContext);
} else {
parseContext.addError(String.format("Could not parse: '%s'", parseContext.current().text));
parseContext.consume();
// Skip past the entire section
skipSection(parseContext);
}
}
}
ProjectView projectView = new ProjectView(sections.build());
projectViewFiles.add(new ProjectViewSet.ProjectViewFile(projectView, parseContext.getProjectViewFile()));
}
use of com.google.idea.blaze.base.projectview.section.SectionParser in project intellij by bazelbuild.
the class ProjectViewSetTest method testProjectViewSetSerializable.
@Test
public void testProjectViewSetSerializable() throws Exception {
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("test")))).add(ListSection.builder(TargetSection.KEY).add(TargetExpression.fromStringSafe("//test:all"))).add(ScalarSection.builder(ImportSection.KEY).set(new WorkspacePath("test"))).add(ListSection.builder(TestSourceSection.KEY).add(new Glob("javatests/*"))).add(ListSection.builder(ExcludedSourceSection.KEY).add(new Glob("*.java"))).add(ListSection.builder(BuildFlagsSection.KEY).add("--android_sdk=abcd")).add(ListSection.builder(SyncFlagsSection.KEY).add("--config=arm")).add(ListSection.builder(ImportTargetOutputSection.KEY).add(Label.create("//test:test"))).add(ListSection.builder(ExcludeTargetSection.KEY).add(Label.create("//test:test"))).add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.JAVA)).add(ListSection.builder(AdditionalLanguagesSection.KEY).add(LanguageClass.JAVA)).add(TextBlockSection.of(TextBlock.newLine())).add(ListSection.builder(RunConfigurationsSection.KEY).add(new WorkspacePath("test"))).add(ScalarSection.builder(ShardBlazeBuildsSection.KEY).set(false)).add(ScalarSection.builder(TargetShardSizeSection.KEY).set(500)).build()).build();
// Assert we have all sections
assert projectViewSet.getTopLevelProjectViewFile() != null;
ProjectView projectView = projectViewSet.getTopLevelProjectViewFile().projectView;
for (SectionParser parser : Sections.getParsers()) {
ImmutableList<Section<?>> sections = projectView.getSections();
assertThat(sections.stream().anyMatch(section -> section.isSectionType(parser.getSectionKey()))).isTrue();
}
TestUtils.assertIsSerializable(projectViewSet);
}
use of com.google.idea.blaze.base.projectview.section.SectionParser in project intellij by bazelbuild.
the class BlazeEditProjectViewControl method modifyInitialProjectView.
private static String modifyInitialProjectView(BuildSystem buildSystem, String initialProjectViewText, WorkspacePathResolver workspacePathResolver) {
BlazeContext context = new BlazeContext();
ProjectViewParser projectViewParser = new ProjectViewParser(context, workspacePathResolver);
projectViewParser.parseProjectView(initialProjectViewText);
ProjectViewSet projectViewSet = projectViewParser.getResult();
ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
if (projectViewFile == null) {
return initialProjectViewText;
}
ProjectView projectView = projectViewFile.projectView;
// Sort default value providers to match the section order
List<SectionKey> sectionKeys = Sections.getParsers().stream().map(SectionParser::getSectionKey).collect(toList());
List<ProjectViewDefaultValueProvider> defaultValueProviders = Lists.newArrayList(ProjectViewDefaultValueProvider.EP_NAME.getExtensions());
defaultValueProviders.sort(Comparator.comparingInt(val -> sectionKeys.indexOf(val.getSectionKey())));
for (ProjectViewDefaultValueProvider defaultValueProvider : defaultValueProviders) {
projectView = defaultValueProvider.addProjectViewDefaultValue(buildSystem, projectViewSet, projectView);
}
return ProjectViewParser.projectViewToString(projectView);
}
use of com.google.idea.blaze.base.projectview.section.SectionParser in project intellij by bazelbuild.
the class ProjectViewVerifier method warnAboutDeprecatedSections.
private static void warnAboutDeprecatedSections(BlazeContext context, ProjectViewSet projectViewSet) {
List<SectionParser> deprecatedParsers = Sections.getParsers().stream().filter(SectionParser::isDeprecated).collect(toList());
for (SectionParser sectionParser : deprecatedParsers) {
for (ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
ProjectView projectView = projectViewFile.projectView;
if (projectView.getSections().stream().anyMatch(section -> section.isSectionType(sectionParser.getSectionKey()))) {
String deprecationMessage = sectionParser.getDeprecationMessage();
if (deprecationMessage == null) {
deprecationMessage = String.format("%s is deprecated", sectionParser.getName());
}
IssueOutput.warn(deprecationMessage).inFile(projectViewFile.projectViewFile).submit(context);
}
}
}
}
Aggregations