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
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.