Skip to content

[core] Make boolean XPath attributes accessible with their prefix #1170

@oowekyala

Description

@oowekyala

Boolean attributes in XPath are stripped of their is, has or uses prefix, although it greatly contributes to readability:

http://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIterator.java#L36-L44

SwitchStatement[@IsDefault = true()] would be much more readable than just @Default = true(), and same for eg @IsArray for dimensionable nodes. The problem is even greater with has, since it's common practice to eg have a hasXX and getXX on the same class, which would be truncated to the same attribute name. If we're going to flesh our the AST APIs, we need to avoid that.

It would be great to preserve the prefix on boolean attributes. The problem here is compatibility, so we would have to keep the two forms along for some time, one being deprecated.

The new behaviour needs to be described in the language specific doc (it's part of the AST API).

⚠️ For ease of migration, we should probably do this on master and expose the attributes in both ways and deprecate the old way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:RFCA drafted proposal on changes to PMD, up for feedback form the team and communityin:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions