You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
UnusedImportsRule warns about unused imports. When it founds an unused import, it adds it to a Set<ImportWrapper> imports and then adds violation. JavaRuleViolation has method setClassNameFrom, which (I believe) has the root of the problem.
Code Sample demonstrating the issue:
Here is this method that has the problem. If the class has default (package-private) access level, qualifiedName and className both remain null.
private void setClassNameFrom(JavaNode node) {
String qualifiedName = null;
for (AbstractAnyTypeDeclaration parent : node.getParentsOfType(AbstractAnyTypeDeclaration.class)) {
String clsName = parent.getScope().getEnclosingScope(ClassScope.class).getClassName();
if (qualifiedName == null) {
qualifiedName = clsName;
} else {
qualifiedName = clsName + '$' + qualifiedName;
}
}
if (qualifiedName == null) {
Set<ClassNameDeclaration> classes = node.getScope().getEnclosingScope(SourceFileScope.class)
.getClassDeclarations().keySet();
for (ClassNameDeclaration c : classes) {
// find the first public class/enum declaration
if (c.getAccessNodeParent() instanceof AccessNode) {
if (((AccessNode) c.getAccessNodeParent()).isPublic()) {
qualifiedName = c.getImage();
break;
}
}
}
}
if (qualifiedName != null) {
className = qualifiedName;
}
Running PMD through:Other
The text was updated successfully, but these errors were encountered:
@jsotuyod , hello! Actually I was more or less ready to provide more info if only anybody asked for it. We're using PMD not as a maven goal but as a test that checks only changed files comparing to master. That's why I didn't have any report.
Next time I'd be glad to ask for more info and probably fix something by myself, though I wasn't sure where is the active developers' place (slack, irc or whatever). Now I see you're using sourceforge
Affects PMD Version: 6.12
Rule: e.g UnusedUmportsRule
Description:
UnusedImportsRule warns about unused imports. When it founds an unused import, it adds it to a
Set<ImportWrapper> imports
and then adds violation.JavaRuleViolation
has methodsetClassNameFrom
, which (I believe) has the root of the problem.Code Sample demonstrating the issue:
Here is this method that has the problem. If the class has default (package-private) access level,
qualifiedName
andclassName
both remain null.Running PMD through: Other
The text was updated successfully, but these errors were encountered: