From bf466b8b84837500b1342ca7abc48bbb46894a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 10 Jun 2018 03:08:56 +0200 Subject: [PATCH] Document Attribute --- .../pmd/lang/ast/xpath/Attribute.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java index bbfa026ec5..d419185eff 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java @@ -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 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;