-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename of accessor method improperly renames property-style accesses #678
Comments
During a rename refactor, there is a tricky balance set up between Property-style accesses that resolve to a source method must not be seen as field accesses to prevent being renamed with the field. This is accomplished here in public VisitStatus acceptASTNode(ASTNode node, TypeLookupResult result, IJavaElement enclosingElement) {
...
} else if (node instanceof ConstantExpression) {
if (fieldName.equals(((ConstantExpression) node).getText())) {
if (result.declaration instanceof FieldNode || result.declaration instanceof PropertyNode) {
doCheck = true;
isAssignment = EqualityVisitor.checkForAssignment(node, result.enclosingAssignment);
start = node.getStart();
end = node.getEnd();
// check for "foo.bar" where "bar" refers to synthetic "getBar()", "isBar()" or "setBar(...)"
} else if (result.declaration instanceof MethodNode && result.declaration.getEnd() < 1) {
doCheck = true;
isAssignment = ((MethodNode) result.declaration).getName().startsWith("set");
start = node.getStart();
end = node.getEnd();
}
} These same accesses must not be seen as method references by public VisitStatus acceptASTNode(ASTNode node, TypeLookupResult result, IJavaElement enclosingElement) {
...
if (result.declaration instanceof MethodNode && ((MethodNode) result.declaration).getName().equals(methodName)) {
if (isDeclaration || node instanceof StaticMethodCallExpression) {
start = ((AnnotatedNode) node).getNameStart();
end = ((AnnotatedNode) node).getNameEnd() + 1;
// check for non-synthetic match; SyntheticAccessorSearchRequestor matches "foo.bar" to "getBar()" w/o backing field
} else if (node.getText().equals(methodName) || isNotSynthetic(node.getText(), result.declaringType)) {
start = node.getStart();
end = node.getEnd();
}
} However, when renaming an accessor, the property-style access needs to be seen by The check for method reference in |
See #489 (comment) for more info on method references in call hierarchy. Not all the same participants are invoked and so search for references, rename refactoring, find occurrences and call hierarchy can be difficult to get working all at the same time. |
- renaming only field will not rename pseudo-property accesses (aka calls to provided getter/setter/isser using the property style)
- SyntheticAccesorsRenameParticipant will need to find these references - Finding them with field search of SyntheticAccessorsSearchRequestor is causing extra references and unwanted renames of actual field references
Ready to test |
Ready to test |
This works for me in 3.1.0.xx-201808191927-e47 in the example I was testing 👍 |
Consider the following:
Rename of accessor
getFoo
improperly replacesi = a.foo
withi = a.getNewName
. Same goes for rename ofsetFoo
(and probablyisFoo
if one existed).Originally seen as part of #672
The text was updated successfully, but these errors were encountered: