Search code examples
javaeclipseidejava-bytecode-asm

In Java, how detect source where int value was set to long variable


In Java, is there any tools(IDE or library) can detect(search/grep) that an int value was set to a long variable?

Sample code:

    public static void main(String[] args) {

        int intValue = Integer.MIN_VALUE;
        long longValue = Long.MIN_VALUE;

        // No compile error, How can I know all these codes in my project?
        longValue = intValue; 

    }

Thanks for any advices


Solution

  • Looking at this video, I managed to figure it out:

    In IntelliJ, go to:

    Edit -> Find -> Search Structurally...

    Hit Existing Templates, then chose assignments under expressions

    That'll give you $Inst$ = $Expr$ in your Search template box. Now hit Edit variables..., and make Inst's Expression Type to be long, and Expr's to be int.

    Search within your current file and you'll see it pull up all such assignments. Go on to convert it into an inspection profile as the video describes. Hope this helps.