Skip to content

[java] Deprecate getImage()/@Image and remove usages - #7048

Merged
adangel merged 25 commits into
pmd:mainfrom
UncleOwen:issue-4787-pmd-java-remove-remaining-usages-of-getImage
Oct 23, 2026
Merged

adangel merged 25 commits into
pmd:mainfrom
UncleOwen:issue-4787-pmd-java-remove-remaining-usages-of-getImage

Conversation

@UncleOwen

@UncleOwen UncleOwen commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Part of #4787

Describe the PR

This PR removes the remaining uses of @Image/Node.getImage() from pmd-java.

Related issues

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 marked this pull request as draft September 7, 2026 19:05
@UncleOwen
UncleOwen force-pushed the issue-4787-pmd-java-remove-remaining-usages-of-getImage branch from fb854d3 to 0aeecfd Compare September 7, 2026 19:11
@UncleOwen
UncleOwen marked this pull request as ready for review September 7, 2026 19:31
@pmd-actions-helper

pmd-actions-helper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 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-10-22 14:34:40+00:00 for 2dd4db6)

@UncleOwen UncleOwen changed the title [java] Work on #4787 remove remaining usages of @Image/Node.getImage() [java] Work on #4787: remove remaining usages of @Image/Node.getImage() Sep 7, 2026
…of-getImage

# Conflicts:
#	pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/FieldNamingConventionsRule.java

@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 for the PR!

I'd prefer, if we directly prepare the deprecation of getImage here. That means

  • we don't use the parsers setLastTokenImage anymore (which would call setImage on the node)
  • we have for all these cases in the node a proper alternative attribute and getImage returns that attribute. The parser will call the set_name_of_the_attribute setter instead of setLastTokenImage

I've tested this approach with ASTBreakStatement - there are no test failures, so I assume, we don't use break statements with labels in any sample file we have a treedump test... which means, in that case, we can directly deprecated it (note: release notes).

…of-getImage

# Conflicts:
#	pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousOctalEscapeRule.java
@UncleOwen

UncleOwen commented Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

When I wrote this PR, I didn't want to touch the parser. That's why we wouldn't be able to deprecate setImage(). But I think this PR does enable us to deprecate getImage() and the image variable. At least, as far as Java is concerned. Looking back at it, I agree that this asymmetry is confusing. Should I continue working on this PR, so we can deprecate setImage() as well?

As for making sure that getImage() still works even if deprecated: We could add an assert getImage().equals(getLabel()) in ASTBreakStatement.jjtClose().

@UncleOwen
UncleOwen marked this pull request as draft October 19, 2026 17:21
@UncleOwen

Copy link
Copy Markdown
Member Author

Hmmm, maybe jjtClose is too early.

@adangel adangel self-assigned this Oct 22, 2026
@adangel adangel changed the title [java] Work on #4787: remove remaining usages of @Image/Node.getImage() [java] Deprecate getImage()/@Image and remove usages Oct 22, 2026
@adangel adangel added the is:deprecation The main focus is deprecating public APIs or rules, eg to make them internal, or removing them label Oct 22, 2026
@adangel adangel added this to the 7.29.0 milestone Oct 22, 2026
@adangel

adangel commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Hmmm, maybe jjtClose is too early.

I've continued and finished this PR. I've decided to not use assert in jjtClose and just have unit tests, to verify image attribute.

Note: This is only a first step towards #4787 . I've outlined there the next steps for java:

  • Deprecate @Image of: ASTCompactConstructorDeclaration, ASTEnumConstant, ASTInfixExpression, ASTStringLiteral (and all other subtypes of AbstractLiteral - last usage of setImage)
  • Deprecate @Image of remaining nodes (inherited through AbstractJjtreeNode). Deprecation in AbstractJavaNode. In theory, this should not affect any more nodes, because setImage is not used anymore.

If the build looks fine, I'm going to merge this for 7.29.0.

@adangel
adangel marked this pull request as ready for review October 22, 2026 14:06
@adangel
adangel merged commit 803bccb into pmd:main Oct 23, 2026
13 checks passed
@UncleOwen
UncleOwen deleted the issue-4787-pmd-java-remove-remaining-usages-of-getImage branch October 23, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

is:deprecation The main focus is deprecating public APIs or rules, eg to make them internal, or removing them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants