문제

I'm trying to create some design and style rules for my team using PMD Designer. The goal is to add these rules to our teams SonarQube. It would be useful in some cases to identify when a line break is used. For example:

MyResult result = new Builder().doSomething().run();

versus

MyResult result = new Builder()
    .doSomething()
    .run();

However the AST for each is identical:

AST Comparison of each technique

Is there anyway to identify the difference in line breaks within a PMD rule? If not, is there a different analysis engine that would?

도움이 되었습니까?

해결책

While the structure of the AST is the same, there is more detail than that in the actual XML file. In particular, there are attributes for the line number and column of tags. Which means you can write an XPath or Java rule against those attributes.

You can see an example here.

<TypeDeclaration BeginColumn="1" BeginLine="1" EndColumn="1" EndLine="10"

You can also generate this for your own file for testing using the PMD Eclipse plugin.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top