Class Attribute
- java.lang.Object
-
- net.sourceforge.pmd.lang.rule.xpath.Attribute
-
public final class Attribute extends Object
Represents an XPath attribute of a specific node. Attributes know their name, the node they wrap, and have access to their value.Two attributes are equal if they have the same name and their parent nodes are equal.
Note that attributes do not support just any type, but a restricted set of value types that can be mapped to XPath types. The exact supported types are not specified, but include at least Java primitives and String.
- See Also:
Node.getXPathAttributesIterator()
-
-
Constructor Summary
Constructors Constructor Description Attribute(@NonNull Node parent, @NonNull String name, @NonNull MethodHandle handle, @NonNull Method method)
Creates a new attribute belonging to the given node using its accessor.Attribute(@NonNull Node parent, @NonNull String name, @Nullable String value)
Creates a new attribute belonging to the given node using its string value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
@NonNull String
getName()
Return the name of the attribute (without leading @ sign).@NonNull Node
getParent()
Return the node that owns this attribute.@NonNull String
getStringValue()
Return the string value of the attribute.Type
getType()
Gets the generic type of the value of this attribute.Object
getValue()
Return the value of the attribute.int
hashCode()
boolean
isDeprecated()
Return whether this attribute was deprecated.String
toString()
-
-
-
Constructor Detail
-
Attribute
public Attribute(@NonNull Node parent, @NonNull String name, @NonNull MethodHandle handle, @NonNull Method method)
Creates a new attribute belonging to the given node using its accessor.- Parameters:
handle
- A method handle, used to fetch the attribute.method
- The method corresponding to the method handle. This is used to perform reflective queries, eg to find annotations on the attribute getter, but only the method handle is ever invoked.
-
-
Method Detail
-
getType
public Type getType()
Gets the generic type of the value of this attribute.
-
getName
public @NonNull String getName()
Return the name of the attribute (without leading @ sign).
-
getParent
public @NonNull Node getParent()
Return the node that owns this attribute.
-
isDeprecated
public boolean isDeprecated()
Return whether this attribute was deprecated. This is the case if the getter has the annotationDeprecated
orDeprecatedAttribute
.
-
getValue
public Object getValue()
Return the value of the attribute. This may return null. The getter is invoked at most once.
-
getStringValue
public @NonNull String getStringValue()
Return the string value of the attribute. If the getter returned null, then return the empty string (which is a falsy value in XPath). Otherwise, return a string representation of the value (e.g. withObject.toString()
, but this is not guaranteed).
-
-