Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
Alternate version of Literal String Comparison quickfix, with types. See
//make sure resolveBindings() returns true in the Resolution class
public boolean visit(MethodInvocation node) {
if (this.lscMethodInvocation != null) {
return false;
// for checking the type of the receiver. Although it is tempting to try
// node.resolveTypeBinding(), that refers to the return value.
ITypeBinding typeBinding = node.getExpression().resolveTypeBinding();
if (comparisonMethods.contains(node.getName().getIdentifier()) && //check the method name
"java.lang.String".equals(typeBinding.getQualifiedName())) {
List<Expression> arguments = (List<Expression>) node.arguments();
if (arguments.size() == 1) { // I doubt this could be anything other than 1
// if this was a constant string, resolveConstantExpressionValue() will be nonnull
Expression argument = arguments.get(0);
if (argument.resolveConstantExpressionValue() != null) {
this.lscMethodInvocation = node;
this.stringLiteralExpression = argument;
this.stringVariableExpression = node.getExpression();
return false;
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment