Skip to content

Commit

Permalink
ClaroDocs Now Renders Exported Initializers/Unwrappers
Browse files Browse the repository at this point in the history
Straightforward modelling of initializers/unwrappers.
  • Loading branch information
JasonSteving99 committed Oct 6, 2023
1 parent 740b928 commit bfa8c47
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/java/com/claro/module_system/clarodocs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ java_binary(
"//src/java/com/claro/module_system/clarodocs/html_rendering/aliases",
"//src/java/com/claro/module_system/clarodocs/html_rendering/contracts",
"//src/java/com/claro/module_system/clarodocs/html_rendering/homepage:homepage_html",
"//src/java/com/claro/module_system/clarodocs/html_rendering/initializers",
"//src/java/com/claro/module_system/clarodocs/html_rendering/procedures:procedure_html",
"//src/java/com/claro/module_system/clarodocs/html_rendering/typedefs:type_html",
"//src/java/com/claro/module_system/clarodocs/html_rendering/unwrappers",
"//src/java/com/claro/module_system/module_serialization/proto:serialized_claro_module_java_proto",
],
visibility = ["//visibility:public"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.claro.module_system.clarodocs.html_rendering.aliases.AliasHtml;
import com.claro.module_system.clarodocs.html_rendering.contracts.ContractHtml;
import com.claro.module_system.clarodocs.html_rendering.homepage.HomePageHtml;
import com.claro.module_system.clarodocs.html_rendering.initializers.InitializersHtml;
import com.claro.module_system.clarodocs.html_rendering.procedures.ProcedureHtml;
import com.claro.module_system.clarodocs.html_rendering.typedefs.TypeHtml;
import com.claro.module_system.clarodocs.html_rendering.unwrappers.UnwrappersHtml;
import com.claro.module_system.module_serialization.proto.SerializedClaroModule;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
Expand Down Expand Up @@ -56,7 +58,17 @@ public static void main(String[] args) throws IOException {
// Render contract impls.
serializedClaroModule.getExportedContractImplementationsList().forEach(
contractImpl -> ContractHtml.renderContractImplHtml(res, contractImpl));
// Top-level procedure defs.
// Render initializers.
serializedClaroModule.getExportedTypeDefinitions().getInitializersByTypeNameMap()
.forEach(
(initializedTypeName, procedures) ->
InitializersHtml.renderInitializersBlock(res, initializedTypeName, procedures));
// Render unwrappers.
serializedClaroModule.getExportedTypeDefinitions().getUnwrappersByTypeNameMap()
.forEach(
(unwrappedTypeName, procedures) ->
UnwrappersHtml.renderUnwrappersBlock(res, unwrappedTypeName, procedures));
// Render top-level procedure defs.
res.append(
serializedClaroModule.getExportedProcedureDefinitionsList().stream()
.map(ProcedureHtml::generateProcedureHtml)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

java_library(
name = "initializers",
srcs = ["InitializersHtml.java"],
deps = [
"//src/java/com/claro/module_system/clarodocs/html_rendering:util",
"//src/java/com/claro/module_system/clarodocs/html_rendering/procedures:procedure_html",
"//src/java/com/claro/module_system/module_serialization/proto:serialized_claro_module_java_proto",
],
visibility = [
"//src/java/com/claro/module_system/clarodocs:__pkg__",
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.claro.module_system.clarodocs.html_rendering.initializers;

import com.claro.module_system.clarodocs.html_rendering.Util;
import com.claro.module_system.clarodocs.html_rendering.procedures.ProcedureHtml;
import com.claro.module_system.module_serialization.proto.SerializedClaroModule;

import java.util.stream.Collectors;

import static com.claro.module_system.clarodocs.html_rendering.Util.GrammarPart.INITIALIZERS;

public class InitializersHtml {
public static final String INITIALIZERS_CLASS = "initializers";
public static final String INITIALIZERS_BLOCK_TEMPLATE =
INITIALIZERS + " %s {\n%s\n}";

public static void renderInitializersBlock(
StringBuilder res,
String initializedTypeName,
SerializedClaroModule.ExportedTypeDefinitions.ProcedureList procedures) {
res.append(
Util.wrapAsDefaultCodeBlock(
INITIALIZERS_CLASS,
initializedTypeName,
String.format(
INITIALIZERS_BLOCK_TEMPLATE,
initializedTypeName,
procedures.getProceduresList().stream()
.map(procedure -> ProcedureHtml.generateProcedureHtmlWithIndentationLevel(procedure, 1))
.collect(Collectors.joining("\n"))
)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ java_library(
"//src/java/com/claro/module_system/module_serialization/proto/claro_types:claro_types_java_proto",
],
visibility = [
"//src/java/com/claro/module_system/clarodocs/html_rendering/contracts:__pkg__",
"//src/java/com/claro/module_system/clarodocs:__pkg__",
"//src/java/com/claro/module_system/clarodocs/html_rendering/contracts:__pkg__",
"//src/java/com/claro/module_system/clarodocs/html_rendering/initializers:__pkg__",
"//src/java/com/claro/module_system/clarodocs/html_rendering/unwrappers:__pkg__",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

java_library(
name = "unwrappers",
srcs = ["UnwrappersHtml.java"],
deps = [
"//src/java/com/claro/module_system/clarodocs/html_rendering:util",
"//src/java/com/claro/module_system/clarodocs/html_rendering/procedures:procedure_html",
"//src/java/com/claro/module_system/module_serialization/proto:serialized_claro_module_java_proto",
],
visibility = [
"//src/java/com/claro/module_system/clarodocs:__pkg__",
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.claro.module_system.clarodocs.html_rendering.unwrappers;

import com.claro.module_system.clarodocs.html_rendering.Util;
import com.claro.module_system.clarodocs.html_rendering.procedures.ProcedureHtml;
import com.claro.module_system.module_serialization.proto.SerializedClaroModule;

import java.util.stream.Collectors;

import static com.claro.module_system.clarodocs.html_rendering.Util.GrammarPart.UNWRAPPERS;

public class UnwrappersHtml {
public static final String UNWRAPPERS_CLASS = "unwrappers";
public static final String UNWRAPPERS_BLOCK_TEMPLATE =
UNWRAPPERS + " %s {\n%s\n}";

public static void renderUnwrappersBlock(
StringBuilder res,
String unwrappedTypeName,
SerializedClaroModule.ExportedTypeDefinitions.ProcedureList procedures) {
res.append(
Util.wrapAsDefaultCodeBlock(
UNWRAPPERS_CLASS,
unwrappedTypeName,
String.format(
UNWRAPPERS_BLOCK_TEMPLATE,
unwrappedTypeName,
procedures.getProceduresList().stream()
.map(procedure -> ProcedureHtml.generateProcedureHtmlWithIndentationLevel(procedure, 1))
.collect(Collectors.joining("\n"))
)
));
}
}

0 comments on commit bfa8c47

Please sign in to comment.