openrewrite / openrewrite/rewrite
Xml.Tag should provide a method to read a specific attribute value
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
What problem are you trying to solve?
I am reading information from a Xml.Tag via the XmlIsoVisitor.visitTag method. I have to read the value of a specific attribute.
Right now, this is harder than it needs to be.
List<Xml.Attribute> attributes = tag.getAttributes();
String attributeValue = getAttributeValue(attributes, "myattribute");
private String getAttributeValue(List<Xml.Attribute> attributes, String attributeName) {
Optional<Xml.Attribute> attribute = attributes.stream().filter(a -> attributeName.equals(a.getKeyAsString())).findFirst();
return attribute.map(Xml.Attribute::getValueAsString).orElse(null);
}
Describe the solution you'd like
I'd like to see a convenience method that does something similar to getAttributeValue. Is this something you'd consider?
Have you considered any alternatives or workarounds?
Yes, see method above.
Additional context
N/A
Are you interested in [contributing this feature to OpenRewrite]
Yes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the Xml.Tag and Xml.Attribute implementations and inspect how XmlIsoVisitor.visitTag exposes tag data. Compare the requested convenience lookup with the existing attribute accessors, then add coverage for finding an attribute by name and for a missing attribute. Done means callers can read a specific attribute value without implementing their own stream lookup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100