Python: add default implementation of getName() and deprecate it

This commit is contained in:
Erik Krogh Kristensen
2022-03-07 11:13:32 +01:00
parent e721094182
commit a1769f8036
4 changed files with 9 additions and 6 deletions

View File

@@ -154,8 +154,11 @@ abstract class Container extends @container {
*/
string toString() { result = this.getAbsolutePath() }
/** Gets the name of this container */
abstract string getName();
/**
* Gets the name of this container.
* DEPRECATED: Use `getAbsolutePath` instead.
*/
deprecated string getName() { result = this.getAbsolutePath() }
/**
* Gets the relative path of this file or folder from the root folder of the
@@ -327,7 +330,7 @@ abstract class Container extends @container {
* paths. The list of paths is composed of the paths passed to the extractor and
* `sys.path`.
*/
predicate isImportRoot(int n) { this.getName() = import_path_element(n) }
predicate isImportRoot(int n) { this.getAbsolutePath() = import_path_element(n) }
/** Holds if this folder is the root folder for the standard library. */
predicate isStdLibRoot(int major, int minor) {

View File

@@ -184,7 +184,7 @@ class PackageObject extends ModuleObject {
Location getLocation() { none() }
override predicate hasLocationInfo(string path, int bl, int bc, int el, int ec) {
path = this.getPath().getName() and
path = this.getPath().getAbsolutePath() and
bl = 0 and
bc = 0 and
el = 0 and

View File

@@ -259,7 +259,7 @@ predicate file_consistency(string clsname, string problem, string what) {
exists(Container f |
clsname = f.getAQlClass() and
uniqueness_error(count(f.toString()), "toString", problem) and
what = "file " + f.getName()
what = "file " + f.getAbsolutePath()
)
}

View File

@@ -4,7 +4,7 @@ predicate of_interest(ControlFlowNode n, int line) {
exists(Location l, File f | l = n.getLocation() |
line = l.getStartLine() and
f = l.getFile() and
f.getName().matches("%test.py%") and
f.getAbsolutePath().matches("%test.py%") and
exists(Comment c |
c.getLocation().getStartLine() < line and
c.getLocation().getFile() = f