Skip to content

Commit

Permalink
Add ability to register all public methods for query in native
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkak committed Jan 14, 2025
1 parent 71646fd commit e6537af
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class ReflectiveClassBuildItem extends MultiBuildItem {
private final List<String> className;
private final boolean methods;
private final boolean queryMethods;
private final boolean queryPublicMethods;
private final boolean fields;
private final boolean classes;
private final boolean constructors;
Expand Down Expand Up @@ -47,7 +48,7 @@ public static Builder builder(String... classNames) {
private ReflectiveClassBuildItem(boolean constructors, boolean queryConstructors, boolean methods, boolean queryMethods,
boolean fields, boolean getClasses, boolean weak, boolean serialization, boolean unsafeAllocated, String reason,
Class<?>... classes) {
this(constructors, false, queryConstructors, methods, queryMethods, fields, getClasses, weak, serialization,
this(constructors, false, queryConstructors, methods, queryMethods, false, fields, getClasses, weak, serialization,
unsafeAllocated, reason, stream(classes).map(Class::getName).toArray(String[]::new));
}

Expand Down Expand Up @@ -119,12 +120,13 @@ public static ReflectiveClassBuildItem serializationClass(String... classNames)
ReflectiveClassBuildItem(boolean constructors, boolean queryConstructors, boolean methods, boolean queryMethods,
boolean fields, boolean weak, boolean serialization,
boolean unsafeAllocated, String... className) {
this(constructors, false, queryConstructors, methods, queryMethods, fields, false, weak, serialization, unsafeAllocated,
this(constructors, false, queryConstructors, methods, queryMethods, false, fields, false, weak, serialization,
unsafeAllocated,
null, className);
}

ReflectiveClassBuildItem(boolean constructors, boolean publicConstructors, boolean queryConstructors, boolean methods,
boolean queryMethods,
boolean queryMethods, boolean queryPublicMethods,
boolean fields, boolean classes, boolean weak, boolean serialization,
boolean unsafeAllocated, String reason, String... className) {
for (String i : className) {
Expand All @@ -142,6 +144,7 @@ public static ReflectiveClassBuildItem serializationClass(String... classNames)
} else {
this.queryMethods = queryMethods;
}
this.queryPublicMethods = queryPublicMethods;
this.fields = fields;
this.classes = classes;
this.constructors = constructors;
Expand Down Expand Up @@ -172,6 +175,10 @@ public boolean isQueryMethods() {
return queryMethods;
}

public boolean isQueryPublicMethods() {
return queryPublicMethods;
}

public boolean isFields() {
return fields;
}
Expand Down Expand Up @@ -224,6 +231,7 @@ public static class Builder {
private boolean queryConstructors;
private boolean methods;
private boolean queryMethods;
private boolean queryPublicMethods;
private boolean fields;
private boolean classes;
private boolean weak;
Expand Down Expand Up @@ -305,6 +313,20 @@ public Builder queryMethods() {
return queryMethods(true);
}

/**
* Configures whether all public methods should be registered for reflection, for query purposes only,
* i.e. {@link Class#getMethods()}. Setting this enables getting all public methods (including ones defined in
* superclasses) for the class but does not allow invoking them reflectively.
*/
public Builder queryPublicMethods(boolean queryPublicMethods) {
this.queryPublicMethods = queryPublicMethods;
return this;
}

public Builder queryPublicMethods() {
return queryPublicMethods(true);
}

/**
* Configures whether fields should be registered for reflection.
* Setting this enables getting all declared fields for the class as well as accessing them reflectively.
Expand Down Expand Up @@ -380,7 +402,7 @@ public Builder unsafeAllocated() {

public ReflectiveClassBuildItem build() {
return new ReflectiveClassBuildItem(constructors, publicConstructors, queryConstructors, methods, queryMethods,
fields, classes, weak,
queryPublicMethods, fields, classes, weak,
serialization, unsafeAllocated, reason, className);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ void generateReflectConfig(BuildProducer<GeneratedResourceBuildItem> reflectConf
extractToJsonArray(info.queriedMethodSet, queriedMethodsArray);
}
}
if (info.queryPublicMethods) {
json.put("queryAllPublicMethods", true);
}
if (!methodsArray.isEmpty()) {
json.put("methods", methodsArray);
}
Expand Down Expand Up @@ -253,6 +256,7 @@ static final class ReflectionInfo {
boolean queryConstructors;
boolean methods;
boolean queryMethods;
boolean queryPublicMethods;
boolean fields;
boolean classes;
boolean serialization;
Expand All @@ -270,6 +274,7 @@ private ReflectionInfo() {
private ReflectionInfo(ReflectiveClassBuildItem classBuildItem, String typeReachable) {
this.methods = classBuildItem.isMethods();
this.queryMethods = classBuildItem.isQueryMethods();
this.queryPublicMethods = classBuildItem.isQueryPublicMethods();
this.fields = classBuildItem.isFields();
this.classes = classBuildItem.isClasses();
this.typeReachable = typeReachable;
Expand Down

0 comments on commit e6537af

Please sign in to comment.