Skip to content

Commit

Permalink
[refactor] Swap arguments for internal consistency purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Jul 29, 2023
1 parent 8e805dd commit 585cde5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 4 additions & 6 deletions exist-core/src/main/java/org/exist/xquery/ModuleContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,17 @@ public class ModuleContext extends XQueryContext {
private static final Logger LOG = LogManager.getLogger(ModuleContext.class);

private XQueryContext parentContext;
private String modulePrefix;
private String moduleNamespace;
private String modulePrefix;
private final String location;

public ModuleContext(final XQueryContext parentContext, final String modulePrefix, final String moduleNamespace,
final String location) {
public ModuleContext(final XQueryContext parentContext, final String moduleNamespace, final String modulePrefix, final String location) {
super(parentContext != null ? parentContext.db : null,
parentContext != null ? parentContext.getConfiguration() : null,
null,
false);

this.modulePrefix = modulePrefix;
this.moduleNamespace = moduleNamespace;
this.modulePrefix = modulePrefix;
this.location = location;

setParentContext(parentContext);
Expand Down Expand Up @@ -196,7 +194,7 @@ public void updateContext(final XQueryContext from) {

@Override
public XQueryContext copyContext() {
final ModuleContext ctx = new ModuleContext(parentContext, modulePrefix, moduleNamespace, location);
final ModuleContext ctx = new ModuleContext(parentContext, moduleNamespace, modulePrefix, location);
copyFields(ctx);
try {
ctx.declareNamespace(modulePrefix, moduleNamespace);
Expand Down
18 changes: 9 additions & 9 deletions exist-core/src/main/java/org/exist/xquery/XQueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public Optional<ExistRepository> getRepository() {
// use the resolved file or return null
// build a module object from the file
final Source src = new FileSource(resolved, false);
return compileOrBorrowModule(prefix, namespace, "", src);
return compileOrBorrowModule(namespace, prefix, "", src);
}

/**
Expand Down Expand Up @@ -2516,7 +2516,7 @@ public void mapModule(final String namespace, final XmldbURI uri) {
}

final Source moduleSource = new DBSource(getBroker().getBrokerPool(), (BinaryDocument) sourceDoc, true);
return compileOrBorrowModule(prefix, namespaceURI, location, moduleSource);
return compileOrBorrowModule(namespaceURI, prefix, location, moduleSource);

} catch (final PermissionDeniedException e) {
throw moduleLoadException("Permission denied to read module source from location hint URI '" + location + ".", location, e);
Expand Down Expand Up @@ -2553,7 +2553,7 @@ public void mapModule(final String namespace, final XmldbURI uri) {
throw moduleLoadException("Permission denied to read module source from location hint URI '" + location + ".", location, e);
}

return compileOrBorrowModule(prefix, namespaceURI, location, moduleSource);
return compileOrBorrowModule(namespaceURI, prefix, location, moduleSource);
}

protected XPathException moduleLoadException(final String message, final String moduleLocation)
Expand Down Expand Up @@ -2585,18 +2585,18 @@ public Iterator<String> getMappedModuleURIs() {
/**
* Compile of borrow an already compile module from the cache.
*
* @param prefix the module namespace prefix
* @param namespaceURI the module namespace URI
* @param prefix the module namespace prefix
* @param location the location hint
* @param source the source for the module
*
* @return the module or null
*
* @throws XPathException if the module could not be loaded (XQST0059) or compiled (XPST0003)
*/
private ExternalModule compileOrBorrowModule(final String prefix, final String namespaceURI, final String location,
private ExternalModule compileOrBorrowModule(final String namespaceURI, final String prefix, final String location,
final Source source) throws XPathException {
final ExternalModule module = compileModule(prefix, namespaceURI, location, source);
final ExternalModule module = compileModule(namespaceURI, prefix, location, source);
if (module != null) {
addModule(module.getNamespaceURI(), module);
declareModuleVars(module);
Expand All @@ -2607,14 +2607,14 @@ private ExternalModule compileOrBorrowModule(final String prefix, final String n
/**
* Compile an XQuery Module
*
* @param prefix the namespace prefix of the module.
* @param namespaceURI the namespace URI of the module.
* @param prefix the namespace prefix of the module.
* @param location the location of the module
* @param source the source of the module.
* @return The compiled module, or null if the source is not a module
* @throws XPathException if the module could not be loaded (XQST0059) or compiled (XPST0003)
*/
private @Nullable ExternalModule compileModule(final String prefix, String namespaceURI, final String location,
private @Nullable ExternalModule compileModule(String namespaceURI, final String prefix, final String location,
final Source source) throws XPathException {
if (LOG.isDebugEnabled()) {
LOG.debug("Loading module from {}", location);
Expand All @@ -2635,7 +2635,7 @@ private ExternalModule compileOrBorrowModule(final String prefix, final String n
}

final ExternalModuleImpl modExternal = new ExternalModuleImpl(namespaceURI, prefix);
final XQueryContext modContext = new ModuleContext(this, prefix, namespaceURI, location);
final XQueryContext modContext = new ModuleContext(this, namespaceURI, prefix, location);
modExternal.setContext(modContext);
final XQueryLexer lexer = new XQueryLexer(modContext, reader);
final XQueryParser parser = new XQueryParser(lexer);
Expand Down

0 comments on commit 585cde5

Please sign in to comment.