Fix intelliij inspection warnings

This commit is contained in:
Johan Maasing 2025-04-09 20:03:18 +02:00
parent 2558a52b42
commit 6c8f9f66a6
3 changed files with 15 additions and 14 deletions

View file

@ -5,7 +5,6 @@ import nu.zoom.dsl.parser.EndpointsParser;
import org.antlr.v4.runtime.tree.TerminalNode; import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public class EndpointsVisitorTransformer extends EndpointsBaseVisitor<EndpointsParser.DocumentContext> { public class EndpointsVisitorTransformer extends EndpointsBaseVisitor<EndpointsParser.DocumentContext> {
private final ArrayList<EndpointNode> endpoints = new ArrayList<>(); private final ArrayList<EndpointNode> endpoints = new ArrayList<>();
@ -71,7 +70,7 @@ public class EndpointsVisitorTransformer extends EndpointsBaseVisitor<EndpointsP
requestTypeName = requestBodyContext.IDENTIFIER().getText() ; requestTypeName = requestBodyContext.IDENTIFIER().getText() ;
} }
if (requestTypeName == null) { if (requestTypeName == null) {
throw new ParseException("Unable to create the request body data type for " + segments.stream().collect(Collectors.joining())) ; throw new ParseException("Unable to create the request body data type for " + String.join("", segments)) ;
} }
var endpoint = new EndpointNode(new PathsNode(segments), requestTypeName); var endpoint = new EndpointNode(new PathsNode(segments), requestTypeName);
this.endpoints.add(endpoint); this.endpoints.add(endpoint);
@ -101,7 +100,7 @@ public class EndpointsVisitorTransformer extends EndpointsBaseVisitor<EndpointsP
} }
private void addDatatType(TypeNode type, int lineNumber) throws ParseException { private void addDatatType(TypeNode type, int lineNumber) throws ParseException {
if (this.dataTypes.stream().filter(t -> t.name().equals(type.name())).findAny().isPresent()) { if (this.dataTypes.stream().anyMatch(t -> t.name().equals(type.name()))) {
throw new ParseException("Duplicate datatype '" + type.name()+ "' at line " + lineNumber) ; throw new ParseException("Duplicate datatype '" + type.name()+ "' at line " + lineNumber) ;
} else { } else {
this.dataTypes.add(type); this.dataTypes.add(type);

View file

@ -1,7 +1,6 @@
package nu.zoom.dsl.ast; package nu.zoom.dsl.ast;
import java.util.List; import java.util.List;
import java.util.Optional;
public record TypeNode(String name, List<FieldNode> fields) { public record TypeNode(String name, List<FieldNode> fields) {
} }

View file

@ -13,6 +13,7 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Stream;
public class Generator { public class Generator {
private final Path templatesDir ; private final Path templatesDir ;
@ -34,7 +35,8 @@ public class Generator {
} }
public List<Path> generate() throws IOException, TemplateException { public List<Path> generate() throws IOException, TemplateException {
List<Path> templates = Files.list(templatesDir).filter(p -> p.toString().endsWith(".ftl")).toList() ; try (Stream<Path> files = Files.list(templatesDir)) {
List<Path> templates = files.filter(p -> p.toString().endsWith(".ftl")).toList() ;
ArrayList<Path> out = new ArrayList<>(); ArrayList<Path> out = new ArrayList<>();
for (Path template : templates) { for (Path template : templates) {
// TODO file ending // TODO file ending
@ -47,6 +49,7 @@ public class Generator {
} }
return out ; return out ;
} }
}
private String outputFilenameFromTemplate(Path template) { private String outputFilenameFromTemplate(Path template) {
return template.getFileName().toString().replace(".ftl", ".scala"); return template.getFileName().toString().replace(".ftl", ".scala");