Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Value Types when on Valhalla #249

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "";
}

}
Loading