Package org.openrewrite.java
Class VariableNameUtils
java.lang.Object
org.openrewrite.java.VariableNameUtils
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionfindInheritedNames(J.ClassDeclaration classDeclaration) Collects class field names inherited from super classes.findNamesInScope(org.openrewrite.Cursor scope) Find the names of variables that already exist in the scope of a cursor.static StringgenerateVariableName(String baseName, org.openrewrite.Cursor scope, VariableNameUtils.GenerationStrategy strategy) Generates a variable name without namespace conflicts in the scope of a cursor.static StringnormalizeName(String name) Replace accent and diacritics with normalized characters.
-
Method Details
-
generateVariableName
public static String generateVariableName(String baseName, org.openrewrite.Cursor scope, VariableNameUtils.GenerationStrategy strategy) Generates a variable name without namespace conflicts in the scope of a cursor. A JavaSourceFile must be available in the Cursor path to account for all names available in the cursor scope.- Parameters:
baseName- baseName for the variable.scope- The cursor position of a JavaVisitor,TreeVisitor.getCursor().strategy-VariableNameUtils.GenerationStrategyto use if a name already exists with the baseName.- Returns:
- either the baseName if a namespace conflict does not exist or a name generated with the provided strategy.
-
normalizeName
Replace accent and diacritics with normalized characters.- Parameters:
name- variable name to normalize.- Returns:
- normalized name.
-
findNamesInScope
Find the names of variables that already exist in the scope of a cursor. A JavaSourceFile must be available in the Cursor path to account for all names available in the cursor scope.- Parameters:
scope- The cursor position of a JavaVisitor,TreeVisitor.getCursor().- Returns:
- Variable names available in the name scope of the cursor.
-
findInheritedNames
Collects class field names inherited from super classes. Note: Does not currently account forJavaType.Unknown.
-