In one of my Android projects (but not necessarily tied to Android) I have quite a few method calls that really do nothing but blow up the code and could be automatically removed. Examples:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
@Override
public void onDestroy() {
super.onDestroy();
}
I couldn't find any inspections that help me in automatically removing these expressions, so I tried structural search. My attempt so far: I copied the template of 'annotated methods' and made 2 small changes.
- $Annotation$ changed to occurs=1, text=Override
- Added a $Statement$ variable with occurs=1
The template code:
class $Class$ {
@$Annotation$( )
$MethodType$ $MethodName$($ParameterType$ $ParameterName$) {
$Statement$;
}
}
So far, so good - it's only finding methods with a single line in the body. But now I want to explicitely search for exact statements calling the super method (kind of like a back reference to $MethodName$), but which also return the super value (when not void). Any ideas?
I believe this would be a really useful inspection that could be integrated into the main IntelliJ codebase as well. :-)