Package org.sonar.python.semantic
Class SymbolUtils
java.lang.Object
org.sonar.python.semantic.SymbolUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<Expression> assignmentsLhs(AssignmentStatement assignmentStatement) boundNamesFromExpression(Tree tree) static booleancanBeAnOverridingMethod(FunctionSymbol functionSymbol) static intfirstParameterOffset(FunctionSymbol functionSymbol, boolean isStaticCall) flattenAmbiguousSymbols(Set<Symbol> symbols) static StringfullyQualifiedModuleName(String packageName, String fileName) static Optional<FunctionSymbol> getFirstAlternativeIfEqualArgumentNames(List<FunctionSymbol> alternatives) static List<FunctionSymbol> getFunctionSymbols(Symbol symbol) static StringgetModuleFileName(String fileName) static Optional<FunctionSymbol> getOverriddenMethod(FunctionSymbol functionSymbol) static List<FunctionSymbol> getOverriddenMethods(FunctionSymbol functionSymbol) static PythonTypegetPythonType(SymbolV2 symbol) static booleanisEqualParameterCountAndNames(List<FunctionSymbol> alternatives) static booleanisPrivateName(String name) static PathpathOf(PythonFile pythonFile) static StringpythonPackageName(File file, String projectBaseDirAbsolutePath) Computes the Python package name for a file using legacy __init__.py detection only.static StringpythonPackageName(File file, List<String> packageRoots, String projectBaseDirAbsolutePath) Computes the Python package name for a file using package roots.static StringqualifiedNameOrEmpty(CallExpression callExpression) symbolV2ToSymbolV1(SymbolV2 symbolV2) static SymboltypeshedSymbolWithFQN(String fullyQualifiedName)
-
Method Details
-
getModuleFileName
-
fullyQualifiedModuleName
-
assignmentsLhs
-
boundNamesFromExpression
-
pythonPackageName
public static String pythonPackageName(File file, List<String> packageRoots, String projectBaseDirAbsolutePath) Computes the Python package name for a file using package roots.If the file is under one of the provided package roots, computes the package name by converting the relative path from the root to the file's parent directory into a dotted package name. This supports PEP 420 namespace packages (directories without __init__.py).
If the file is not under any package root, falls back to the legacy behavior of walking up the directory tree and checking for __init__.py files.
- Parameters:
file- the Python source filepackageRoots- list of absolute paths to package root directoriesprojectBaseDirAbsolutePath- the project base directory absolute path (used for fallback)- Returns:
- the dotted package name, or empty string if not in a package
-
pythonPackageName
Computes the Python package name for a file using legacy __init__.py detection only. This method is kept for backward compatibility.- Parameters:
file- the Python source fileprojectBaseDirAbsolutePath- the project base directory absolute path- Returns:
- the dotted package name, or empty string if not in a package
-
pathOf
-
firstParameterOffset
- Returns:
- the offset between parameter position and argument position: 0 if there is no implicit first parameter (self, cls, etc...) 1 if there is an implicit first parameter -1 if unknown (intent is not clear from context)
-
getOverriddenMethod
-
getOverriddenMethods
-
getFunctionSymbols
-
getFirstAlternativeIfEqualArgumentNames
public static Optional<FunctionSymbol> getFirstAlternativeIfEqualArgumentNames(List<FunctionSymbol> alternatives) -
isEqualParameterCountAndNames
-
canBeAnOverridingMethod
-
typeshedSymbolWithFQN
-
flattenAmbiguousSymbols
-
isPrivateName
-
qualifiedNameOrEmpty
-
getPythonType
-
symbolV2ToSymbolV1
-