NeoForge icon indicating copy to clipboard operation
NeoForge copied to clipboard

[1.21.8] Add Gradle task to validate calls to extensions methods over vanilla methods

Open XFactHD opened this issue 5 months ago • 1 comments

This PR adds a Gradle task which, given a list of "extension definitions", validates that calls to vanilla methods for which NeoForge provides an overload with more context are correctly replaced with calls to the extension methods.

The task takes as input the joined compiled JAR containing both vanilla and NeoForge code and a JSON file declaring the "extension definitions". An "extension definition" consists of an original descriptor (owning class, method name and method descriptor) of the vanilla method, a replacement descriptor of the extension method and optionally a list of exclusions for methods which are permitted to call the original method (the replacement method itself as well as super calls are automatically excluded). The task then walks all classes in the joined JAR, checks the existence of the original methods and their replacements, collects calls to methods which may be methods that were intended to be replaced and collects class inheritance information in order to filter the gathered method calls (the target methods may be called on a subclass of the target type in which case inheritance info needs to be used to connect these calls to the target's declared owner). The collected calls are then filtered for unrelated calls (i.e. calls to methods with the same name and descriptor but on types we don't care about) or permitted calls and the remaining calls are printed together with missing or invalid original methods and replacement methods.

I expect the Gradle side of this to have some issues as I frankly have no clue what I'm doing on that end. The "extension definition" JSON only contains a small set of entries for testing and needs to be filled with all known extensions before this can be merged.

XFactHD avatar Jul 30 '25 22:07 XFactHD

  • [ ] Publish PR to GitHub Packages