Improve move to struct initialization inspection. Fix pull request from wbars#2822
Improve move to struct initialization inspection. Fix pull request from wbars#2822ibrque wants to merge 3 commits into
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 |
zolotov
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.