If you only need to analyze simple methods that return constant values, such as the one in your example, then you can do this relatively easily through static analysis using ASM or similar bytecode tools.
For methods that match the structure of your example (i.e., only direct return constants), you just need to look for a pattern
LDC ??? ARETURN
And collect the constants loaded using LDC. That would be very simple.
If the methods can be more complex, for example, if they return the values assigned to the variables, then you will need to perform a flow analysis. This is much more, but ASM provides support.
If the methods you analyze return values other than simple constants, then it will be incredibly difficult / impossible to do with static analysis.
henry source share