From 7f33762a917e12fee20990acb44f5552e11f6a54 Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:43:32 -0400 Subject: [PATCH 1/2] generate value types --- .../validation/generator/SimpleAdapterWriter.java | 2 +- .../validation/generator/SimpleComponentWriter.java | 5 ++++- .../validation/generator/SimpleParamBeanWriter.java | 4 ++-- .../main/java/io/avaje/validation/generator/Util.java | 10 ++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleAdapterWriter.java b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleAdapterWriter.java index c9b114ec..a898d23b 100644 --- a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleAdapterWriter.java +++ b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleAdapterWriter.java @@ -92,7 +92,7 @@ private void writeClassStart() { writer.append("@ConstraintAdapter(%s.class)", beanReader.contraintTarget()).eol(); } - writer.append("public final class %sValidationAdapter implements ValidationAdapter<%s> ", adapterShortName, beanReader.shortName()); + writer.append("public final %sclass %sValidationAdapter implements ValidationAdapter<%s> ", Util.valhalla(), adapterShortName, beanReader.shortName()); writer.append("{").eol().eol(); } diff --git a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java index 14e380e2..27c86ac5 100644 --- a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java +++ b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java @@ -117,7 +117,10 @@ private void writeClassStart() { writeMetaDataEntry(all); writer.append("})").eol(); - writer.append("public class %s implements GeneratedComponent {", shortName).eol().eol(); + writer + .append("public %sclass %s implements GeneratedComponent {", Util.valhalla(), shortName) + .eol() + .eol(); } private void writeMetaDataEntry(List entries) { diff --git a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java index 6a5f628f..4cfacfab 100644 --- a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java +++ b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java @@ -67,8 +67,8 @@ private void writeClassStart() { @Generated("avaje-validator-generator") @Named @%s - public final class %s implements MethodAdapterProvider {""", - Util.shortName(diAnnotation()), adapterShortName) + public final %sclass %s implements MethodAdapterProvider {""", + Util.shortName(diAnnotation()), Util.valhalla(), adapterShortName) .eol(); } diff --git a/validator-generator/src/main/java/io/avaje/validation/generator/Util.java b/validator-generator/src/main/java/io/avaje/validation/generator/Util.java index c93262a2..22208488 100644 --- a/validator-generator/src/main/java/io/avaje/validation/generator/Util.java +++ b/validator-generator/src/main/java/io/avaje/validation/generator/Util.java @@ -158,4 +158,14 @@ static boolean isPublic(Element element) { } return !ProcessingContext.isImported(element); } + + static String valhalla() { + try { + if (Modifier.valueOf("VALUE") != null && APContext.previewEnabled()) return "value "; + } catch (IllegalArgumentException e) { + // no valhalla + } + return ""; + } + } From d47a7de24a0c78c0e3d48da7c7491b24f6fb547f Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Mon, 5 Aug 2024 22:54:41 +1200 Subject: [PATCH 2/2] Format, remove unused method --- .../generator/SimpleComponentWriter.java | 5 +-- .../generator/SimpleParamBeanWriter.java | 36 ++++++++----------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java index 27c86ac5..b167c3fd 100644 --- a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java +++ b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleComponentWriter.java @@ -117,10 +117,7 @@ private void writeClassStart() { writeMetaDataEntry(all); writer.append("})").eol(); - writer - .append("public %sclass %s implements GeneratedComponent {", Util.valhalla(), shortName) - .eol() - .eol(); + writer.append("public %sclass %s implements GeneratedComponent {", Util.valhalla(), shortName).eol().eol(); } private void writeMetaDataEntry(List entries) { diff --git a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java index 4cfacfab..966cc8e5 100644 --- a/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java +++ b/validator-generator/src/main/java/io/avaje/validation/generator/SimpleParamBeanWriter.java @@ -19,24 +19,18 @@ final class SimpleParamBeanWriter { SimpleParamBeanWriter(ValidMethodReader beanReader) { this.beanReader = beanReader; final var method = beanReader.getBeanType(); - this.adapterPackage = ProcessorUtils.packageOf(method.getEnclosingElement().asType().toString()); - adapterFullName = - adapterPackage - + "." - + method - .getSimpleName() - .toString() - .transform(str -> str.substring(0, 1).toUpperCase() + str.substring(1)) - + "ParamProvider"; + this.adapterFullName = adapterPackage + + "." + + method + .getSimpleName() + .toString() + .transform(str -> str.substring(0, 1).toUpperCase() + str.substring(1)) + + "ParamProvider"; this.adapterShortName = Util.shortName(adapterFullName); } - String fullName() { - return adapterFullName; - } - private Writer createFileWriter() throws IOException { final JavaFileObject jfo = createSourceFile(adapterFullName); return jfo.openWriter(); @@ -62,14 +56,14 @@ private void writePackage() { private void writeClassStart() { writer - .append( - """ - @Generated("avaje-validator-generator") - @Named - @%s - public final %sclass %s implements MethodAdapterProvider {""", - Util.shortName(diAnnotation()), Util.valhalla(), adapterShortName) - .eol(); + .append( + """ + @Generated("avaje-validator-generator") + @Named + @%s + public final %sclass %s implements MethodAdapterProvider {""", + Util.shortName(diAnnotation()), Util.valhalla(), adapterShortName) + .eol(); } private void writeMethods() {