Skip to content

#150: Implement class inheritance pattern#1227

Merged
yegor256 merged 3 commits into
cqfn:masterfrom
marinka-aa:fix-issue-150-class-inheritance
Jun 25, 2026
Merged

#150: Implement class inheritance pattern#1227
yegor256 merged 3 commits into
cqfn:masterfrom
marinka-aa:fix-issue-150-class-inheritance

Conversation

@marinka-aa

@marinka-aa marinka-aa commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added a new rule to detect when classes use implementation inheritance (extends) and report the affected lines.
  • Documentation
    • Expanded the pattern guide with additional documented patterns and examples, including class inheritance.
  • Tests
    • Added Java fixtures and unit tests covering simple inheritance, nested classes, and non-matching cases (implements-only and extends via type bounds).

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40623217-e3b9-48a7-bacc-f7c2f55f5622

📥 Commits

Reviewing files that changed from the base of the PR and between 4014272 and 8e96527.

📒 Files selected for processing (5)
  • test/patterns/class_inheritance/NestedInheritance.java
  • test/patterns/class_inheritance/OnlyImplements.java
  • test/patterns/class_inheritance/SimpleInheritance.java
  • test/patterns/class_inheritance/TypeParameterExtends.java
  • test/patterns/class_inheritance/test_class_inheritance.py
✅ Files skipped from review due to trivial changes (1)
  • test/patterns/class_inheritance/NestedInheritance.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • test/patterns/class_inheritance/SimpleInheritance.java
  • test/patterns/class_inheritance/TypeParameterExtends.java
  • test/patterns/class_inheritance/test_class_inheritance.py
  • test/patterns/class_inheritance/OnlyImplements.java

📝 Walkthrough

Walkthrough

Adds a new ClassInheritance pattern, registers it as P34, updates pattern documentation, and adds Java fixtures plus Python tests for inheritance, implements-only, generic bounds, and nested classes.

Changes

Class inheritance pattern and docs

Layer / File(s) Summary
Pattern catalog updates
PATTERNS.md
Adds documented pattern entries P12-P27 and the new P34 class inheritance entry with descriptions and examples.
Pattern implementation and registration
aibolit/patterns/class_inheritance/*, aibolit/config.py
Implements ClassInheritance for classes with extends, and registers P34 in the pattern configuration.
Fixtures and tests
test/patterns/class_inheritance/*.java, test/patterns/class_inheritance/test_class_inheritance.py
Adds inheritance-related Java fixtures and unit tests that verify detected line numbers and non-matches.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • ivanovmg

Poem

I hopped through patterns, P34 in sight,
With ears in the config, all snug and tight.
The tests went thump on extends and Base,
And bunny-checks lit up the AST race.
Hooray for code hops! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding the class inheritance pattern.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PMD (7.25.0)
test/patterns/class_inheritance/TypeParameterExtends.java

[ERROR] Error at scripts/ruleset.xml:23:36
21|
22|
23|
^^^^^ Value should be 'countImports'

24|
25| : '|' should be 'countImports'
[ERROR] Error at scripts/ruleset.xml:19:3
17|
18|
19|
^^^^^ Error while parsing rule reference

20|
21| : Error at scripts/ruleset.xml:23:36
21|
22|
23|
^^^^^ Value should be 'countImports'

24|
25|
[ERROR] Cannot load ruleset scripts/ruleset.xml: 2 XML validation errors occurred
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

test/patterns/class_inheritance/SimpleInheritance.java

[ERROR] Error at scripts/ruleset.xml:23:36
21|
22|
23|
^^^^^ Value should be 'countImports'

24|
25| : '|' should be 'countImports'
[ERROR] Error at scripts/ruleset.xml:19:3
17|
18|
19|
^^^^^ Error while parsing rule reference

20|
21| : Error at scripts/ruleset.xml:23:36
21|
22|
23|
^^^^^ Value should be 'countImports'

24|
25|
[ERROR] Cannot load ruleset scripts/ruleset.xml: 2 XML validation errors occurred
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

test/patterns/class_inheritance/NestedInheritance.java

[ERROR] Error at scripts/ruleset.xml:23:36
21|
22|
23|
^^^^^ Value should be 'countImports'

24|
25| : '|' should be 'countImports'
[ERROR] Error at scripts/ruleset.xml:19:3
17|
18|
19|
^^^^^ Error while parsing rule reference

20|
21| : Error at scripts/ruleset.xml:23:36
21|
22|
23|
^^^^^ Value should be 'countImports'

24|
25|
[ERROR] Cannot load ruleset scripts/ruleset.xml: 2 XML validation errors occurred
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/patterns/class_inheritance/NestedInheritance.java`:
- Around line 1-9: The fixture in NestedInheritance.java is missing the standard
SPDX license header, which is causing the copyrights check to fail in CI. Add
the repository’s usual SPDX header at the very top of the file before the
package declaration, keeping the existing Outer and Inner class definitions
unchanged.

In `@test/patterns/class_inheritance/OnlyImplements.java`:
- Around line 1-5: The fixture in OnlyImplements is missing the required SPDX
copyright header, which is causing the copyrights check to fail. Add the
standard SPDX license header at the top of the file before the package
declaration, keeping the existing Base and MyList definitions unchanged.

In `@test/patterns/class_inheritance/SimpleInheritance.java`:
- Around line 1-5: The fixture is missing the required SPDX license header,
causing the copyrights check to fail. Add the standard SPDX header at the top of
this Java file before the package declaration, keeping the existing Base and
MyList class definitions unchanged.

In `@test/patterns/class_inheritance/TypeParameterExtends.java`:
- Around line 1-4: Add the standard SPDX copyright header at the top of the
fixture before the package declaration in GenericBox so the copyrights check
passes. Keep the class definition unchanged and insert the repo’s standard
header in this file, ensuring it appears before patterns.class_inheritance and
matches the existing SPDX format used in other fixtures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e467bf0-b11e-4907-b532-35ce5640aa44

📥 Commits

Reviewing files that changed from the base of the PR and between a3ace02 and 4014272.

📒 Files selected for processing (9)
  • PATTERNS.md
  • aibolit/config.py
  • aibolit/patterns/class_inheritance/__init__.py
  • aibolit/patterns/class_inheritance/class_inheritance.py
  • test/patterns/class_inheritance/NestedInheritance.java
  • test/patterns/class_inheritance/OnlyImplements.java
  • test/patterns/class_inheritance/SimpleInheritance.java
  • test/patterns/class_inheritance/TypeParameterExtends.java
  • test/patterns/class_inheritance/test_class_inheritance.py

Comment thread test/patterns/class_inheritance/NestedInheritance.java
Comment thread test/patterns/class_inheritance/OnlyImplements.java
Comment thread test/patterns/class_inheritance/SimpleInheritance.java
Comment thread test/patterns/class_inheritance/TypeParameterExtends.java
@yegor256 yegor256 merged commit 6d5c676 into cqfn:master Jun 25, 2026
20 checks passed
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.

2 participants