Package org.sonar.python.tree
Class TreeUtils
java.lang.Object
org.sonar.python.tree.TreeUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic RegularArgumentargumentByKeyword(String keyword, List<Argument> arguments) static StringdecoratorNameFromExpression(Expression expression) dottedNameToPartFqn(DottedName dottedName) static intfindIndentationSize(Tree tree) static TreefirstAncestor(Tree tree, Predicate<Tree> predicate) static TreefirstAncestorOfKind(Tree tree, Tree.Kind... kinds) firstChild(Tree tree, Predicate<Tree> filter) static Stream<Expression>flattenTuples(Expression expression) fullyQualifiedNameFromExpression(Expression expression) fullyQualifiedNameFromQualifiedExpression(QualifiedExpression qualifiedExpression) static ClassSymbolgetClassSymbolFromDef(ClassDef classDef) static FunctionSymbolgetFunctionSymbolFromDef(FunctionDef functionDef) getParentClassesFQN(ClassDef classDef) getSymbolFromTree(Tree tree) static Comparator<Tree>static TokenStatements can have a separator like semicolon.static booleanhasDescendant(Tree tree, Predicate<Tree> predicate) static booleanisBooleanLiteral(Tree tree) static booleanisDecoratorWithFQN(Decorator decorator, String fullyQualifiedName) static booleanisFunctionWithGivenDecoratorFQN(Tree tree, String decoratorFQN) static LocationInFilelocationInFile(Tree tree, String fileId) static StringnameFromExpression(Expression expression) nameFromExpressionOrQualifiedExpression(Expression expression) static StringnameFromQualifiedExpression(QualifiedExpression qualifiedExpression) nameFromQualifiedOrCallExpression(Expression expression) nonTupleParameters(FunctionDef functionDef) nonWhitespaceTokens(Tree tree) static RegularArgumentnthArgumentOrKeyword(int argPosition, String keyword, List<Argument> arguments) static Optional<RegularArgument>nthArgumentOrKeywordOptional(int argPosition, String keyword, List<Argument> arguments) positionalParameters(FunctionDef functionDef) stringValueFromNameOrQualifiedExpression(Expression expression) Extracts the string value from a name or qualified expression.toInstanceOfMapper(Class<T> castToClass) toOptionalInstanceOf(Class<T> castToClass, Tree tree) toOptionalInstanceOfMapper(Class<T> castToClass) static List<FunctionDef>topLevelFunctionDefs(ClassDef classDef) Collects all top-level function definitions within a class def.toStreamInstanceOfMapper(Class<T> castToClass) static StringtreeToString(Tree tree, boolean renderMultiline)
-
Method Details
-
firstAncestor
-
firstAncestorOfKind
-
groupAssignmentByParentStatementList
-
getTreeByPositionComparator
-
tokens
-
nonWhitespaceTokens
-
hasDescendant
-
flattenTuples
-
getSymbolFromTree
-
getClassSymbolFromDef
-
getParentClassesFQN
-
getFunctionSymbolFromDef
@CheckForNull public static FunctionSymbol getFunctionSymbolFromDef(@Nullable FunctionDef functionDef) -
nonTupleParameters
-
positionalParameters
-
topLevelFunctionDefs
Collects all top-level function definitions within a class def. It is used to discover methods defined within "strange" constructs, such asclass A: if p: def f(self): ... -
findIndentationSize
-
argumentByKeyword
@CheckForNull public static RegularArgument argumentByKeyword(String keyword, List<Argument> arguments) -
nthArgumentOrKeyword
@CheckForNull public static RegularArgument nthArgumentOrKeyword(int argPosition, String keyword, List<Argument> arguments) -
nthArgumentOrKeywordOptional
public static Optional<RegularArgument> nthArgumentOrKeywordOptional(int argPosition, String keyword, List<Argument> arguments) -
isBooleanLiteral
-
nameFromExpression
-
nameFromQualifiedOrCallExpression
-
nameFromExpressionOrQualifiedExpression
-
nameFromQualifiedExpression
-
decoratorNameFromExpression
-
asyncTokenOfEnclosingFunction
-
isFunctionWithGivenDecoratorFQN
-
isDecoratorWithFQN
-
fullyQualifiedNameFromQualifiedExpression
public static Optional<String> fullyQualifiedNameFromQualifiedExpression(QualifiedExpression qualifiedExpression) -
fullyQualifiedNameFromExpression
-
locationInFile
-
getTreeSeparatorOrLastToken
Statements can have a separator like semicolon. When handling ranges we want to take them into account. -
toInstanceOfMapper
-
toOptionalInstanceOfMapper
-
toOptionalInstanceOf
-
toStreamInstanceOfMapper
-
firstChild
-
treeToString
-
dottedNameToPartFqn
-
stringValueFromNameOrQualifiedExpression
Extracts the string value from a name or qualified expression. Returns empty Optional for expressions that are not simple names or chains of qualified expressions.
-