Fix spurious warning about deprecated attributes
Because we were evaluating all attributes eagerly, deprecated attributes were reported even without being used. Possibly, performance also took a hit.
This commit is contained in:
@@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
/**
|
||||
@@ -63,8 +64,14 @@ public class Attribute {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/** Returns the most general type that the value may be. */
|
||||
@Experimental
|
||||
public Class<?> getType() {
|
||||
return method == null ? String.class : method.getReturnType();
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
if (value != null) {
|
||||
if (value != null) { // TODO if the method returned null we'll call it again...
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +179,8 @@ public class DocumentNavigator extends DefaultNavigator {
|
||||
Attribute result = null;
|
||||
while (baseIterator.hasNext() && result == null) {
|
||||
Attribute candidate = baseIterator.next();
|
||||
if (!(candidate.getValue() instanceof List)) {
|
||||
// Calling getValue() here would break laziness
|
||||
if (!List.class.isAssignableFrom(candidate.getType())) {
|
||||
result = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user