diff --git a/assembly/pom.xml b/assembly/pom.xml
index ab82935..e8c323f 100644
--- a/assembly/pom.xml
+++ b/assembly/pom.xml
@@ -10,7 +10,6 @@
1.0-SNAPSHOT
- nu.zoom.dsl
assembly
diff --git a/parser/pom.xml b/parser/pom.xml
index a5d8510..e533c1a 100644
--- a/parser/pom.xml
+++ b/parser/pom.xml
@@ -10,8 +10,8 @@
1.0-SNAPSHOT
- nu.zoom.dsl
parser
+
org.antlr
diff --git a/parser/src/main/java/nu/zoom/dsl/ast/EndpointNode.java b/parser/src/main/java/nu/zoom/dsl/ast/EndpointNode.java
index c4c771d..cb0fd6f 100644
--- a/parser/src/main/java/nu/zoom/dsl/ast/EndpointNode.java
+++ b/parser/src/main/java/nu/zoom/dsl/ast/EndpointNode.java
@@ -1,7 +1,5 @@
package nu.zoom.dsl.ast;
-import java.util.Optional;
-
public record EndpointNode(
PathsNode paths,
String inputType) {
diff --git a/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java b/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java
index a70e385..d175077 100644
--- a/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java
+++ b/parser/src/main/java/nu/zoom/dsl/ast/EndpointsVisitorTransformer.java
@@ -8,80 +8,81 @@ import java.util.ArrayList;
import java.util.List;
public class EndpointsVisitorTransformer extends EndpointsBaseVisitor {
- private ArrayList endpoints = new ArrayList<>();
- private ArrayList config = new ArrayList<>();
- private ArrayList dataTypes = new ArrayList<>();
- public EndpointsVisitorTransformer() {
- }
+ private final ArrayList endpoints = new ArrayList<>();
+ private final ArrayList config = new ArrayList<>();
+ private final ArrayList dataTypes = new ArrayList<>();
- public List getEndpoints() {
- return List.copyOf(endpoints);
- }
+ public EndpointsVisitorTransformer() {
+ }
- public List getConfig() {
- return List.copyOf(config);
- }
+ public List getEndpoints() {
+ return List.copyOf(endpoints);
+ }
- public List getDataTypes() {
- return List.copyOf(dataTypes);
- }
+ public List getConfig() {
+ return List.copyOf(config);
+ }
- @Override
- public EndpointsParser.DocumentContext visitConfigitem(EndpointsParser.ConfigitemContext ctx) {
- String configKey = ctx.configkey().IDENTIFIER().getText() ;
- String configValue = getText(ctx.configvalue().IDENTIFIER(), ctx.configvalue().VALUE()) ;
- this.config.add(new ConfigItemNode(configKey, configValue));
- return super.visitConfigitem(ctx) ;
- }
+ public List getDataTypes() {
+ return List.copyOf(dataTypes);
+ }
- @Override
- public EndpointsParser.DocumentContext visitCompoundType(EndpointsParser.CompoundTypeContext ctx) {
- this.dataTypes.add(extractCompoundTypeNode(ctx));
- return super.visitCompoundType(ctx);
- }
+ @Override
+ public EndpointsParser.DocumentContext visitConfigitem(EndpointsParser.ConfigitemContext ctx) {
+ String configKey = ctx.configkey().IDENTIFIER().getText();
+ String configValue = getText(ctx.configvalue().IDENTIFIER(), ctx.configvalue().VALUE());
+ this.config.add(new ConfigItemNode(configKey, configValue));
+ return super.visitConfigitem(ctx);
+ }
- @Override
- public EndpointsParser.DocumentContext visitEndpoint(EndpointsParser.EndpointContext ctx) {
- List segments = ctx
- .path()
- .pathSegment()
- .stream()
- .map(
- segment -> getText(segment.IDENTIFIER(), segment.VALUE())
- ).toList() ;
- TerminalNode typeReference = ctx.IDENTIFIER() ;
- if (typeReference != null) {
- var endpoint = new EndpointNode(new PathsNode(segments), typeReference.getText());
- this.endpoints.add(endpoint);
- } else {
- var compoundTypeNode = extractCompoundTypeNode(ctx.compoundType()) ;
- var endpoint = new EndpointNode(new PathsNode(segments), compoundTypeNode.name());
- this.dataTypes.add(compoundTypeNode);
- this.endpoints.add(endpoint);
- }
- return super.visitEndpoint(ctx);
- }
+ @Override
+ public EndpointsParser.DocumentContext visitCompoundType(EndpointsParser.CompoundTypeContext ctx) {
+ this.dataTypes.add(extractCompoundTypeNode(ctx));
+ return super.visitCompoundType(ctx);
+ }
- private CompoundTypeNode extractCompoundTypeNode(EndpointsParser.CompoundTypeContext ctx) {
- String typeName = ctx.compoundTypeName().getText() ;
- List fields = extractTypeFields(ctx.compoundFields().compoundField()) ;
- return new CompoundTypeNode(typeName, fields) ;
- }
+ @Override
+ public EndpointsParser.DocumentContext visitEndpoint(EndpointsParser.EndpointContext ctx) {
+ List segments = ctx
+ .path()
+ .pathSegment()
+ .stream()
+ .map(
+ segment -> getText(segment.IDENTIFIER(), segment.VALUE())
+ ).toList();
+ TerminalNode typeReference = ctx.IDENTIFIER();
+ if (typeReference != null) {
+ var endpoint = new EndpointNode(new PathsNode(segments), typeReference.getText());
+ this.endpoints.add(endpoint);
+ } else {
+ var compoundTypeNode = extractCompoundTypeNode(ctx.compoundType());
+ var endpoint = new EndpointNode(new PathsNode(segments), compoundTypeNode.name());
+ this.dataTypes.add(compoundTypeNode);
+ this.endpoints.add(endpoint);
+ }
+ return super.visitEndpoint(ctx);
+ }
- private List extractTypeFields(List compoundFieldContexts) {
- return compoundFieldContexts.stream().map(
- ctx -> new FieldNode(
- ctx.fieldName().getText(),
- ctx.fieldType().getText()
- )
- ).toList() ;
- }
+ private CompoundTypeNode extractCompoundTypeNode(EndpointsParser.CompoundTypeContext ctx) {
+ String typeName = ctx.compoundTypeName().getText();
+ List fields = extractTypeFields(ctx.compoundFields().compoundField());
+ return new CompoundTypeNode(typeName, fields);
+ }
- // Concatenate the text from to terminal nodes. Useful for contexts that are either an identifier or a value,
- // and you just want the text from whichever is not null.
- private String getText(TerminalNode identifier, TerminalNode value) {
- return
- identifier != null ? identifier.getText() : ""
- + value != null ? value.getText() : "" ;
- }
+ private List extractTypeFields(List compoundFieldContexts) {
+ return compoundFieldContexts.stream().map(
+ ctx -> new FieldNode(
+ ctx.fieldName().getText(),
+ ctx.fieldType().getText()
+ )
+ ).toList();
+ }
+
+ // Concatenate the text from to terminal nodes. Useful for contexts that are either an identifier or a value,
+ // and you just want the text from whichever is not null.
+ private String getText(TerminalNode identifier, TerminalNode value) {
+ return
+ ((identifier != null) ? identifier.getText() : "") +
+ ((value != null) ? value.getText() : "");
+ }
}
diff --git a/parser/src/main/java/nu/zoom/dsl/ast/ParserWrapper.java b/parser/src/main/java/nu/zoom/dsl/ast/ParserWrapper.java
index e0397d7..9ccc8a1 100644
--- a/parser/src/main/java/nu/zoom/dsl/ast/ParserWrapper.java
+++ b/parser/src/main/java/nu/zoom/dsl/ast/ParserWrapper.java
@@ -7,7 +7,6 @@ import org.antlr.v4.runtime.CommonTokenStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.nio.file.Path;
public class ParserWrapper {
diff --git a/parser/src/main/java/nu/zoom/dsl/cli/EndpointsCLI.java b/parser/src/main/java/nu/zoom/dsl/cli/EndpointsCLI.java
index ff4be61..c955684 100644
--- a/parser/src/main/java/nu/zoom/dsl/cli/EndpointsCLI.java
+++ b/parser/src/main/java/nu/zoom/dsl/cli/EndpointsCLI.java
@@ -19,16 +19,20 @@ import java.util.concurrent.Callable;
description = "Generate source code from an endpoints specification file."
)
public class EndpointsCLI implements Callable {
- @Parameters(index = "0", description = "The source endpoints DSL file.")
+ @SuppressWarnings("unused")
+ @Parameters(index = "0", description = "The source endpoints DSL file.")
private Path file;
- @Option(names = {"-t", "--template"}, description = "The template directory. Default is ~/endpoints-templates")
+ @SuppressWarnings("CanBeFinal")
+ @Option(names = {"-t", "--template"}, description = "The template directory. Default is ~/endpoints-templates")
private Path templateDir = Paths.get(System.getProperty("user.dir"), "endpoints-templates");
- @Option(names = {"-o", "--output"}, description = "The directory to write the generated code to. Default is ~/endpoints-output")
+ @SuppressWarnings("CanBeFinal")
+ @Option(names = {"-o", "--output"}, description = "The directory to write the generated code to. Default is ~/endpoints-output")
private Path outputDir = Paths.get(System.getProperty("user.dir"), "endpoints-output");
- @Option(names = {"-v", "--verbose"}, description = "Print verbose debug messages.")
+ @SuppressWarnings("unused")
+ @Option(names = {"-v", "--verbose"}, description = "Print verbose debug messages.")
private Boolean verbose = false;
public static void main(String[] args) {
@@ -60,13 +64,13 @@ public class EndpointsCLI implements Callable {
}
}
- private void validateTemplateDirectory() throws IOException {
+ private void validateTemplateDirectory() {
if (!Files.isDirectory(this.templateDir)) {
throw new IllegalArgumentException("Template directory '" + this.templateDir + "' is not a directory.");
}
}
- private void validateInputFile() throws IOException {
+ private void validateInputFile() {
if (Files.notExists(this.file)) {
throw new IllegalArgumentException("Input file '" + this.file + "' does not exist.");
}