@Override public Void visitBinary(BinaryTree binary, Void unused) { if (!COMPARISON_OPERATORS.contains(binary.getKind())) { return super.visitBinary(binary, null); } VisitorState subState = state.withPath(getCurrentPath()); Optional<Fixer> fixer = Optional.empty(); if (isNull(binary.getLeftOperand())) { fixer = getFixer(binary.getRightOperand(), subState); } if (isNull(binary.getRightOperand())) { fixer = getFixer(binary.getLeftOperand(), subState); } fixer .map(f -> describeMatch(binary, ProblemUsage.COMPARISON.fix(f, binary, subState))) .ifPresent(state::reportMatch); return super.visitBinary(binary, null); }
@Override public Void visitBinary(BinaryTree binaryTree, Void unused) { if (binaryTree.getKind() != Kind.NOT_EQUAL_TO && binaryTree.getKind() != Kind.EQUAL_TO) { return super.visitBinary(binaryTree, null); } if (matchesEitherWay(binaryTree, isParameter, (tree, s) -> matchesNull(tree))) { if (binaryTree.getKind() == Kind.NOT_EQUAL_TO) { makeAlwaysTrue(); } if (binaryTree.getKind() == Kind.EQUAL_TO) { makeAlwaysFalse(); } return null; } if (matchesEitherWay(binaryTree, THIS_CLASS, otherClass)) { matchedGetClass = true; String instanceOf = String.format( "%s instanceof %s", parameter.getSimpleName(), classSymbol.getSimpleName()); if (binaryTree.getKind() == Kind.EQUAL_TO) { fix.replace(binaryTree, instanceOf); } if (binaryTree.getKind() == Kind.NOT_EQUAL_TO) { fix.replace(binaryTree, String.format("!(%s)", instanceOf)); } } return super.visitBinary(binaryTree, null); }
@Override public Void visitBinary(BinaryTree node, Trees trees) { add(node, trees); return super.visitBinary(node, trees); }
@Override public Void visitBinary(BinaryTree binary, Void unused) { if (!COMPARISON_OPERATORS.contains(binary.getKind())) { return super.visitBinary(binary, null); } VisitorState subState = state.withPath(getCurrentPath()); Optional<Fixer> fixer = Optional.empty(); if (isNull(binary.getLeftOperand())) { fixer = getFixer(binary.getRightOperand(), subState); } if (isNull(binary.getRightOperand())) { fixer = getFixer(binary.getLeftOperand(), subState); } fixer .map(f -> describeMatch(binary, ProblemUsage.COMPARISON.fix(f, binary, subState))) .ifPresent(state::reportMatch); return super.visitBinary(binary, null); }
@Override public Void visitBinary(BinaryTree binaryTree, Void unused) { if (binaryTree.getKind() != Kind.NOT_EQUAL_TO && binaryTree.getKind() != Kind.EQUAL_TO) { return super.visitBinary(binaryTree, null); } if (matchesEitherWay(binaryTree, isParameter, (tree, s) -> matchesNull(tree))) { if (binaryTree.getKind() == Kind.NOT_EQUAL_TO) { makeAlwaysTrue(); } if (binaryTree.getKind() == Kind.EQUAL_TO) { makeAlwaysFalse(); } return null; } if (matchesEitherWay(binaryTree, THIS_CLASS, otherClass)) { matchedGetClass = true; String instanceOf = String.format( "%s instanceof %s", parameter.getSimpleName().toString(), classSymbol.getSimpleName().toString()); if (binaryTree.getKind() == Kind.EQUAL_TO) { fix.replace(binaryTree, instanceOf); } if (binaryTree.getKind() == Kind.NOT_EQUAL_TO) { fix.replace(binaryTree, String.format("!(%s)", instanceOf)); } } return super.visitBinary(binaryTree, null); }