Class LocationBasedInternalName

java.lang.Object
org.ek9lang.compiler.support.LocationBasedInternalName

public final class LocationBasedInternalName extends Object
Generates deterministic internal names using SHA-256 hashing.

Two variants are provided:

  • generate(String, String, IToken, String...) — includes relative source file name, line and position in the hash. Use when the declaration point is stable (e.g. aspect proxy register statements that are in user code, not shifted by compiler directives).
  • generate(String, String...) — uses only semantic context strings. Use when line numbers may shift (e.g. dynamic functions where @IR directives inserted above shift the declaration line).

Both produce stable names across compilations (unlike UUID-based names). Callers must pass a relative source name (not an absolute path) to ensure consistent hashes across different build environments.

  • Method Details

    • generate

      public static String generate(String prefix, String relativeSourceName, IToken sourceToken, String... additionalContext)
      Generate a deterministic internal name from a relative source file and token location. Includes the relative source file name, line number, and character position in the hash.
      Parameters:
      prefix - The name prefix (e.g. "_AspectProxy_")
      relativeSourceName - The relative source file path (not absolute, for environment stability)
      sourceToken - The source token providing line and position
      additionalContext - Optional additional strings to include in the hash
      Returns:
      A deterministic name like _AspectProxy_A1B2C3...
    • generate

      public static String generate(String prefix, String... context)
      Generate a deterministic internal name from semantic context only. Does NOT include line numbers, so names remain stable when source lines shift (e.g. when @IR directives are added above the declaration).
      Parameters:
      prefix - The name prefix (e.g. "_Function_")
      context - One or more context strings that uniquely identify the construct (e.g. source file name, enclosing function FQN, super function name)
      Returns:
      A deterministic name like _Function_A1B2C3...