javachecker-framework

Extract @Nullable/@NonNull annotations of given method handle


I am playing around with the CheckerFramework and wanted to extract the effective @Nullable/@NonNull annotations of the return value and parameters of a method, e.g. some.package.Thing: Object compute(Object,Collection). The only way I found so far, is to generate source code that uses this method in different nullness contexts, so that I can infer the annotations from the checker results. But I am pretty sure that there is a way to extend the NullnessChecker, so that I can give it a method handle (obtained through reflection) of method on the classpath and export the effective nullness annotations. Can anybody give me some hints on where to start?


Solution

  • As background, the Checker Framework lets you write annotations on types, such as List<@NonNull String>, but it also applies defaulting and inference.

    The final type annotation is written to the class file. Therefore, you can use tools that read the class file.