Document Attribute

This commit is contained in:
Clément Fournier
2018-06-10 03:08:56 +02:00
parent 9aacc4d206
commit bf466b8b84

View File

@ -14,6 +14,10 @@ import java.util.logging.Logger;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
/** /**
* Represents an XPath attribute of a specific node.
* Attributes know their name, the node they wrap,
* and have access to their value.
*
* @author daniels * @author daniels
*/ */
public class Attribute { public class Attribute {
@ -22,20 +26,23 @@ public class Attribute {
private static final Logger LOG = Logger.getLogger(Attribute.class.getName()); private static final Logger LOG = Logger.getLogger(Attribute.class.getName());
private static final ConcurrentMap<String, Boolean> DETECTED_DEPRECATED_ATTRIBUTES = new ConcurrentHashMap<>(); private static final ConcurrentMap<String, Boolean> DETECTED_DEPRECATED_ATTRIBUTES = new ConcurrentHashMap<>();
private static final Object[] EMPTY_OBJ_ARRAY = new Object[0]; private static final Object[] EMPTY_OBJ_ARRAY = new Object[0];
private Node parent; private Node parent;
private String name; private String name;
private Method method; private Method method;
private Object value; private Object value;
private String stringValue; private String stringValue;
/** Creates a new attribute belonging to the given node using its accessor. */
public Attribute(Node parent, String name, Method m) { public Attribute(Node parent, String name, Method m) {
this.parent = parent; this.parent = parent;
this.name = name; this.name = name;
this.method = m; this.method = m;
} }
/** Creates a new attribute belonging to the given node using its string value. */
public Attribute(Node parent, String name, String value) { public Attribute(Node parent, String name, String value) {
this.parent = parent; this.parent = parent;
this.name = name; this.name = name;
@ -43,6 +50,16 @@ public class Attribute {
this.stringValue = value; this.stringValue = value;
} }
public String getName() {
return name;
}
public Node getParent() {
return parent;
}
public Object getValue() { public Object getValue() {
if (value != null) { if (value != null) {
return value; return value;
@ -71,11 +88,7 @@ public class Attribute {
if (this.value == null) { if (this.value == null) {
v = getValue(); v = getValue();
} }
if (v == null) { stringValue = v == null ? "" : String.valueOf(v);
stringValue = "";
} else {
stringValue = String.valueOf(v);
}
return stringValue; return stringValue;
} }
@ -83,14 +96,6 @@ public class Attribute {
return parent.getXPathNodeName() + "/@" + name; return parent.getXPathNodeName() + "/@" + name;
} }
public String getName() {
return name;
}
public Node getParent() {
return parent;
}
@Override @Override
public String toString() { public String toString() {
return name + ':' + getValue() + ':' + parent; return name + ':' + getValue() + ':' + parent;