Fix intelliij inspection warnings
This commit is contained in:
parent
2558a52b42
commit
6c8f9f66a6
3 changed files with 15 additions and 14 deletions
|
@ -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);
|
||||||
|
|
|
@ -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) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,18 +35,20 @@ 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)) {
|
||||||
ArrayList<Path> out = new ArrayList<>();
|
List<Path> templates = files.filter(p -> p.toString().endsWith(".ftl")).toList() ;
|
||||||
for (Path template : templates) {
|
ArrayList<Path> out = new ArrayList<>();
|
||||||
// TODO file ending
|
for (Path template : templates) {
|
||||||
Path outpath = outputDir.resolve(outputFilenameFromTemplate(template.getFileName()));
|
// TODO file ending
|
||||||
Template ftl = this.cfg.getTemplate(template.getFileName().toString()) ;
|
Path outpath = outputDir.resolve(outputFilenameFromTemplate(template.getFileName()));
|
||||||
try (var outw = Files.newBufferedWriter(outpath, StandardCharsets.UTF_8)) {
|
Template ftl = this.cfg.getTemplate(template.getFileName().toString()) ;
|
||||||
ftl.process(this.data, outw);
|
try (var outw = Files.newBufferedWriter(outpath, StandardCharsets.UTF_8)) {
|
||||||
out.add(outpath);
|
ftl.process(this.data, outw);
|
||||||
|
out.add(outpath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return out ;
|
||||||
}
|
}
|
||||||
return out ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String outputFilenameFromTemplate(Path template) {
|
private String outputFilenameFromTemplate(Path template) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue