-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add Transient annotation to private accessor methods #425
Conversation
src/main/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessor.java
Outdated
Show resolved
Hide resolved
*/ | ||
private boolean methodReturnsFieldFromClass(J.Return returnStatement) { | ||
J.ClassDeclaration classDecl = getCursor().dropParentUntil(parent -> parent instanceof J.ClassDeclaration).getValue(); | ||
JavaType.Variable returnedVar = ((J.Identifier)returnStatement.getExpression()).getFieldType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about matching on the field type here ; I'd expect we'd want to match that the identifier or accessed field name are the same as what's returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed like the Identifier sometimes had different object numbers when I was debugging, but getting it's FieldType object always matched up (which also contains the variable name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the return expression can be a lot of things, but I imagine we'd only want to add an annotation when it's exactly an identifier or field access that references a field in the surrounding class; I think that were we were headed already right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...est/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessorTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
src/main/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessor.java
Outdated
Show resolved
Hide resolved
...est/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessorTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
...est/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessorTest.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessor.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
void doNotChangePublicOrProtectedGetter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec and tests don't seem to mention package private
cases. Would we want to make explicit what we do with those in the tests? Right now it seems we only change private
cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since the spec doesn't mention it, it may be best to only stick with the explicit private
case.
if (expression instanceof J.FieldAccess) { | ||
return ((J.FieldAccess) expression).getName().getFieldType(); | ||
} else if (expression instanceof J.Identifier) { // ie: return field; | ||
return ((J.Identifier) expression).getFieldType(); | ||
} else { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a way we're iterating over returns twice; first as we visit each return, and then again to extract the returned field type; would it make sense to fold those into one by doing this extract in the visitor just above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, will update to do that. Also I noticed that I'm collecting the class variables in each method, so I'll extract that to a higher scope variable to be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved already, and you're welcome to merge as is; I just had two small suggestions that I'd like your thoughts on, but they are not a requirement to address before we merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @timtebeek for helping me review this. Thanks @evie-lau for making these updates.
What's changed?
OpenJPA -> EclipseLink recipe
Add
@Transient
annotation to private accessor methodsWhat's your motivation?
https://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/OpenJPA/Mappings#Private_Accessor_Methods
Anything in particular you'd like reviewers to focus on?
Question for this recipe, and maybe even all the other EclipseLink migration recipes...
Do all the JPA migration recipes require the class being tagged with
@Entity
or some JPA annotation? @cjobinaboChecklist