In one of my Android projects (but not necessarily bound to Android), I have quite a few method calls that really do nothing but explode the code and can be automatically deleted. 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 could not find any checks that would help me automatically remove these expressions, so I tried a structural search. My attempt so far: I copied the "annotated methods" template and made 2 small changes.
- $ Annotations $ changed to happens = 1, text = Override
- Added $ Statement $ with with = 1 variable
Template Code:
class $Class$ { @$Annotation$( ) $MethodType$ $MethodName$($ParameterType$ $ParameterName$) { $Statement$; } }
So far so good - he only found methods with one line in the body. But now I want to explicitly look for exact operators that call the super method (like a back reference to $ MethodName $), but which also return a super value (if not empty). Any ideas?
I believe that this will be a really useful inspection, which can also be integrated into the IntelliJ core code base. :-)
java android intellij-idea android-studio structural-search
mreichelt
source share