Class SectionedBuffers
java.lang.Object
org.ek9lang.cli.SectionedBuffers
Manages sectioned source buffers for the REPL.
Each EK9 section type (type, function, record, trait, class, program) has its own buffer.
Provides functional operations for iterating across all buffers with a unified line numbering scheme.
This class eliminates duplication by providing a single iteration mechanism that can be used for delete, edit, insert, and line number translation operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of a buffer operation that found a match.static final recordSnapshot of all buffers for undo support.static final recordRepresents a section with its buffer and metadata. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Optional<T> applyAtLine(int globalLineNum, BiFunction<SectionedBuffers.Section, Integer, T> operation) Apply an operation at a specific global line number.intcalculateBufferIndex(int actualLineNumber) Calculate the buffer index for a given actual source line number.voidclearAll()Clear all buffers.Create a snapshot of all buffers for undo support.booleandeleteLine(int globalLineNum) Delete a line by its global line number.booleanEdit a line by its global line number.findByGlobalLine(int globalLineNum) Find a buffer location by global line number (1-based).Get all sections in the canonical order for source assembly.getBufferForMode(ReplMode mode) Get the buffer list for a specific mode.intGet the total number of lines across all buffers.booleaninsertLine(int globalLineNum, String text, ReplMode currentMode) Insert a line before the specified global line number.booleanisEmpty()Check if all buffers are empty.voidRestore buffers from a snapshot.
-
Constructor Details
-
SectionedBuffers
public SectionedBuffers()
-
-
Method Details
-
getAllSections
Get all sections in the canonical order for source assembly. -
getBufferForMode
-
findByGlobalLine
Find a buffer location by global line number (1-based). Iterates through all sections in order until the line is found.- Parameters:
globalLineNum- The 1-based global line number- Returns:
- The location if found, empty otherwise
-
applyAtLine
public <T> Optional<T> applyAtLine(int globalLineNum, BiFunction<SectionedBuffers.Section, Integer, T> operation) Apply an operation at a specific global line number. The operation receives the section and index, and returns a result.- Type Parameters:
T- The result type- Parameters:
globalLineNum- The 1-based global line numberoperation- The operation to apply (section, index) -> result- Returns:
- The operation result if line was found, empty otherwise
-
deleteLine
public boolean deleteLine(int globalLineNum) Delete a line by its global line number.- Parameters:
globalLineNum- The 1-based global line number to delete- Returns:
- true if deleted, false if line not found
-
editLine
Edit a line by its global line number.- Parameters:
globalLineNum- The 1-based global line number to editnewText- The new text for the line- Returns:
- true if edited, false if line not found
-
insertLine
Insert a line before the specified global line number. If globalLineNum is one past the last line, appends to the specified mode's buffer.- Parameters:
globalLineNum- The 1-based position to insert beforetext- The text to insertcurrentMode- The current mode (used for append case)- Returns:
- true if inserted, false if line number out of range
-
getTotalLineCount
public int getTotalLineCount()Get the total number of lines across all buffers. -
clearAll
public void clearAll()Clear all buffers. -
isEmpty
public boolean isEmpty()Check if all buffers are empty. -
createSnapshot
Create a snapshot of all buffers for undo support. -
restoreFromSnapshot
Restore buffers from a snapshot. -
calculateBufferIndex
public int calculateBufferIndex(int actualLineNumber) Calculate the buffer index for a given actual source line number.- Parameters:
actualLineNumber- The line number in assembled source- Returns:
- The buffer index, or -1 if not a user line
-