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

Introduce HasTypeArguments matcher #644

Closed
wants to merge 5 commits into from

Conversation

oxkitsune
Copy link
Contributor

Introduces a Matcher that matches {MethodInvocation,NewClass}Tree instances declared with type arguments.

Should unblock #46

@oxkitsune oxkitsune requested a review from rickie May 22, 2023 09:48
@github-actions
Copy link

  • Surviving mutants in this change: 4
  • Killed mutants in this change: 9
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.util.MoreMatchers 4 9

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
@github-actions
Copy link

  • Surviving mutants in this change: 4
  • Killed mutants in this change: 9
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.util.MoreMatchers 4 9

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@oxkitsune oxkitsune changed the title Introduce MoreMatchers#hasTypeArguments() matcher Introduce HasTypeArguments matcher May 22, 2023
@github-actions
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 10
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.HasTypeArguments 2 10

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@github-actions
Copy link

Looks good. All 12 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.refaster.matchers.HasTypeArguments 0 12

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

"",
" Foo positive3() {",
" // BUG: Diagnostic contains:",
" return new <List<Object>>Foo(List.of());",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's is probably a better example of this

@oxkitsune oxkitsune marked this pull request as ready for review May 22, 2023 11:19
@Stephan202 Stephan202 force-pushed the gdejong/has-type-arguments-matcher branch from 1655979 to d0452ab Compare May 25, 2023 14:19
@github-actions
Copy link

Looks good. All 12 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.refaster.matchers.HasTypeArguments 0 12

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

Added a small commit. Not done reviewing yet but wanted to flush what I have 😄.

return false;
}

return !((ParameterizedTypeTree) classTree.getIdentifier()).getTypeArguments().isEmpty();
Copy link
Member

Choose a reason for hiding this comment

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

We can extract classTree.getIdentifier() as we use it twice.

"",
"class A {",
" Object negative1() {",
" return alwaysNull();",
Copy link
Member

Choose a reason for hiding this comment

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

We can simply use toString() here :)

"",
" <E> ImmutableSet<E> positive1() {",
" // BUG: Diagnostic contains:",
" return ImmutableSet.<E>builder().build();",
Copy link
Member

Choose a reason for hiding this comment

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

We can probably simplify by:

"  List<Integer> positive1() {",
"    return new ArrayList<Integer>();",
"  }",
"",

(Will apply this tomorrow when I get back to this.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link

Looks good. All 12 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.refaster.matchers.HasTypeArguments 0 12

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

I like the idea behind this new Matcher, but I wonder how it's meant to be used in #46, because the Refaster template methods modified in that PR don't accept any parameters: the new X() / new X<...>() constructor invocations against which we want to match are explicitly defined in the method bodies, so there's no place to put the @Matches/@NotMatches annotations? 🤔

@oxkitsune
Copy link
Contributor Author

That is something I ran into as well, but haven't had a super good look into it.

@oxkitsune
Copy link
Contributor Author

I think we can close this PR, as the main goal of this Matcher was to unblock #46 and fix that issue, so we can apply EPS to guava.
I don't think we need this Matcher in EPS as Refaster is able to match type arguments.

@oxkitsune oxkitsune closed this May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants