Skip to content

Commit

Permalink
Following #309: reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Bruchez committed Mar 29, 2022
1 parent beb6694 commit ea8d375
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,19 @@ object SimplePath {
def sibling(test: Test): Seq[NodeInfo] = precedingSibling(test) ++ followingSibling(test)

def namespaces = find(Axis.NAMESPACE, AnyTest)
def namespaceMappings = namespaces map (n => n.getLocalPart -> n.getStringValue)
def namespaceMappings = {

// 2022-03-28: We use the namespace axis to get namespaces, and this doesn't work on an attribute node,
// apparently. Unclear if this is by design or not, but the test below addresses that by looking at the
// parent element if needed.
val ns =
this match {
case n if n.isAttribute => n.parentUnsafe.namespaces
case n => n.namespaces
}

ns map (n => n.getLocalPart -> n.getStringValue)
}

def prefixesForURI(uri: String) = prefixesForURIImpl(uri, this)
def nonEmptyPrefixesForURI(uri: String) = prefixesForURI(uri) filter (_ != "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,7 @@ trait ControlOps extends ResourcesOps {
def renameNodeContent(elemOrAtt: NodeInfo, avt: Boolean): Unit =
FormRunnerRename.replaceSingleVarReference(
xpathString = elemOrAtt.stringValue,
namespaceMapping = NamespaceMapping(elemOrAtt match {
case n if n.isAttribute => n.parentUnsafe.namespaceMappings.toMap
case n => n.namespaceMappings.toMap
}),
namespaceMapping = NamespaceMapping(elemOrAtt.namespaceMappings.toMap),
functionLibrary = inScopeContainingDocument.partAnalysis.functionLibrary,
avt = avt,
oldName = oldName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ trait FormRunnerComponents {
def replaceVarReferencesWithFunctionCalls(elemOrAtt: NodeInfo, avt: Boolean): String =
FormRunnerRename.replaceVarReferencesWithFunctionCalls(
elemOrAtt.stringValue,
NamespaceMapping(elemOrAtt match {
case n if n.isAttribute => n.parentUnsafe.namespaceMappings.toMap
case n => n.namespaceMappings.toMap
}),
NamespaceMapping(elemOrAtt.namespaceMappings.toMap),
FormRunnerFunctionLibrary,
avt,
name => s"(fr:control-string-value('$name'))"
Expand Down

0 comments on commit ea8d375

Please sign in to comment.