You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling getImage() on an instance of ASTAnnotation, the returned value will be in pascal case, instead of the string that is actually present in the .cls file. This makes it impossible to enforce casing rules on annotations using PMD.
Note Disclaimer: I am pretty new to writing custom PMD rules, so if there is a better way to get the raw annotation string, please let me know!
@rsoesemann When I take a look at the replacement implementation of getName in ASTAnnotation, it still has the same underlying method calls, so I doubt that would resolve the case sensitivity issue.
adangel
changed the title
[Apex] ASTAnnotation.getImage() does not return value as written in the class
[apex] ASTAnnotation.getImage() does not return value as written in the class
Mar 16, 2023
Yes, getImage() (which probably will be removed in some future version) and getName() both return the normalized annotation names.
For Java rules and PMD 7, the raw name is generally available via annotationNode.getTextDocument().sliceOriginalText(annotationNode.getTextRegion()), which would return in the above example @istest. PR #4936 adds a new getter getRawName() which returns the original annotation name without normalization. This can then also be used in XPath rules (e.g. //Annotation[@RawName != @Name]).
Affects PMD Version:
6.55.0, 7.0.0
Description:
When calling
getImage()
on an instance ofASTAnnotation
, the returned value will be in pascal case, instead of the string that is actually present in the.cls
file. This makes it impossible to enforce casing rules on annotations using PMD.Code Sample demonstrating the issue:
PMD/pmd-rules/src/main/java/com/mycompany/custom_pmd/AnnotationExample.java
SFDX_Project/force-app/main/default/classes/Example.cls
We would expect this to print the value
istest
because that is what's in theExample.cls
, but instead, here is the output produced:Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
dependency-reduced-pom.xml
Running PMD through:
Maven
The text was updated successfully, but these errors were encountered: