Merge branch 'pr-1744'
This commit is contained in:
@ -16,6 +16,9 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
### Fixed Issues
|
||||
|
||||
* java
|
||||
* [#1729](https://github.com/pmd/pmd/issues/1729): \[java] JavaRuleViolation loses information in `className` field when class has package-private access level
|
||||
|
||||
### API Changes
|
||||
|
||||
### External Contributions
|
||||
|
@ -119,6 +119,19 @@ public class JavaRuleViolation extends ParametricRuleViolation<JavaNode> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Still not found?
|
||||
if (qualifiedName == null) {
|
||||
for (ClassNameDeclaration c : classes) {
|
||||
// find the first package-private class/enum declaration
|
||||
if (c.getAccessNodeParent() instanceof AccessNode) {
|
||||
if (((AccessNode) c.getAccessNodeParent()).isPackagePrivate()) {
|
||||
qualifiedName = c.getImage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qualifiedName != null) {
|
||||
|
@ -120,4 +120,14 @@ public class JavaRuleViolationTest {
|
||||
assertEquals("pkg", violation.getPackageName());
|
||||
assertEquals("Bar", violation.getClassName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageAndPackagePrivateClassesName() {
|
||||
ASTCompilationUnit ast = parse("package pkg; import java.util.List; class Foo { }");
|
||||
ASTImportDeclaration importNode = ast.getFirstDescendantOfType(ASTImportDeclaration.class);
|
||||
|
||||
JavaRuleViolation violation = new JavaRuleViolation(null, new RuleContext(), importNode, null);
|
||||
assertEquals("pkg", violation.getPackageName());
|
||||
assertEquals("Foo", violation.getClassName());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user