[java] UnnecessaryFullyQualifiedName: Fix false-neg with nested exceptions
This commit is contained in:
@ -17,6 +17,7 @@ import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTNameList;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
@ -268,7 +269,9 @@ public class UnnecessaryFullyQualifiedNameRule extends AbstractJavaRule {
|
||||
// package a;
|
||||
// name: a.b.c.d(); -> we assume, b is a class, c is a field, d is a method.
|
||||
// but it could very well be, that: a.b is a package and c is a class, d is a (static) method.
|
||||
if (node.jjtGetParent() instanceof ASTPrimaryPrefix || node instanceof ASTClassOrInterfaceType) {
|
||||
if (node.jjtGetParent() instanceof ASTPrimaryPrefix
|
||||
|| node.jjtGetParent() instanceof ASTNameList
|
||||
|| node instanceof ASTClassOrInterfaceType) {
|
||||
return currentPackage != null && name.startsWith(currentPackage);
|
||||
}
|
||||
|
||||
|
@ -643,21 +643,24 @@ package net.sourceforge.pmd.lang.java.rule.codestyle.unnecessaryfullyqualifiedna
|
||||
|
||||
<test-code>
|
||||
<description>False-Negative when referencing inner class</description>
|
||||
<expected-problems>5</expected-problems>
|
||||
<expected-linenumbers>3,4,7,8,11</expected-linenumbers>
|
||||
<expected-problems>7</expected-problems>
|
||||
<expected-linenumbers>3,4,6,7,8,9,12</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
package com.example;
|
||||
|
||||
public class ClassOne extends com.example.ClassTwo {
|
||||
com.example.ClassTwo.Builder builder = null;
|
||||
|
||||
public void run() {
|
||||
public void run() throws com.example.ClassOne.MyException {
|
||||
com.example.ClassOne.Builder builder = null;
|
||||
com.example.ClassTwo.Builder builder2 = null;
|
||||
throw new com.example.ClassOne.MyException();
|
||||
}
|
||||
|
||||
public class Builder extends com.example.ClassTwo.Builder {
|
||||
}
|
||||
|
||||
public static class MyException extends Exception { }
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user