New Tippers- from IntelliJ
- Remove redundant continue in default branch of switch.
for (final ASTNode $ : ancestors.of(¢))
switch ($.getNodeType()) {
case ASTNode.BLOCK:
return $;
default:
continue;
}
- Redundant return in switch branches when switch is last in method.
protected final void apply(final Tipper<?> w, final ASTNode n) {
tipper = w;
switch (type) {
case DECLARATION:
applyDeclaration(w, n);
return;
case FILE:
applyFile(w, n);
return;
default:
return;
}
}
- Redundant return - in try...catch now.
void simple() {
try (FileReader r = new FileReader(toString())) {
r.read();
} catch (final FileNotFoundException x) {
@foreign("r") final int a1 = hashCode() * hashCode() * x.hashCode();
f(a1 * a1 * a1);
return;
} catch (final IOException x) {
@knows({ "a2", "x" }) @foreign("r") final int a2 = hashCode() * hashCode();
f(a2 * x.hashCode());
@knows({ "a2", "x" }) final int r = hashCode();
f(r * a2 * a2 + r);
return;
} finally {
@foreign("r") final int a = hashCode() * hashCode();
@knows("a") final int r = hashCode();
f(a * a * r + r);
}
}
-
boolean method is always inverted - can invert method return value and un-invert all inversions in invocations.
-
redundant local variable (can be inlined):
final String peeled = unpeeled;
if (peeled.equals(get()))
azzert.that("No trimming of " + get(), peeled, is(not(get())));
assertSimilar($, peeled);
(no need for the peeled, why not use unpeeled?)
-
Actual method parameter is the same constant (parameter can be eliminated and uses will be replaced with the constant.
-
Declaration access can be weaker (private, protected,...)
-
Declaration can have final modifier (think eclipse can do this).
-
Method declares it throws 2 exceptions, one inherits from the other (can be replaced with single exception):
private int apply(final WrappedCompilationUnit u) throws JavaModelException, CoreException {
(JavaModelException inherits CoreException).
- Empty methods (or such that just delegate to super) (Can be eliminated).
@Override public void createSelectionListener() {
super.createSelectionListener();
}
-
Method can be void.
-
Redundant throw clause:
This inspection reports exceptions that are declared in a method's signature but never thrown by the method itself or its implementations/derivatives.
- Unused declaration:
This inspection reports classes, methods or fields in the specified inspection scope that are not used or not reachable from entry points. In editor, it also detects local variables that are declared but not used as well as private members that are never accessed for reading or not initialized in a class.
- Unused method parameters:
This inspection reports parameters that are not used by their methods and all method implementations/overriders.
- Long literal ending with 'l' instead of 'L'
Reports long literals ending with lowercase 'l'. These literals may be confusing, as lowercase 'l' looks very similar to '1'.
- Pointless arithmetic expression:
Reports pointless arithmetic expressions. Such expressions include adding or subtracting zero, multiplying by zero or one and division by one. Such expressions may be the result of automated refactorings not completely followed through to completion, and in any case are unlikely to be what the developer intended to do.
- Redundant type cast:
@Test public void a() {
auxInt(enumerate.expressions((ASTNode) null));
}
and one that needs type binding and hierarchy:
@Override public boolean visit(final SimpleName $) {
final String name = ((Name) $).getFullyQualifiedName();
...
}
- Redundant array creation:
This inspection reports unnecessary creation of array expression to be passed as an argument to varargs parameter.
static boolean containsOperator(final ASTNode ¢) {
return iz.nodeTypeIn(¢, new int[] { ASTNode.INFIX_EXPRESSION, ASTNode.PREFIX_EXPRESSION, ASTNode.POSTFIX_EXPRESSION, ASTNode.ASSIGNMENT });
}
can just be:
static boolean containsOperator(final ASTNode ¢) {
return iz.nodeTypeIn(¢, ASTNode.INFIX_EXPRESSION, ASTNode.PREFIX_EXPRESSION, ASTNode.POSTFIX_EXPRESSION, ASTNode.ASSIGNMENT);
}
Amazing job!
Take note though that many of these are impossible without binding.