ARTICLE AD BOX
I want to write a rule that checks if two ClassType nodes represent the same class, independently of whether or not that class is referenced with its fully qualified class name (FQCN) or not.
Checking type information in a XPath rule is possible with the build in function pmd-java:typeIs. However, that function takes a FQCN as a string parameter, so it can only be used if that FQCN is known when writing the rule or if it can be determined by the XPath.
The simplest example I could think of is:
package foo.bar; public class FooBar { private String foo; private java.lang.String bar; }In this example, the FQCN is known when writing the rule (java.lang.String). In my real-world use-case however, it is not known when writing the rule, since the rule needs to be generic.
PMD 7.24.0 parses thee example into the following AST:
└─ CompilationUnit ├─ PackageDeclaration │ └─ ModifierList └─ ClassDeclaration ├─ ModifierList └─ ClassBody ├─ FieldDeclaration │ ├─ ModifierList │ ├─ ClassType │ └─ VariableDeclarator │ └─ VariableId └─ FieldDeclaration ├─ ModifierList ├─ ClassType └─ VariableDeclarator └─ VariableIdn>For both ClassType nodes, PMD Designer shows me that PMD is smart enough to know that the represented class is java.lang.String. Example:

Unfortunately, I can't find a way to access that information in an XPath rule to use it as a parameter value for pmd-java:typeIs.
Is there a way to access the FQCN of the class represented by a ClassType node; or more broadly, is there a way to check, if two ClassType nodes represent the same class?
