Record Class StringInterpolationPart

java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.data.StringInterpolationPart
Record Components:
type - The part type (LITERAL or VARIABLE)
value - For LITERAL: the text content; for VARIABLE: the variable name
originalType - For VARIABLE: the type before $ conversion (null for LITERAL)

public record StringInterpolationPart(StringInterpolationPart.PartType type, String value, String originalType) extends Record
Represents a single part of an interpolated string.

Parts are either:

  • LITERAL - Fixed text, value contains the literal string
  • VARIABLE - String variable reference, value contains variable name

For VARIABLE parts, originalType records the type before String conversion. This metadata supports debugging, analysis, and potential Phase 12 optimizations (e.g., reusing a previously converted String if the source hasn't been mutated).

  • Constructor Details

    • StringInterpolationPart

      public StringInterpolationPart(StringInterpolationPart.PartType type, String value, String originalType)
      Creates an instance of a StringInterpolationPart record class.
      Parameters:
      type - the value for the type record component
      value - the value for the value record component
      originalType - the value for the originalType record component
  • Method Details

    • literal

      public static StringInterpolationPart literal(String text)
      Create a literal text part.
      Parameters:
      text - The literal text content
      Returns:
      A new LITERAL part
    • variable

      public static StringInterpolationPart variable(String variableName, String originalType)
      Create a variable reference part.
      Parameters:
      variableName - The name of the String variable
      originalType - The type before conversion (for analysis/debugging)
      Returns:
      A new VARIABLE part
    • isLiteral

      public boolean isLiteral()
      Check if this is a literal part.
      Returns:
      true if this part contains literal text
    • isVariable

      public boolean isVariable()
      Check if this is a variable part.
      Returns:
      true if this part references a String variable
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • type

      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • value

      public String value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • originalType

      public String originalType()
      Returns the value of the originalType record component.
      Returns:
      the value of the originalType record component