-
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
Merged
sambsnyd
merged 32 commits into
openrewrite:main
from
ammachado:add-namespaces-xml-tree
Jun 20, 2024
Merged
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
512d05e
Partial support for parsing XML namespaces
ammachado 7b65a68
Adding namespace resolution
ammachado 9d4c924
Missing license header
ammachado 520a282
Adding recipes to search namespace URIs/prefixes
ammachado 1ec44eb
Namespace shortcut methods on \'Xml.Document\'
ammachado f5a3621
Change implementation to rely only on attributes
ammachado aecc3e6
Javadocs and cleanup
ammachado 385cb7b
Rename XmlNamespaceUtils & minor polish
timtebeek c88e2ae
Fix namespace search on XML hierarchy
ammachado 546b99f
`ChangeNamespaceValue` now updates the `schemaLocation` attribute
ammachado 5d2e2b8
Merge branch 'main' into add-namespaces-xml-tree
ammachado e0e9527
Merge branch 'main' into add-namespaces-xml-tree
timtebeek 436049d
Merge branch 'main' into add-namespaces-xml-tree
ammachado f621398
Consider namespaces on `SemanticallyEqual`.
ammachado 218827b
Suggestions from code review.
ammachado a456198
Update rewrite-xml/src/main/java/org/openrewrite/xml/ChangeNamespaceV…
ammachado b283aa0
Revert namespace comparison changes in `SemanticallyEqual`.
ammachado 5c76231
Merge branch 'main' into add-namespaces-xml-tree
ammachado d1cffc1
Merge branch 'main' into add-namespaces-xml-tree
timtebeek acb7c26
Merge branch 'main' into add-namespaces-xml-tree
ammachado 6fec0b5
Merge branch 'main' into add-namespaces-xml-tree
timtebeek bf3b658
Adding a Namespaces abstraction
ammachado ac084a1
Merge branch 'main' into add-namespaces-xml-tree
evie-lau 326b824
Add support for wildcard and local-name()
evie-lau 50dc26f
Merge branch 'main' into add-namespaces-xml-tree
evie-lau 20e6212
Apply suggestions from code review
timtebeek 69d6772
Fix `Namespaces` mutability
ammachado 527a239
Merge branch 'main' into add-namespaces-xml-tree
timtebeek 2a0212b
Adding an iterator implementation for `Namespaces`
ammachado cd2fcf3
Replace `NotNull` with OpenRewrite's `NonNull`
ammachado c7f84cc
Merge branch 'main' into add-namespaces-xml-tree
sambsnyd e4083b4
Polish.
sambsnyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
rewrite-xml/src/main/java/org/openrewrite/xml/internal/Namespaces.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.xml.internal; | ||
|
||
import lombok.Value; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
@Value | ||
public class Namespaces { | ||
|
||
Map<String, String> namespaces = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
public Namespaces() { | ||
} | ||
|
||
public Namespaces(String prefix, String uri) { | ||
this.namespaces.put(prefix, uri); | ||
} | ||
|
||
public Namespaces(Map<String, String> namespaces) { | ||
this.namespaces.putAll(namespaces); | ||
} | ||
|
||
public Namespaces add(String prefix, String uri) { | ||
Map<String, String> combinedNamespaces = new HashMap<>(namespaces); | ||
combinedNamespaces.put(prefix, uri); | ||
return new Namespaces(combinedNamespaces); | ||
} | ||
|
||
public Namespaces add(Map<String, String> namespaces) { | ||
Map<String, String> combinedNamespaces = new HashMap<>(this.namespaces); | ||
combinedNamespaces.putAll(namespaces); | ||
return new Namespaces(combinedNamespaces); | ||
} | ||
|
||
public Namespaces combine(Namespaces namespaces) { | ||
return add(namespaces.getNamespaces()); | ||
} | ||
|
||
public String get(String prefix) { | ||
return namespaces.get(prefix); | ||
} | ||
|
||
public boolean containsPrefix(String prefix) { | ||
return namespaces.containsKey(prefix); | ||
} | ||
|
||
public boolean containsUri(String uri) { | ||
return namespaces.containsValue(uri); | ||
} | ||
|
||
public Set<Map.Entry<String, String>> entrySet() { | ||
return namespaces.entrySet(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?