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

Exclude enum methods "values" and "valueOf" from reports #491

Merged
merged 1 commit into from
Feb 27, 2017
Merged

Conversation

Godin
Copy link
Member

@Godin Godin commented Feb 25, 2017

I propose to do a baby step in story of filtering by excluding enum methods values and valueOf from reports.

Copy link
Member

@marchof marchof left a comment

Choose a reason for hiding this comment

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

@Godin Thx! I added some inline comments.

final String superClassName, final int access, final String name,
final String desc) {
if ("java/lang/Enum".equals(superClassName)
&& ("values".equals(name) || name.equals("valueOf") && desc
Copy link
Member

Choose a reason for hiding this comment

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

@Godin Shouldn't we also check the signature of the values method? For readability I would prefer braces or a separate statement for each method. Maybe also some inline comments what we're going to filter here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch 👍 Don't know why my mind decided that signature check not needed for values method, while needed for valueOf 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

@marchof fixed

@@ -87,4 +87,24 @@ public void testMethodFilter_Lambda() {
assertEquals(1, coverage.getMethods().size());
}

@Test
public void testMethodFilter_EnumValues() {
Copy link
Member

Choose a reason for hiding this comment

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

@Godin What about a negative test for different signature?

Copy link
Member Author

Choose a reason for hiding this comment

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

@marchof added

}

@Test
public void testMethodFilter_EnumValueOf() {
Copy link
Member

Choose a reason for hiding this comment

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

@Godin Same here: Negativ test for different signature.

Copy link
Member Author

Choose a reason for hiding this comment

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

@marchof added

Copy link
Member

@marchof marchof left a comment

Choose a reason for hiding this comment

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

@Godin I feel bad for beeing so picky today :-(

final String desc) {
if ("java/lang/Enum".equals(superClassName)) {
// filter out methods that compiler creates for enums
if ("values".equals(name)
Copy link
Member

@marchof marchof Feb 27, 2017

Choose a reason for hiding this comment

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

We mix two different comparisons styles here: "expected".equals(actual) vs. actual.equals("expected"). I would prefer to use the first one only as it is NPE safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

Umm, below there is anyway name.startsWith(...) that isn't NPE safe. Also according to my knowledge of ASM API - desc can't be null. For the NPE safety IMO far better to ensure that parameters of methods are not null by default and nullability should be stated explicitly.

But ok, I'll swap arguments, hoping that you won't say that concatenation on left hand side looks awkward 😆

analyzer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "Foo", null,
"java/lang/Enum", null);

MethodProbesVisitor mv = analyzer.visitMethod(0, "values", "()[LFoo;",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't that be two test methods? Took me a short moment to realize that this tests two setups.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hesitated to create separate, because then IMO not so easy to catch difference between them. But ok, I'll split.

@marchof marchof merged commit 296f992 into master Feb 27, 2017
@marchof marchof deleted the issue-491 branch February 27, 2017 14:03
@jacoco jacoco locked and limited conversation to collaborators Feb 27, 2017
@Godin Godin added this to DONE in Filtering Mar 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Filtering
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants