Skip to content

Commit

Permalink
Generate Value Types when on Valhalla (#249)
Browse files Browse the repository at this point in the history
* generate value types

* Format, remove unused method

---------

Co-authored-by: Rob Bygrave <robin.bygrave@gmail.com>
  • Loading branch information
SentryMan and rbygrave authored Aug 5, 2024
1 parent f2a585f commit c2da73e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ 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<String> entries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -62,14 +56,14 @@ private void writePackage() {

private void writeClassStart() {
writer
.append(
"""
@Generated("avaje-validator-generator")
@Named
@%s
public final class %s implements MethodAdapterProvider {""",
Util.shortName(diAnnotation()), 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}

}

0 comments on commit c2da73e

Please sign in to comment.