Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Peter Major
@aldaris
Hi, I'm trying to write a new rule that forbids direct usages of Instant.now() (to enforce in-house API that relies on Clock instances). I've got as far as having this Xpath rule: //PrimaryPrefix/Name[@Image='Instant.now'][pmd-java:typeIs('java.time.Instant')] , but now I'm wondering how could I detect cases when now() is statically imported
Peter Major
@aldaris
This looks to do the job: //PrimaryPrefix/Name[@Image='now'][//ImportDeclaration[@Static=true()]/Name[@Image="java.time.Instant"]]
Clément Fournier
@oowekyala
Not sure this would catch the case import static java.time.Instant.now;
Besides using the Name node in ImportDeclaration is deprecated, you should rather use the attribute @ImportedName of ImportDeclaration
Ah I see you already fixed my first comment in the version you posted to pmd/pmd-designer#27 ^^
Peter Major
@aldaris
thanks for the heads up, the designer didn't really tell me which attributes are deprecated or not :)
I shall use @ImportedName instead.
Clément Fournier
@oowekyala
Yeah, the XPath editor could be more helpful... I'll add a couple of tickets for later
Peter Major
@aldaris
Looks pretty handy though, it would have taken me ages to figure out what elements and attributes to use without it.
Peter Major
@aldaris
If there is an overloaded method, is there a way to tell which one of those methods get called? Figuring out the type of a method call argument seems to be non straightforward
zhaolibin
@zhaolibin
everybody here
how to install the pmd designer
Andreas Dangel
@adangel
@zhaolibin The designer is included in the standard PMD distribution (https://pmd.github.io) - see https://github.com/pmd/pmd-designer#installation