Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xml.Tag should provide a method to read a specific attribute value #4844

Open
bmuschko opened this issue Jan 3, 2025 · 0 comments
Open

Xml.Tag should provide a method to read a specific attribute value #4844

bmuschko opened this issue Jan 3, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@bmuschko
Copy link
Contributor

bmuschko commented Jan 3, 2025

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

@bmuschko bmuschko added the enhancement New feature or request label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant