pjfanning opened a new pull request, #1305:
URL: https://github.com/apache/poi/pull/1305

   Lets an evaluator substitute its own `OperationEvaluationContext` subclass 
for the built-in one, so reference resolution (and the other public context 
methods) can be customised without special-casing inside core evaluator code.
   
   Motivation: in #1271, commit 0b65f24 adds `instanceof 
VirtualEvaluationSheet` checks to 
`OperationEvaluationContext.getRefEval`/`getAreaEval` so the standalone 
evaluator can bypass `SheetRangeEvaluator`/`LazyRefEval`. That puts an eager 
`getSheet()` call on the hot path for every user (a fresh `HSSFEvaluationSheet` 
per reference for HSSF) and leaks a package-private type into core dispatch. 
With this hook the standalone engine can install a context subclass that 
returns its `VirtualRefEval`/`VirtualAreaEval` instead, and core stays 
untouched.
   
   Changes:
   - `OperationEvaluationContext` is no longer `final` and gains a `protected` 
copy constructor. That is how a subclass picks up the evaluator's internal 
`EvaluationTracker` (needed for circular-reference detection and dependency 
tracking) without exposing that package-private type.
   - 
`WorkbookEvaluator.setEvaluationContextFactory(UnaryOperator<OperationEvaluationContext>)`
 installs the hook. Every place the evaluator built a context (formula cells, 
name/string formulas, conditional-format formulas, cross-workbook name 
references) now goes through a package-private `createEvaluationContext()` that 
applies the factory. Reachable from user code via 
`BaseFormulaEvaluator._getWorkbookEvaluator()`.
   - With no factory installed there is no change in behaviour or cost.
   
   All changes are binary compatible (dropping `final`, adding a protected 
constructor and two public methods).
   
   Test: `TestEvaluationContextFactory` installs a context that resolves row-0 
references from a backing `ValueEval[]` instead of the sheet — the shape of the 
virtual-sheet use case in #1271 — and checks:
   - `A1+B1` / `SUM(A1:B1)` read from the array while `A5` still reads from the 
sheet; the array can be mutated and re-evaluated; removing the factory restores 
defaults
   - a circular reference outside the virtual row is still reported as 
`#REF!`-style `CIRCULAR_REF` (the copied tracker is shared)
   - `WorkbookEvaluator.evaluate(String, CellReference)` goes through the 
factory too
   - a factory returning `null` fails fast with `IllegalStateException`; an 
identity factory sees the plain default context
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to