JS: Factor out overridden part of PathExpr.getSearchRoot

This commit is contained in:
Asger Feldthaus
2020-05-13 16:34:43 +01:00
parent 5f510878f3
commit 3846f534a8
2 changed files with 13 additions and 3 deletions

View File

@@ -112,7 +112,7 @@ class MainModulePath extends PathExpr, @json_string {
override string getValue() { result = this.(JSONString).getValue() }
override Folder getSearchRoot(int priority) {
override Folder getAdditionalSearchRoot(int priority) {
priority = 0 and
result = pkg.getFile().getParentContainer()
}

View File

@@ -194,8 +194,18 @@ abstract class PathExpr extends Locatable {
Folder getSearchRoot(int priority) {
// We default to the enclosing module's search root, though this may be overridden.
getEnclosingModule().searchRoot(this, result, priority)
or
result = getAdditionalSearchRoot(priority)
}
/**
* INTERNAL. Use `getSearchRoot` instead.
*
* Can be overridden by subclasses of `PathExpr` to provide additional search roots
* without overriding `getSearchRoot`.
*/
Folder getAdditionalSearchRoot(int priority) { none() }
/** Gets the `i`th component of this path. */
string getComponent(int i) { result = getValue().(PathString).getComponent(i) }
@@ -276,8 +286,8 @@ private class ConcatPath extends PathExpr {
)
}
override Folder getSearchRoot(int priority) {
result = this.(AddExpr).getAnOperand().(PathExpr).getSearchRoot(priority)
override Folder getAdditionalSearchRoot(int priority) {
result = this.(AddExpr).getAnOperand().(PathExpr).getAdditionalSearchRoot(priority)
}
}