Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Godin
Copy link
Member

@Godin Godin commented Dec 6, 2024

Currently visibility of IFilter implementations is inconsistent:

package-private final

  • AssertFilter
  • BridgeFilter
  • ExhaustiveSwitchFilter
  • KotlinComposeFilter
  • KotlinDefaultMethodsFilter
  • KotlinEnumFilter
  • KotlinInlineClassFilter
  • RecordPatternFilter

public non-final

  • KotlinGeneratedFilter
  • KotlinLateinitFilter

all others are public final.

I propose to make them all, except Filters, consistently package-private and final.
IMO design-wise they should have been such since the beginning.

This will also fix a good amount of javadoc doclint warnings

use of default constructor, which does not provide a comment

which appear when building with JDK versions starting from 18.

@Godin Godin added this to the 0.8.13 milestone Dec 6, 2024
@Godin Godin requested a review from marchof December 6, 2024 23:02
@Godin Godin self-assigned this Dec 6, 2024
@Godin Godin force-pushed the IFilter_implementations_should_be_package_private branch from 09fa0d1 to fda454b Compare December 6, 2024 23:04
@Godin Godin enabled auto-merge (squash) December 6, 2024 23:04
@marchof
Copy link
Member

marchof commented Dec 8, 2024

👍 For cleaning-up package visibility!

A remark regarding method isKotlinClass():

  • The new location introduces a cyclic dependency between Filters and the Kotlin filter implementations (which we also have at other places)
  • The following filters miss this check: KotlinLateinitFilter, KotlinWhenFilter, KotlinWhenStringFilter, KotlinNotNullOperatorFilter

Both could be addressed by creating a separate Group for the Kotlin filters. It also eliminates the repeated isKotlinClass() checks in every filter implementation:

private static IFilter allKotlinFilters() {
	return new Filters( //
			new KotlinGeneratedFilter(), //
			new KotlinEnumFilter(), //
			new KotlinLateinitFilter(), //
			new KotlinWhenFilter(), //
			new KotlinWhenStringFilter(), //
			new KotlinUnsafeCastOperatorFilter(), //
			new KotlinNotNullOperatorFilter(), //
			new KotlinInlineClassFilter(), //
			new KotlinDefaultArgumentsFilter(), //
			new KotlinInlineFilter(), new KotlinCoroutineFilter(), //
			new KotlinDefaultMethodsFilter(), //
			new KotlinComposeFilter()) {
		@Override
		public void filter(final MethodNode methodNode,
				final IFilterContext context, final IFilterOutput output) {
			if (isKotlinClass(context)) {
				super.filter(methodNode, context, output);
			}
		}
	};
}

@Godin
Copy link
Member Author

Godin commented Dec 9, 2024

A remark regarding method isKotlinClass():
The following filters miss this check: KotlinLateinitFilter, KotlinWhenFilter, KotlinWhenStringFilter, KotlinNotNullOperatorFilter

So IMO the absence of this check in them is not a problem. We can add it, but IMO such a change should not be made within this PR.

The new location introduces a cyclic dependency between Filters and the Kotlin filter implementations

I agree that factoring out repeated isKotlinClass is indeed a good thing to do, even on its own, and actually I have been planning to do so for some time already.

But unfortunately this will not remove all cycles - it is also used in SyntheticFilter
It seems that SyntheticFilter should be split into two or more to remove all cycles - for Kotlin and for the rest. IMO such change should not be made within this PR.

There are also filters which are likely not applicable for Kotlin - for example TryWithResourcesJavac11Filter. IMO such classification should not be made within this PR and instead made carefully with the addition of more tests to not regress which I already started to add - see #1703 and #1684

@marchof All in all, I think that the scope of this PR should not be extended above its current title - change of visibility of classes (see "Clear scope" in org.jacoco.doc/docroot/doc/conventions.html), and I think that it should not be blocked and should not wait for all the above, ie IMO factorization of isKotlinClass and removal of cycles can be done later. Also it seems that to avoid cycles isKotlinClass can be moved to KotlinSMAP - I just updated this PR to do so. WDYT about this?

@marchof
Copy link
Member

marchof commented Dec 9, 2024

@Godin Ok, let's focus on the class visibility in this PR and discuss isKotlinClass() in a separate PR, ok?

@Godin
Copy link
Member Author

Godin commented Dec 9, 2024

@marchof ok and so where this PR should place isKotlinClass? 😅 😉

  1. in KotlinSMAP class as it is currently proposed in this PR - I like this variant because they are related since the use of KotlinSMAP must be guarded by isKotlinClass as it can't be used for non-Kotlin classes, and seems that this avoids cycles
  2. in Filters class as was initially proposed in this PR - this variant introduced cycles
  3. in KotlinGeneratedFilter as was initially - in this case KotlinGeneratedFilter will remain public and we'll need to add a comment to its constructor to get rid of the warning
  4. and one more idea just came to my mind - as non-static in interface IFilterContext implemented by ClassAnalyzer, but IMO this is overkill and again IMO requires separate PR

@marchof
Copy link
Member

marchof commented Dec 9, 2024

@Godin Ah I see, due to visibility issues we need to move it 😅

So let's go with your initial proposal and keep it in Filters for now.

@marchof
Copy link
Member

marchof commented Dec 9, 2024

@Godin Thanks! Let me propose a follow-up for the filter code organization.

@Godin Godin merged commit 5a6a5c4 into jacoco:master Dec 9, 2024
34 checks passed
@Godin Godin deleted the IFilter_implementations_should_be_package_private branch December 9, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants