-
Notifications
You must be signed in to change notification settings - Fork 571
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
Improve move to struct initialization inspection. Fix pull request from wbars #2822
base: master
Are you sure you want to change the base?
Conversation
Replace single struct declaration with short var declaration, or add to existing struct literal in statement
This PR created from an old commit :( Last commit |
What the state of the PR? cc: @grenki |
@zolotov PR ready merge. Tests are ok |
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.
seems unsupportable. refactoring is required
PsiElement resolve = fieldReferenceExpression.resolve(); | ||
return literalValue != null && isFieldDefinition(resolve) && | ||
!exists(literalValue.getElementList(), element -> isFieldInitialization(element, resolve)); | ||
if (resolve == null || !PsiTreeUtil.isAncestor(type, resolve, true)) return false; |
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's unclear why if the field is a descendant of some type
then the field reference is uninitialized. Where is the link?
GoLiteralValue literalValue = data.getCompositeLit().getLiteralValue(); | ||
private static void moveFieldReferenceExpressions(@NotNull List<GoReferenceExpression> referenceExpressions, | ||
@Nullable GoLiteralValue literalValue, | ||
@NotNull GoAssignmentStatement parentAssignment) { |
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.
what's the difference between assigment
parameter which is used in almost all methods and parentAssignment
} | ||
|
||
private static void moveFieldReferenceExpressions(@NotNull Data data) { | ||
GoLiteralValue literalValue = data.getCompositeLit().getLiteralValue(); | ||
private static void moveFieldReferenceExpressions(@NotNull List<GoReferenceExpression> referenceExpressions, |
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.
what's happened with DTO here? Any reason to pass 3 parameters here?
@@ -60,12 +60,34 @@ public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull Psi | |||
private static Data getData(@NotNull PsiElement element) { |
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.
getData method became overcomplicated. In my opinion, such methods should look like this:
val data
data.somePieceOfData1 = gatherSomePieceOfData_1()
data.somePieceOfData2 = gatherSomePieceOfData_2()
data.somePieceOfData3 = gatherSomePieceOfData_3()
return data
For now it looks like endless if, if, != null, return null
. It's barely readable and hard to edit.
No description provided.