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 · 1 comment
Open
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
@timtebeek timtebeek moved this to Backlog in OpenRewrite Jan 8, 2025
@timtebeek
Copy link
Contributor

Thanks for the suggestion! This still seems reasonable to me. As a bit of context we tend to have the LST elements merely represent the underlying structure, while we use higher level constructs like visitors and traits to make it easier to manipulate the underlying elements. That then also means there's less of a need to evolve the LST elements, which helps backwards compatibility with our serialization. Not sure how that work out exactly in this case, but perhaps it's good to explore two or more options briefly.

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: Backlog
Development

No branches or pull requests

2 participants