-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add filter for Kotlin enum classes #1625
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
Conversation
leveretka
left a comment
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.
Overall looks good, thanks for fixing it!
I just have a small suggestion to improve readability.
|
|
||
| public void filter(final MethodNode methodNode, | ||
| final IFilterContext context, final IFilterOutput output) { | ||
| if (!"java/lang/Enum".equals(context.getSuperClassName())) { |
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.
I don't know if this is the convention here, but as a code reader, I'd prefer to see a single if without negations in the conditions to reduce a cognitive load. Since the body of the if is just one line, this is an acceptable level of nesting.
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.
We don't have a strict convention about this and both styles can be found, but seems that the early-returns style is prevalent:
single if in
jacoco/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/EnumEmptyConstructorFilter.java
Lines 39 to 48 in 5aabb2e
| public void filter(final MethodNode methodNode, | |
| final IFilterContext context, final IFilterOutput output) { | |
| if (ENUM_TYPE.equals(context.getSuperClassName()) | |
| && CONSTRUCTOR_NAME.equals(methodNode.name) | |
| && CONSTRUCTOR_DESC.equals(methodNode.desc) | |
| && new Matcher().match(methodNode)) { | |
| output.ignore(methodNode.instructions.getFirst(), | |
| methodNode.instructions.getLast()); | |
| } | |
| } |
Lines 26 to 35 in 5aabb2e
| public void filter(final MethodNode methodNode, | |
| final IFilterContext context, final IFilterOutput output) { | |
| if ((methodNode.access & Opcodes.ACC_PRIVATE) != 0 | |
| && CONSTRUCTOR_NAME.equals(methodNode.name) | |
| && CONSTRUCTOR_DESC.equals(methodNode.desc) && new Matcher() | |
| .match(methodNode, context.getSuperClassName())) { | |
| output.ignore(methodNode.instructions.getFirst(), | |
| methodNode.instructions.getLast()); | |
| } | |
| } |
early returns in
jacoco/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java
Lines 23 to 30 in 5aabb2e
| public void filter(final MethodNode methodNode, | |
| final IFilterContext context, final IFilterOutput output) { | |
| if ((methodNode.access & Opcodes.ACC_BRIDGE) == 0) { | |
| return; | |
| } | |
| output.ignore(methodNode.instructions.getFirst(), | |
| methodNode.instructions.getLast()); | |
| } |
jacoco/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinInlineClassFilter.java
Lines 74 to 87 in 5aabb2e
| public void filter(final MethodNode methodNode, | |
| final IFilterContext context, final IFilterOutput output) { | |
| if (!KotlinGeneratedFilter.isKotlinClass(context)) { | |
| return; | |
| } | |
| if (!context.getClassAnnotations().contains("Lkotlin/jvm/JvmInline;")) { | |
| return; | |
| } | |
| if ((methodNode.access & Opcodes.ACC_STATIC) != 0) { | |
| return; | |
| } | |
| output.ignore(methodNode.instructions.getFirst(), | |
| methodNode.instructions.getLast()); | |
| } |
jacoco/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinGeneratedFilter.java
Lines 31 to 50 in 5aabb2e
| public void filter(final MethodNode methodNode, | |
| final IFilterContext context, final IFilterOutput output) { | |
| if (context.getSourceFileName() == null) { | |
| // probably full debug information is missing | |
| // disabled filtering as all methods might be erroneously skipped | |
| return; | |
| } | |
| if (!isKotlinClass(context)) { | |
| return; | |
| } | |
| if (hasLineNumber(methodNode)) { | |
| return; | |
| } | |
| output.ignore(methodNode.instructions.getFirst(), | |
| methodNode.instructions.getLast()); | |
| } |
jacoco/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultMethodsFilter.java
Lines 25 to 31 in 5aabb2e
| public void filter(final MethodNode methodNode, | |
| final IFilterContext context, final IFilterOutput output) { | |
| if (!KotlinGeneratedFilter.isKotlinClass(context)) { | |
| return; | |
| } | |
| new Matcher().match(methodNode, output); | |
| } |
Lines 72 to 86 in 5aabb2e
| public void filter(final MethodNode methodNode, | |
| final IFilterContext context, final IFilterOutput output) { | |
| if ((methodNode.access & Opcodes.ACC_SYNTHETIC) == 0) { | |
| return; | |
| } | |
| if (!KotlinGeneratedFilter.isKotlinClass(context)) { | |
| return; | |
| } | |
| if (isDefaultArgumentsMethod(methodNode)) { | |
| new Matcher().match(methodNode, output, false); | |
| } else if (isDefaultArgumentsConstructor(methodNode)) { | |
| new Matcher().match(methodNode, output, true); | |
| } | |
| } |
| new ExhaustiveSwitchFilter(), // | ||
| new RecordPatternFilter(), // | ||
| new AnnotationGeneratedFilter(), new KotlinGeneratedFilter(), | ||
| new KotlinEnumFilter(), // |
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.
Why do we need a // here?
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.
Otherwise Eclipse JDT Formatter will join lines and the change will look like
new AnnotationGeneratedFilter(), new KotlinGeneratedFilter(),
- new KotlinLateinitFilter(), new KotlinWhenFilter(),
- new KotlinWhenStringFilter(),
+ new KotlinEnumFilter(), new KotlinLateinitFilter(),
+ new KotlinWhenFilter(), new KotlinWhenStringFilter(),
new KotlinUnsafeCastOperatorFilter(),
Fixes #1557