Skip to content

Instantly share code, notes, and snippets.

@h0tk3y
Last active March 2, 2023 11:15
Show Gist options
  • Save h0tk3y/1cf292029e110b2360c31a0e96994aad to your computer and use it in GitHub Desktop.
Save h0tk3y/1cf292029e110b2360c31a0e96994aad to your computer and use it in GitHub Desktop.
Gradle instrumentation tool codegen example for properties
class PropertiesExtension implements AnnotatedMethodReaderExtension, CodeGeneratorContributor {
@Override
public InstrumentationCodeGenerator contributeCodeGenerator() {
return new CodeGeneratorContributor() {
@Override
public InstrumentationCodeGenerator contributeCodeGenerator() {
// look for the extra data in the requests – find the ones that need accessor
// implementations, then generate them, like:
//
// class ChekstyleImpls {
// public static access_get_maxErrors(Checkstyle self) {
// self.getMaxErrors().get()
// }
//
// public static access_set_maxErrors(Checkstyle self, int value) {
// ...
// }
// }
}
}
}
@Override
public Collection<Result> readRequest(ExecutableElement input) {
// read the annotations
// produce the requests to intercept the property getter and setter (+ Groovy property access)
// the returned requests should reference non-existing methods as interceptor implementations
// like access_get_maxErrors and access_get_maxErrors
// and they also need to store the information that they need those methods to be generated
// (perhaps use the request extras)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment