Skip to content
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

clean up enum and comma in annotation #159

Conversation

valulucchesi
Copy link
Contributor

when there is more than one enum in the annotation and it's being separated by comma piranha is keeping an extra comma after the cleanup.

code to do the cleanup by STALE_FLAG as treated:
@ToggleTesting(treated = {TestExperimentName.STALE_FLAG, TestExperimentName.OTHER_FLAG})

current output:
@ToggleTesting(treated = {, TestExperimentName.OTHER_FLAG})

expected output
@ToggleTesting(treated = {TestExperimentName.OTHER_FLAG})

The enum to be removed could be at the beginning, in the middle or at the end. For the first two cases we should remove the comma that is present after the enum and for the third case we should remove the comma that is present before the enum.
For the scenario when there is only one enum we shouldn't do anything else that what the code is currently doing.

@CLAassistant
Copy link

CLAassistant commented Jan 6, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@ketkarameya ketkarameya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valulucchesi Thanks a lot for your contribution. Please find my comments on the pull request.

String replacementString = state.getSourceForNode(tree);
if (index == resolvedTestAnnotation.getFlags().size() - 1) {
replacementString =
replacementString.replace(", " + state.getSourceForNode(expressionTree), "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I believe this will work in most cases, it still ties us down to a formatting style where arguments are separated by , . I believe we should make it more general, (e.g. arguments could also be separated by a new line character or arguments could be separated by just a ,).
One options would be to do it the way error-prone folks delete type arguments in their UnnecessaryTypeArguments bug check.

" @interface ToggleTesting {",
" TestExperimentName[] treated();",
" }",
" @ToggleTesting(treated = {TestExperimentName.STALE_FLAG, TestExperimentName.OTHER_FLAG})",
Copy link
Collaborator

@ketkarameya ketkarameya Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another test scenario could be added @ToggleTesting(treated = {TestExperimentName.STALE_FLAG,TestExperimentName.OTHER_FLAG}) and

@ToggleTesting(treated = {TestExperimentName.STALE_FLAG,
                                                TestExperimentName.OTHER_FLAG})

}
}
return fixBuilder;
}

private int getLower(CharSequence source, int lower, int index, int flagSize) {
while (lower >= 0
&& source.charAt(lower) != '{'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what scenarios would we encounter a { or a = in an Enum List? Can you please add a test scenario for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for = i was thinking in @ToggleTesting(treated = TestExperimentName.STALE_FLAG) but you are right that it is not needed at this stage so i'll remove it
for { the scenario is tested in testRemoveFirstEnumFromAnnotationRemovingCommaAndKeepingOtherEnum where the enum is at the beginning of the list: @ToggleTesting(treated = {TestExperimentName.STALE_FLAG, TestExperimentName.OTHER_FLAG})

Copy link
Collaborator

@ketkarameya ketkarameya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me. I have a small comment below.

@ketkarameya
Copy link
Collaborator

ketkarameya commented Jan 25, 2022

Thanks a lot for your contribution and the comprehensive tests:)
I am merging the PR.

Copy link
Collaborator

@ketkarameya ketkarameya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ketkarameya
Copy link
Collaborator

@valulucchesi I was wondering if this new implementation could also handle something like this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants