Last active
August 29, 2015 14:07
-
-
Save kjlubick/2735ee7e640b407459ee to your computer and use it in GitHub Desktop.
Alternate version of Literal String Comparison quickfix, with types. See http://kjlubick.github.io/#/blog/post/3?building-your-first-eclipse-quick-fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//make sure resolveBindings() returns true in the Resolution class | |
@Override | |
@SuppressWarnings("unchecked") | |
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