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