diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d7ad602..f8e37d6 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -11,8 +11,6 @@ jobs: strategy: matrix: version: - - 8 - - 11 - 17 - 21 distribution: diff --git a/pom.xml b/pom.xml index ec8e918..8b9ec5d 100755 --- a/pom.xml +++ b/pom.xml @@ -12,9 +12,9 @@ UTF-8 - 1.8 - 1.8 - 8 + 17 + 17 + 17 @@ -54,7 +54,7 @@ com.graphql-java graphql-java - 20.4 + 21.3 com.graphql-java-kickstart @@ -92,7 +92,7 @@ org.mockito mockito-junit-jupiter - 4.11.0 + 5.11.0 test diff --git a/src/integration-test/simple/pom.xml b/src/integration-test/simple/pom.xml index 9ad0a63..bd8512f 100755 --- a/src/integration-test/simple/pom.xml +++ b/src/integration-test/simple/pom.xml @@ -41,7 +41,7 @@ org.mockito mockito-junit-jupiter - 4.11.0 + 5.11.0 test diff --git a/src/main/java/com/github/alme/graphql/generator/GeneratorMojo.java b/src/main/java/com/github/alme/graphql/generator/GeneratorMojo.java index cb5b3b6..6a9d08f 100755 --- a/src/main/java/com/github/alme/graphql/generator/GeneratorMojo.java +++ b/src/main/java/com/github/alme/graphql/generator/GeneratorMojo.java @@ -1,7 +1,5 @@ package com.github.alme.graphql.generator; -import static java.lang.String.format; - import java.io.File; import java.util.Map; import java.util.Set; @@ -192,14 +190,14 @@ public void execute() throws MojoExecutionException { .importPackages(importPackages) .build(); - getLog().info(format("Current configuration: %s.", configuration)); + getLog().info("Current configuration: %s.".formatted(configuration)); GqlContext context = new GqlContext(getLog(), configuration.getScalars(), configuration.getAliases()); ReaderFactory readerFactory = new ReaderFactory(configuration.getSourceFiles(), getLog()); WriterFactory writerFactory = new WriterFactory(configuration.getOutputRoot()); new GqlReader(readerFactory).read(context, configuration); - getLog().debug(format("Current context: %s.", context)); + getLog().debug("Current context: %s.".formatted(context)); new GqlWriter(writerFactory).write(context, configuration); getLog().info("Generation is done."); diff --git a/src/main/java/com/github/alme/graphql/generator/dto/GqlSelection.java b/src/main/java/com/github/alme/graphql/generator/dto/GqlSelection.java index 1ab5e1c..f0102fa 100755 --- a/src/main/java/com/github/alme/graphql/generator/dto/GqlSelection.java +++ b/src/main/java/com/github/alme/graphql/generator/dto/GqlSelection.java @@ -1,9 +1,7 @@ package com.github.alme.graphql.generator.dto; -import static java.util.Collections.emptySet; import static java.util.stream.Collectors.toSet; -import java.util.Collections; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; @@ -29,11 +27,11 @@ public class GqlSelection { @Setter private String targetTypeName; public String getKey() { - return String.format("%s:%s:%s:%s", alias, field.getName(), field.getType(), fragmentTypeName); + return "%s:%s:%s:%s".formatted(alias, field.getName(), field.getType(), fragmentTypeName); } public static GqlSelection of(GqlField field, String alias, String fragmentTypeName) { - return new GqlSelection(field, alias, fragmentTypeName, emptySet()); + return new GqlSelection(field, alias, fragmentTypeName, Set.of()); } public static GqlSelection of(GqlField field, String alias, SelectionSet subset) { @@ -41,7 +39,7 @@ public static GqlSelection of(GqlField field, String alias, SelectionSet subset) } public static GqlSelection of(GqlField field, String alias) { - return new GqlSelection(field, alias, "", emptySet()); + return new GqlSelection(field, alias, "", Set.of()); } public static GqlSelection of(String typeName, SelectionSet subset) { @@ -49,7 +47,7 @@ public static GqlSelection of(String typeName, SelectionSet subset) { } private static Set getSubsets(SelectionSet subset) { - return Optional.ofNullable(subset).map(Collections::singleton).orElseGet(Collections::emptySet); + return Optional.ofNullable(subset).map(Set::of).orElseGet(Set::of); } public GqlSelection merge(GqlSelection that) { diff --git a/src/main/java/com/github/alme/graphql/generator/dto/GqlType.java b/src/main/java/com/github/alme/graphql/generator/dto/GqlType.java index 13a70b2..8b95daf 100755 --- a/src/main/java/com/github/alme/graphql/generator/dto/GqlType.java +++ b/src/main/java/com/github/alme/graphql/generator/dto/GqlType.java @@ -22,14 +22,14 @@ public enum Flag { GqlType nested; public static GqlType of(Type type, UnaryOperator naming) { - if (type instanceof NonNullType) { - return mandatory(of(((NonNullType) type).getType(), naming)); + if (type instanceof NonNullType nonnull) { + return mandatory(of(nonnull.getType(), naming)); } - else if (type instanceof ListType) { - return list(of(((ListType) type).getType(), naming)); + else if (type instanceof ListType list) { + return list(of(list.getType(), naming)); } - else if (type instanceof TypeName) { - return named(naming.apply(((TypeName) type).getName())); + else if (type instanceof TypeName named) { + return named(naming.apply(named.getName())); } return null; } @@ -58,39 +58,30 @@ public String getName() { * Used in templates */ public String getFull() { - switch (flag) { - case MANDATORY: - return nested.getFull(); - case LIST: - return String.format("java.util.List<%s>", nested.getFull()); - default: - return name; - } + return switch (flag) { + case MANDATORY -> nested.getFull(); + case LIST -> "java.util.List<%s>".formatted(nested.getFull()); + case NAMED -> name; + }; } /** * Used in templates */ public String getCustom(String customType) { - switch (flag) { - case MANDATORY: - return nested.getCustom(customType); - case LIST: - return String.format("java.util.List<%s>", nested.getCustom(customType)); - default: - return customType; - } + return switch (flag) { + case MANDATORY -> nested.getCustom(customType); + case LIST -> "java.util.List<%s>".formatted(nested.getCustom(customType)); + case NAMED -> customType; + }; } @Override public String toString() { - switch (flag) { - case MANDATORY: - return String.format("%s!", nested); - case LIST: - return String.format("[%s]", nested); - default: - return name; - } + return switch (flag) { + case MANDATORY -> "%s!".formatted(nested); + case LIST -> "[%s]".formatted(nested); + case NAMED -> name; + }; } } diff --git a/src/main/java/com/github/alme/graphql/generator/io/GqlReader.java b/src/main/java/com/github/alme/graphql/generator/io/GqlReader.java index 0124d0b..8f8bc12 100755 --- a/src/main/java/com/github/alme/graphql/generator/io/GqlReader.java +++ b/src/main/java/com/github/alme/graphql/generator/io/GqlReader.java @@ -1,7 +1,5 @@ package com.github.alme.graphql.generator.io; -import static java.lang.String.format; - import java.io.IOException; import java.io.Reader; @@ -41,36 +39,36 @@ public void read(GqlContext context, GqlConfiguration configuration) { .parserOptions(configuration.getParserOptions()) .build(); Document doc = Parser.parse(environment); - log.info(format(LOG_PARSER, doc.getDefinitions().size())); + log.info(LOG_PARSER.formatted(doc.getDefinitions().size())); new InputObjectTypeTranslator().translate(doc, context); - log.info(format(LOG_TRANSLATOR, context.getInputObjectTypes().size(), "Input Object type")); + log.info(LOG_TRANSLATOR.formatted(context.getInputObjectTypes().size(), "Input Object type")); new EnumTypeTranslator().translate(doc, context); - log.info(format(LOG_TRANSLATOR, context.getEnumTypes().size(), "Enum type")); + log.info(LOG_TRANSLATOR.formatted(context.getEnumTypes().size(), "Enum type")); new InterfaceTypeTranslator().translate(doc, context); new UnionTypeTranslator().translate(doc, context); - log.info(format(LOG_TRANSLATOR, context.getInterfaceTypes().size(), "Interface and union type")); + log.info(LOG_TRANSLATOR.formatted(context.getInterfaceTypes().size(), "Interface and union type")); new ObjectTypeTranslator().translate(doc, context); new RelayConnectionTranslator().translate(doc, context); - log.info(format(LOG_TRANSLATOR, context.getObjectTypes().size(), "Object type")); + log.info(LOG_TRANSLATOR.formatted(context.getObjectTypes().size(), "Object type")); boolean generateDefinedOperations = configuration.isGenerateDefinedOperations(); boolean generateDynamicOperations = configuration.isGenerateDynamicOperations(); if (generateDefinedOperations || generateDynamicOperations) { new SchemaTranslator().translate(doc, context); - log.info(format(LOG_TRANSLATOR, context.getOperations().size(), "Schema")); + log.info(LOG_TRANSLATOR.formatted(context.getOperations().size(), "Schema")); } if (generateDefinedOperations) { new OperationTranslator().translate(doc, context); - log.info(format(LOG_TRANSLATOR, context.getDefinedOperations().size(), "Defined operation")); + log.info(LOG_TRANSLATOR.formatted(context.getDefinedOperations().size(), "Defined operation")); } if (generateDynamicOperations) { new DynamicOperationTranslator().translate(doc, context); - log.info(format(LOG_TRANSLATOR, context.getDynamicOperations().size(), "Dynamic operation")); + log.info(LOG_TRANSLATOR.formatted(context.getDynamicOperations().size(), "Dynamic operation")); } } catch (IOException e) { diff --git a/src/main/java/com/github/alme/graphql/generator/io/GqlWriter.java b/src/main/java/com/github/alme/graphql/generator/io/GqlWriter.java index 25d4696..9467d4d 100755 --- a/src/main/java/com/github/alme/graphql/generator/io/GqlWriter.java +++ b/src/main/java/com/github/alme/graphql/generator/io/GqlWriter.java @@ -1,6 +1,5 @@ package com.github.alme.graphql.generator.io; -import static java.lang.String.format; import static java.util.Collections.singletonMap; import static java.util.stream.Collectors.groupingBy; @@ -25,7 +24,6 @@ import freemarker.template.Configuration; import freemarker.template.TemplateExceptionHandler; import freemarker.template.TemplateModelException; -import lombok.val; public class GqlWriter { @@ -106,33 +104,33 @@ private void createSchemaTypes(GqlContext context, GqlConfiguration configuratio String packageName = configuration.getSchemaTypesPackageName(); int count = 0; if (configuration.isGenerateSchemaInputTypes()) { - val inputObjectFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.INPUT_OBJECT); + var inputObjectFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.INPUT_OBJECT); context.getInputObjectTypes() .forEach((className, gqlStructure) -> inputObjectFileCreator .createFile(packageName, className, gqlStructure)); count += context.getInputObjectTypes().size(); } if (configuration.isGenerateSchemaInputTypes() || configuration.isGenerateSchemaOtherTypes()) { - val enumFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.ENUM); + var enumFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.ENUM); context.getEnumTypes() .forEach((className, gqlStructure) -> enumFileCreator .createFile(packageName, className, gqlStructure)); count += context.getEnumTypes().size(); } if (configuration.isGenerateSchemaOtherTypes()) { - val interfaceFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.INTERFACE); + var interfaceFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.INTERFACE); context.getInterfaceTypes() .forEach((className, gqlStructure) -> interfaceFileCreator .createFile(packageName, className, gqlStructure)); count += context.getInterfaceTypes().size(); - val objectFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.OBJECT); + var objectFileCreator = new StructureFileCreator(writerFactory, freemarker, Structure.OBJECT); context.getObjectTypes() .forEach((className, gqlStructure) -> objectFileCreator .createFile(packageName, className, gqlStructure)); count += context.getObjectTypes().size(); } if (count > 0) { - context.getLog().info(format("Finished creating %d schema type class(es).", count)); + context.getLog().info("Finished creating %d schema type class(es).".formatted(count)); } } @@ -140,7 +138,7 @@ private void createOperationInterfaces(GqlContext context, GqlConfiguration conf if ((configuration.isGenerateDefinedOperations() && !context.getDefinedOperations().isEmpty()) || (configuration.isGenerateDynamicOperations() && !context.getDynamicOperations().isEmpty()) ) { - val operationInterfaceFileCreator = new OperationInterfaceFileCreator(writerFactory, freemarker); + var operationInterfaceFileCreator = new OperationInterfaceFileCreator(writerFactory, freemarker); context.getOperations().keySet().stream() .map(Util::firstUpper) .forEach(interfaceName -> operationInterfaceFileCreator @@ -150,8 +148,8 @@ private void createOperationInterfaces(GqlContext context, GqlConfiguration conf private void createDefinedOperations(GqlContext context, GqlConfiguration configuration) { if (configuration.isGenerateDefinedOperations() && !context.getDefinedOperations().isEmpty()) { - val definedOperationFileCreator = new DefinedOperationFileCreator(writerFactory, freemarker); - val definedOperationVariablesFileCreator = new DefinedOperationVariablesFileCreator(writerFactory, freemarker); + var definedOperationFileCreator = new DefinedOperationFileCreator(writerFactory, freemarker); + var definedOperationVariablesFileCreator = new DefinedOperationVariablesFileCreator(writerFactory, freemarker); context.getDefinedOperations().forEach((operationName, operation) -> { String packageName = configuration.getDefinedOperationsPackageName() + "." + Util.firstLower(operationName); definedOperationFileCreator.createFile(packageName, operationName, operation); @@ -159,14 +157,14 @@ private void createDefinedOperations(GqlContext context, GqlConfiguration config definedOperationVariablesFileCreator.createFile(packageName, operationName + "Variables", operation); } }); - val definedOperationResultFileCreator = new DefinedOperationResultFileCreator(writerFactory, freemarker); + var definedOperationResultFileCreator = new DefinedOperationResultFileCreator(writerFactory, freemarker); context.getDefinedSelections().forEach((operationName, typeMap) -> { String packageName = configuration.getDefinedOperationsPackageName() + "." + Util.firstLower(operationName) + ".results"; typeMap.forEach((typeName, selections) -> definedOperationResultFileCreator .createFile(packageName, typeName, singletonMap("selections", selections))); }); context.getDefinedOperations().forEach((operationName, operation) -> - context.getLog().info(format("Finished creating %d class(es) for %s operation.", + context.getLog().info("Finished creating %d class(es) for %s operation.".formatted( (operation.getVariables().isEmpty() ? 1 : 2) + context.getDefinedSelections().get(operationName).size(), operationName))); } @@ -175,18 +173,18 @@ private void createDefinedOperations(GqlContext context, GqlConfiguration config private void createDynamicOperations(GqlContext context, GqlConfiguration configuration) { if (configuration.isGenerateDynamicOperations() && !context.getDynamicOperations().isEmpty()) { String packageName = configuration.getDynamicOperationsPackageName(); - val dynamicOperationFileCreator = new DynamicOperationFileCreator(writerFactory, freemarker); + var dynamicOperationFileCreator = new DynamicOperationFileCreator(writerFactory, freemarker); context.getDynamicOperations() .forEach((className, operation) -> dynamicOperationFileCreator.createFile(packageName, className, operation)); - val dynamicOperationResultFileCreator = new DynamicOperationResultFileCreator(writerFactory, freemarker); - val dynamicOperationSelectorFileCreator = new DynamicOperationSelectorFileCreator(writerFactory, freemarker); + var dynamicOperationResultFileCreator = new DynamicOperationResultFileCreator(writerFactory, freemarker); + var dynamicOperationSelectorFileCreator = new DynamicOperationSelectorFileCreator(writerFactory, freemarker); context.getDynamicSelections() .forEach((className, selections) -> { dynamicOperationResultFileCreator.createFile(packageName + ".results", className, singletonMap("selections", selections)); dynamicOperationSelectorFileCreator.createFile(packageName + ".selectors", className + "Selector", singletonMap("selections", selections.stream().collect(groupingBy(GqlSelection::getFragmentTypeName)))); }); - context.getLog().info(format("Finished creating %d dynamic operation(s) with %d common class(es).", + context.getLog().info("Finished creating %d dynamic operation(s) with %d common class(es).".formatted( context.getDynamicOperations().size(), context.getDynamicSelections().size() * 2)); } diff --git a/src/main/java/com/github/alme/graphql/generator/io/ReaderFactory.java b/src/main/java/com/github/alme/graphql/generator/io/ReaderFactory.java index 5cea3f3..d1eecc2 100644 --- a/src/main/java/com/github/alme/graphql/generator/io/ReaderFactory.java +++ b/src/main/java/com/github/alme/graphql/generator/io/ReaderFactory.java @@ -1,7 +1,5 @@ package com.github.alme.graphql.generator.io; -import static java.lang.String.format; - import java.io.IOException; import java.io.Reader; import java.nio.file.Files; @@ -13,7 +11,6 @@ import graphql.parser.MultiSourceReader; import lombok.RequiredArgsConstructor; -import lombok.Value; @RequiredArgsConstructor public class ReaderFactory { @@ -27,7 +24,7 @@ public Reader getReader() { try { return new FileInfo(Files.newBufferedReader(path), path.toString()); } catch (IOException e) { - log.error(format("Skipping [%s].", path), e); + log.error("Skipping [%s].".formatted(path), e); return null; } }) @@ -39,10 +36,6 @@ public Reader getReader() { .build(); } - @Value - private static class FileInfo { - Reader reader; - String path; - } + private record FileInfo(Reader reader, String path) { } } diff --git a/src/main/java/com/github/alme/graphql/generator/io/creator/FileCreator.java b/src/main/java/com/github/alme/graphql/generator/io/creator/FileCreator.java index 19cf9a8..61d1cb6 100644 --- a/src/main/java/com/github/alme/graphql/generator/io/creator/FileCreator.java +++ b/src/main/java/com/github/alme/graphql/generator/io/creator/FileCreator.java @@ -29,7 +29,7 @@ public void createFile(String packageName, String className, Object baseObject) freemarker.setSharedVariable(CURRENT_PACKAGE_KEY, packageName); freemarker.getTemplate(getTemplate()).process(baseObject, writer); } catch (TemplateException | IOException e) { - throw new MojoExecutionException(String.format(LOG_CANNOT_CREATE, packageName, className), e); + throw new MojoExecutionException(LOG_CANNOT_CREATE.formatted(packageName, className), e); } } diff --git a/src/main/java/com/github/alme/graphql/generator/io/translator/OperationTranslator.java b/src/main/java/com/github/alme/graphql/generator/io/translator/OperationTranslator.java index 0489cad..c61c1f8 100755 --- a/src/main/java/com/github/alme/graphql/generator/io/translator/OperationTranslator.java +++ b/src/main/java/com/github/alme/graphql/generator/io/translator/OperationTranslator.java @@ -9,7 +9,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; import java.util.Objects; @@ -40,7 +39,6 @@ import graphql.language.InlineFragment; import graphql.language.OperationDefinition; import graphql.language.SelectionSet; -import lombok.val; public class OperationTranslator implements Translator { @@ -107,14 +105,14 @@ private Map> traverseSelections( Queue selectionsToResolve = new LinkedList<>(); selectionsToResolve.offer(GqlSelection.of(typeName, subset)); while (!selectionsToResolve.isEmpty()) { - val currentSelection = selectionsToResolve.poll(); + var currentSelection = selectionsToResolve.poll(); String currentTypeName = currentSelection.getType().getName(); // get a set of selections by type name and their unresolved subset - val subSelections = currentSelection.getSubsets().stream() + var subSelections = currentSelection.getSubsets().stream() .flatMap(unresolved -> resolveOneLevel(unresolved, allFragments, requiredFragments, new HashSet<>(), ctx, currentTypeName).stream()) .collect(toSet()); // find exactly the same selection set already linked to this type - val variants = typeMap.computeIfAbsent(currentTypeName, x -> new HashMap<>()); + var variants = typeMap.computeIfAbsent(currentTypeName, x -> new HashMap<>()); int variantNumber = variants.entrySet().stream() .filter(entry -> entry.getValue().equals(subSelections)) .map(Map.Entry::getKey) @@ -216,7 +214,7 @@ private String getDocumentString(OperationDefinition operation, Collection aliasMapAlternative; private static final String KEY_VALUE_SEPARATOR = "="; - - private static final Map DEFAULT_ALIASES = new HashMap<>(); - static { - DEFAULT_ALIASES.put("abstract", "abstractValue"); - DEFAULT_ALIASES.put("assert", "assertValue"); - DEFAULT_ALIASES.put("boolean", "booleanValue"); - DEFAULT_ALIASES.put("break", "breakValue"); - DEFAULT_ALIASES.put("byte", "byteValue"); - DEFAULT_ALIASES.put("case", "caseValue"); - DEFAULT_ALIASES.put("catch", "catchValue"); - DEFAULT_ALIASES.put("char", "charValue"); - DEFAULT_ALIASES.put("class", "classValue"); - DEFAULT_ALIASES.put("const", "constValue"); - DEFAULT_ALIASES.put("continue", "continueValue"); - DEFAULT_ALIASES.put("default", "defaultValue"); - DEFAULT_ALIASES.put("do", "doValue"); - DEFAULT_ALIASES.put("double", "doubleValue"); - DEFAULT_ALIASES.put("else", "elseValue"); - DEFAULT_ALIASES.put("enum", "enumValue"); - DEFAULT_ALIASES.put("extends", "extendsValue"); - DEFAULT_ALIASES.put("final", "finalValue"); - DEFAULT_ALIASES.put("finally", "finallyValue"); - DEFAULT_ALIASES.put("float", "floatValue"); - DEFAULT_ALIASES.put("for", "forValue"); - DEFAULT_ALIASES.put("goto", "gotoValue"); - DEFAULT_ALIASES.put("if", "ifValue"); - DEFAULT_ALIASES.put("implements", "implementsValue"); - DEFAULT_ALIASES.put("import", "importValue"); - DEFAULT_ALIASES.put("instanceof", "instanceofValue"); - DEFAULT_ALIASES.put("int", "intValue"); - DEFAULT_ALIASES.put("interface", "interfaceValue"); - DEFAULT_ALIASES.put("long", "longValue"); - DEFAULT_ALIASES.put("native", "nativeValue"); - DEFAULT_ALIASES.put("new", "newValue"); - DEFAULT_ALIASES.put("package", "packageValue"); - DEFAULT_ALIASES.put("private", "privateValue"); - DEFAULT_ALIASES.put("protected", "protectedValue"); - DEFAULT_ALIASES.put("public", "publicValue"); - DEFAULT_ALIASES.put("return", "returnValue"); - DEFAULT_ALIASES.put("short", "shortValue"); - DEFAULT_ALIASES.put("static", "staticValue"); - DEFAULT_ALIASES.put("strictfp", "strictfpValue"); - DEFAULT_ALIASES.put("super", "superValue"); - DEFAULT_ALIASES.put("switch", "switchValue"); - DEFAULT_ALIASES.put("synchronized", "synchronizedValue"); - DEFAULT_ALIASES.put("this", "thisValue"); - DEFAULT_ALIASES.put("throw", "throwValue"); - DEFAULT_ALIASES.put("throws", "throwsValue"); - DEFAULT_ALIASES.put("transient", "transientValue"); - DEFAULT_ALIASES.put("try", "tryValue"); - DEFAULT_ALIASES.put("void", "voidValue"); - DEFAULT_ALIASES.put("volatile", "volatileValue"); - DEFAULT_ALIASES.put("while", "whileValue"); - DEFAULT_ALIASES.put("yield", "yieldValue"); - } + + private static final Map DEFAULT_ALIASES = Map.ofEntries( + Map.entry("abstract", "abstractValue"), + Map.entry("assert", "assertValue"), + Map.entry("boolean", "booleanValue"), + Map.entry("break", "breakValue"), + Map.entry("byte", "byteValue"), + Map.entry("case", "caseValue"), + Map.entry("catch", "catchValue"), + Map.entry("char", "charValue"), + Map.entry("class", "classValue"), + Map.entry("const", "constValue"), + Map.entry("continue", "continueValue"), + Map.entry("default", "defaultValue"), + Map.entry("do", "doValue"), + Map.entry("double", "doubleValue"), + Map.entry("else", "elseValue"), + Map.entry("enum", "enumValue"), + Map.entry("extends", "extendsValue"), + Map.entry("final", "finalValue"), + Map.entry("finally", "finallyValue"), + Map.entry("float", "floatValue"), + Map.entry("for", "forValue"), + Map.entry("goto", "gotoValue"), + Map.entry("if", "ifValue"), + Map.entry("implements", "implementsValue"), + Map.entry("import", "importValue"), + Map.entry("instanceof", "instanceofValue"), + Map.entry("int", "intValue"), + Map.entry("interface", "interfaceValue"), + Map.entry("long", "longValue"), + Map.entry("native", "nativeValue"), + Map.entry("new", "newValue"), + Map.entry("package", "packageValue"), + Map.entry("private", "privateValue"), + Map.entry("protected", "protectedValue"), + Map.entry("public", "publicValue"), + Map.entry("return", "returnValue"), + Map.entry("short", "shortValue"), + Map.entry("static", "staticValue"), + Map.entry("strictfp", "strictfpValue"), + Map.entry("super", "superValue"), + Map.entry("switch", "switchValue"), + Map.entry("synchronized", "synchronizedValue"), + Map.entry("this", "thisValue"), + Map.entry("throw", "throwValue"), + Map.entry("throws", "throwsValue"), + Map.entry("transient", "transientValue"), + Map.entry("try", "tryValue"), + Map.entry("void", "voidValue"), + Map.entry("volatile", "volatileValue"), + Map.entry("while", "whileValue"), + Map.entry("yield", "yieldValue") + ); @Override public void apply(GqlConfigurationBuilder builder) { @@ -79,14 +77,14 @@ public void apply(GqlConfigurationBuilder builder) { aliasMap.entrySet().stream() .filter(item -> item.getKey() != null && item.getValue() != null && - !item.getKey().trim().isEmpty() && !item.getValue().trim().isEmpty()) + !item.getKey().isBlank() && !item.getValue().isBlank()) .forEach(item -> builder.alias(item.getKey().trim(), item.getValue().trim())); } else if (aliasMapAlternative != null) { aliasMapAlternative.stream() .filter(Objects::nonNull) .map(item -> item.split(KEY_VALUE_SEPARATOR, 2)) - .filter(item -> (item.length == 2) && !item[0].trim().isEmpty() && !item[1].trim().isEmpty()) + .filter(item -> (item.length == 2) && !item[0].isBlank() && !item[1].isBlank()) .forEach(item -> builder.alias(item[0].trim(), item[1].trim())); } } diff --git a/src/main/java/com/github/alme/graphql/generator/parameters/GeneratedAnnotationParameterApplier.java b/src/main/java/com/github/alme/graphql/generator/parameters/GeneratedAnnotationParameterApplier.java index dbef534..69b5c62 100644 --- a/src/main/java/com/github/alme/graphql/generator/parameters/GeneratedAnnotationParameterApplier.java +++ b/src/main/java/com/github/alme/graphql/generator/parameters/GeneratedAnnotationParameterApplier.java @@ -1,7 +1,5 @@ package com.github.alme.graphql.generator.parameters; -import static java.lang.String.format; - import java.time.Instant; import com.github.alme.graphql.generator.GeneratorMojo; @@ -21,7 +19,7 @@ public class GeneratedAnnotationParameterApplier implements ParameterApplier { @Override public void apply(GqlConfiguration.GqlConfigurationBuilder builder) { if (generatedAnnotationVersion != null) { - builder.generatedAnnotation(format(TEMPLATE, + builder.generatedAnnotation(TEMPLATE.formatted( JAVA8.equals(generatedAnnotationVersion) ? "" : PROCESSING, GeneratorMojo.class.getName(), Instant.now() diff --git a/src/main/java/com/github/alme/graphql/generator/parameters/ScalarMapParameterApplier.java b/src/main/java/com/github/alme/graphql/generator/parameters/ScalarMapParameterApplier.java index 1ee4257..45f4333 100644 --- a/src/main/java/com/github/alme/graphql/generator/parameters/ScalarMapParameterApplier.java +++ b/src/main/java/com/github/alme/graphql/generator/parameters/ScalarMapParameterApplier.java @@ -17,12 +17,11 @@ public class ScalarMapParameterApplier implements ParameterApplier { private static final String KEY_VALUE_SEPARATOR = "="; - private static final Map DEFAULT_SCALARS = new HashMap<>(); - static { - DEFAULT_SCALARS.put("Int", "Integer"); - DEFAULT_SCALARS.put("Float", "Double"); - DEFAULT_SCALARS.put("ID", "String"); - } + private static final Map DEFAULT_SCALARS = Map.of( + "Int", "Integer", + "Float", "Double", + "ID", "String" + ); @Override public void apply(GqlConfigurationBuilder builder) { @@ -31,14 +30,14 @@ public void apply(GqlConfigurationBuilder builder) { scalarMap.entrySet().stream() .filter(item -> item.getKey() != null && item.getValue() != null && - !item.getKey().trim().isEmpty() && !item.getValue().trim().isEmpty()) + !item.getKey().isBlank() && !item.getValue().isBlank()) .forEach(item -> builder.scalar(item.getKey().trim(), item.getValue().trim())); } else if (scalarMapAlternative != null) { scalarMapAlternative.stream() .filter(Objects::nonNull) .map(item -> item.split(KEY_VALUE_SEPARATOR, 2)) - .filter(item -> (item.length == 2) && !item[0].trim().isEmpty() && !item[1].trim().isEmpty()) + .filter(item -> (item.length == 2) && !item[0].isBlank() && !item[1].isBlank()) .forEach(item -> builder.scalar(item[0].trim(), item[1].trim())); } }