Skip to content

[java] Fix #6736: Add JTypeMirror.streamClasses() - #6738

Merged
UncleOwen merged 8 commits into
pmd:mainfrom
UncleOwen:issue-6736-streamNestedClasses
Jun 23, 2026
Merged

UncleOwen merged 8 commits into
pmd:mainfrom
UncleOwen:issue-6736-streamNestedClasses

Conversation

@UncleOwen

@UncleOwen UncleOwen commented May 30, 2026 •

Copy link
Copy Markdown
Member

Describe the PR

This PR

  • adds JTypeMirror.streamClasses() and .streamDeclaredClasses(),
  • uses this to make TestFrameworksUtil.isJunit5Class() and .isTestClass() recognize classes with only @Nested classes as test classes
  • which in turn fixes ClassNamingConventions, JUnitJupiterTestShouldBePackagePrivate, and JUnitJupiterTestNoPrivateModifier in this case.

Related issues

Review notes

I think this is my first time touching the .types package. I believe I've done the right thing here, but please double check.
I've used .streamMethods() and .streamDeclaredMethods as a template for my code. I didn't implement the two methods
in JArrayType, because I don't think arrays can have nested classes.

Are there existing tests for JTypeMirror and related classes where I need to add some tests? Currently, I only test my changes indirectly via
TestFrameworksUtilTest.

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@UncleOwen
UncleOwen force-pushed the issue-6736-streamNestedClasses branch from d48b9a9 to d27ab12 Compare May 30, 2026 16:41
@pmd-actions-helper

pmd-actions-helper Bot commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 1 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-06-23 12:17:41+00:00 for 8e5689a)

@UncleOwen UncleOwen changed the title [java Fix #6736: Add JTypeMirror.streamClasses() [java] Fix #6736: Add JTypeMirror.streamClasses() Jun 1, 2026
@UncleOwen
UncleOwen force-pushed the issue-6736-streamNestedClasses branch 4 times, most recently from bb447f5 to c18f0da Compare June 3, 2026 20:31
@adangel

adangel commented Jun 4, 2026

Copy link
Copy Markdown
Member

Are there existing tests for JTypeMirror and related classes where I need to add some tests? Currently, I only test my changes indirectly via
TestFrameworksUtilTest.

Most tests are probably written in Kotlin -> https://github.com/pmd/pmd/tree/main/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types

I assume, there are some tests for JTypeMirror....

@UncleOwen
UncleOwen marked this pull request as draft June 6, 2026 04:18
@UncleOwen
UncleOwen force-pushed the issue-6736-streamNestedClasses branch from c18f0da to 5ff35cd Compare June 12, 2026 14:35
@UncleOwen

Copy link
Copy Markdown
Member Author

@oowekyala Thanks for your comments. I've removed the prefilter. I was going for a similar API between streamMethods and streamClasses. But if this is only a performance thing, that isn't needed for classes, I shouldn't blindly copy it.

I've also added a single test to ClassTypeImplTest, so that the new functionality in ClassTypeImpl is tested directly.

@UncleOwen
UncleOwen marked this pull request as ready for review June 12, 2026 14:57
Implement those methods in ClassTypeImpl, JIntersectionType, JTypeVar and JWildcardType.
Implementation mirrors the implementation of .streamMethods() and .streamDeclaredMethods().

Use the new methods to have TestFrameworksUtil.isJUnit5Class for the existence of @nested classes.
For methods, having a filter reduces the amount of objects created.
This increases performance.
For classes, that's not the case. Let's go for the simple interface.
@UncleOwen
UncleOwen force-pushed the issue-6736-streamNestedClasses branch from adeed05 to 59c0a8f Compare June 19, 2026 17:20
@UncleOwen
UncleOwen requested review from adangel and oowekyala June 19, 2026 17:36

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks good!

Comment thread docs/pages/release_notes.md Resolved
UncleOwen and others added 2 commits June 23, 2026 13:59
…/bestpractices/xml/JUnitJupiterTestShouldBePackagePrivate.xml

Co-authored-by: Andreas Dangel <[email protected]>
@UncleOwen
UncleOwen merged commit cabc962 into pmd:main Jun 23, 2026
13 checks passed
@UncleOwen
UncleOwen deleted the issue-6736-streamNestedClasses branch June 23, 2026 12:19
@UncleOwen UncleOwen added this to the 7.26.0 milestone Jun 23, 2026
UncleOwen added a commit to UncleOwen/pmd that referenced this pull request Jun 23, 2026
* Split TestFrameworksUtil.isXXXClass into hasXXXTests and
  isConcreteToplevelClass
* Use those for a new TestFrameworksUtil.hasTests() method.
* This method automatically supports superclasses because of the work
  done in previous PRs (pmd#6604, pmd#6680, pmd#6689, pmd#6735, pmd#6738)
* Use TestFrameworksUtil.hasTests() in TestClassWithoutTestCasesRule
UncleOwen added a commit to UncleOwen/pmd that referenced this pull request Jun 23, 2026
* Split TestFrameworksUtil.isXXXClass into hasXXXTests and
  isConcreteToplevelClass
* These methods automatically supports superclasses because of the work
  done in previous PRs (pmd#6604, pmd#6680, pmd#6689, pmd#6735, pmd#6738)
* Use these methods in TestClassWithoutTestCasesRule
UncleOwen added a commit to UncleOwen/pmd that referenced this pull request Jun 23, 2026
* Split TestFrameworksUtil.isXXXClass into hasXXXTests and
  isConcreteToplevelClass
* These methods automatically supports superclasses because of the work
  done in previous PRs (pmd#6604, pmd#6680, pmd#6689, pmd#6735, pmd#6738)
* Use these methods in TestClassWithoutTestCasesRule
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.

[java] JUnitJupiterTestShouldBePackagePrivate: False negative when the only tests are in a @Nested class

3 participants