-
Notifications
You must be signed in to change notification settings - Fork 354
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
Partial support for parsing XML namespaces #3925
Partial support for parsing XML namespaces #3925
Conversation
Remove duplicate NonNull; see package-info.java Validate argument not literal Apply formatter
Thanks for getting this started @ammachado ! I've also tagged @knutwannheden for review since we're adding methods in the |
rewrite-xml/src/main/java/org/openrewrite/xml/internal/XmlNamespaceUtils.java
Outdated
Show resolved
Hide resolved
Once merged we can revisit these recipes in rewrite-migrate-java: |
# Conflicts: # rewrite-xml/src/test/java/org/openrewrite/xml/ChangeNamespaceValueTest.java
rewrite-xml/src/main/java/org/openrewrite/xml/ChangeNamespaceValue.java
Outdated
Show resolved
Hide resolved
if (this.root == root) { | ||
return this; | ||
} | ||
Map<String, String> namespaces = XmlNamespaceUtils.extractNamespaces(root.getAttributes()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of extracting the namespaces here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we need this back in to later support namespace lookup for particular elements?
For example, using the test file, and wanting to look for the XPath /client/conduitSelector
with the http://cxf.apache.org/jaxws
namespace:
<jaxws:client name="{http://cxf.apache.org/hello_world_soap_http}SoapPort" createdFromAPI="true" xmlns:jaxws="http://cxf.apache.org/jaxws">
<jaxws:conduitSelector>
<bean class="org.apache.cxf.endpoint.DeferredConduitSelector"/>
</jaxws:conduitSelector>
</jaxws:client>
…alue.java Co-authored-by: Knut Wannheden <[email protected]>
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.xml.internal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is returned from tree.Xml perhaps we should not have this class in an internal package?
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
public class XmlNamespaceUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a separate utils class, could this be methods on Namespaces instead you think?
@Value | ||
public class Namespaces { | ||
|
||
Map<String, String> namespaces = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A mutable map here might lead to problems with our immutability convention and detecting changes.
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
public class XmlNamespaceUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could be methods on the Namespaces
class for easier discoverability.
public Namespaces add(String prefix, String uri) { | ||
namespaces.put(prefix, uri); | ||
return this; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespaces
should be immutable like other parts of the LST
It seems like the recipes included in this PR are possible already without introducing new public API surface area in the form of this |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Got rid of Namespaces class as it is mostly a thin wrapper around Map Merge XmlNamespaceUtils into Xml When you control the definition of the type creating a "utils" class for it makes those methods harder for users to discover than if they were defined on the class itself Moved unit test to use AssertJ assertions to be consistent with our other tests Removed Namespaces field from XPathMatcher because it was unused Sentence-cased recipe metadata
* Partial support for parsing XML namespaces * Adding namespace resolution * Missing license header * Adding recipes to search namespace URIs/prefixes * Namespace shortcut methods on \'Xml.Document\' * Change implementation to rely only on attributes * Javadocs and cleanup * Rename XmlNamespaceUtils & minor polish Remove duplicate NonNull; see package-info.java Validate argument not literal Apply formatter * Fix namespace search on XML hierarchy * `ChangeNamespaceValue` now updates the `schemaLocation` attribute * Consider namespaces on `SemanticallyEqual`. * Suggestions from code review. * Update rewrite-xml/src/main/java/org/openrewrite/xml/ChangeNamespaceValue.java Co-authored-by: Knut Wannheden <[email protected]> * Revert namespace comparison changes in `SemanticallyEqual`. * Adding a Namespaces abstraction * Add support for wildcard and local-name() * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix `Namespaces` mutability * Adding an iterator implementation for `Namespaces` * Replace `NotNull` with OpenRewrite's `NonNull` * Polish. Got rid of Namespaces class as it is mostly a thin wrapper around Map Merge XmlNamespaceUtils into Xml When you control the definition of the type creating a "utils" class for it makes those methods harder for users to discover than if they were defined on the class itself Moved unit test to use AssertJ assertions to be consistent with our other tests Removed Namespaces field from XPathMatcher because it was unused Sentence-cased recipe metadata --------- Co-authored-by: Knut Wannheden <[email protected]> Co-authored-by: Knut Wannheden <[email protected]> Co-authored-by: Evie Lau <[email protected]> Co-authored-by: Evie Lau <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Sam Snyder <[email protected]>
What's changed?
Partial support for #3919, including namespace parsing and resolution
What's your motivation?
Anything in particular you'd like reviewers to focus on?
No
Anyone you would like to review specifically?
No
Have you considered any alternatives or workarounds?
No
Any additional context
No
Checklist