Class VariableNameUtils

java.lang.Object
org.openrewrite.java.VariableNameUtils

@Incubating(since="7.25.0") public class VariableNameUtils extends Object
  • 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.GenerationStrategy to 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

      public static String normalizeName(String name)
      Replace accent and diacritics with normalized characters.
      Parameters:
      name - variable name to normalize.
      Returns:
      normalized name.
    • findNamesInScope

      public static Set<String> findNamesInScope(org.openrewrite.Cursor scope)
      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

      public static Set<String> findInheritedNames(J.ClassDeclaration classDeclaration)
      Collects class field names inherited from super classes. Note: Does not currently account for JavaType.Unknown.