Lines 70-75
Link Here
|
70 |
* For POI internal use only |
70 |
* For POI internal use only |
71 |
* |
71 |
* |
72 |
* @author Josh Micich |
72 |
* @author Josh Micich |
|
|
73 |
* @author Thies Wellpott (debug output enhancements) |
73 |
*/ |
74 |
*/ |
74 |
public final class WorkbookEvaluator { |
75 |
public final class WorkbookEvaluator { |
75 |
|
76 |
|
Lines 384-397
Link Here
|
384 |
} |
385 |
} |
385 |
throw new RuntimeException("Unexpected cell type (" + cellType + ")"); |
386 |
throw new RuntimeException("Unexpected cell type (" + cellType + ")"); |
386 |
} |
387 |
} |
|
|
388 |
|
389 |
|
390 |
/** |
391 |
* Perform detailed output of formular evaluation for next evaluation only? |
392 |
* Is for developer use only (also developers using POI for their XLS files). |
393 |
* Log-Level WARN is for basic infos, INFO for detailed information. These quite |
394 |
* high levels are used because you have to explicitly enable this specific logging. |
395 |
*/ |
396 |
public static boolean dbgEvaluationOutputForNextEval = false; |
397 |
|
398 |
// special logger for formula evaluation output (because of possibly very large output) |
399 |
private static final POILogger EVAL_LOG = POILogFactory.getLogger("POI.FormulaEval"); |
400 |
// current indent level for evalution; negative value for no output |
401 |
private int dbgEvaluationOutputIndent = -1; |
402 |
|
387 |
// visibility raised for testing |
403 |
// visibility raised for testing |
388 |
/* package */ ValueEval evaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) { |
404 |
/* package */ ValueEval evaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) { |
389 |
|
405 |
|
|
|
406 |
String dbgIndentStr = ""; // always init. to non-null just for defensive avoiding NPE |
407 |
if (dbgEvaluationOutputForNextEval) { |
408 |
// first evaluation call when ouput is desired, so iit. this evaluator instance |
409 |
dbgEvaluationOutputIndent = 1; |
410 |
dbgEvaluationOutputForNextEval = false; |
411 |
} |
412 |
if (dbgEvaluationOutputIndent > 0) { |
413 |
// init. indent string to needed spaces (create as substring vom very long space-only string; |
414 |
// limit indendation for deep recursions) |
415 |
dbgIndentStr = " "; |
416 |
dbgIndentStr = dbgIndentStr.substring(0, Math.min(dbgIndentStr.length(), dbgEvaluationOutputIndent*2)); |
417 |
EVAL_LOG.log(POILogger.WARN, dbgIndentStr |
418 |
+ "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetName() |
419 |
+ "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() |
420 |
+ "): " + Arrays.toString(ptgs).replaceAll("\\Qorg.apache.poi.ss.formula.ptg.\\E", "")); |
421 |
dbgEvaluationOutputIndent++; |
422 |
} |
423 |
|
390 |
Stack<ValueEval> stack = new Stack<ValueEval>(); |
424 |
Stack<ValueEval> stack = new Stack<ValueEval>(); |
391 |
for (int i = 0, iSize = ptgs.length; i < iSize; i++) { |
425 |
for (int i = 0, iSize = ptgs.length; i < iSize; i++) { |
392 |
|
426 |
|
393 |
// since we don't know how to handle these yet :( |
427 |
// since we don't know how to handle these yet :( |
394 |
Ptg ptg = ptgs[i]; |
428 |
Ptg ptg = ptgs[i]; |
|
|
429 |
if (dbgEvaluationOutputIndent > 0) { |
430 |
EVAL_LOG.log(POILogger.INFO, dbgIndentStr + " * ptg " + i + ": " + ptg); |
431 |
} |
395 |
if (ptg instanceof AttrPtg) { |
432 |
if (ptg instanceof AttrPtg) { |
396 |
AttrPtg attrPtg = (AttrPtg) ptg; |
433 |
AttrPtg attrPtg = (AttrPtg) ptg; |
397 |
if (attrPtg.isSum()) { |
434 |
if (attrPtg.isSum()) { |
Lines 497-509
Link Here
|
497 |
} |
534 |
} |
498 |
// logDebug("push " + opResult); |
535 |
// logDebug("push " + opResult); |
499 |
stack.push(opResult); |
536 |
stack.push(opResult); |
|
|
537 |
if (dbgEvaluationOutputIndent > 0) { |
538 |
EVAL_LOG.log(POILogger.INFO, dbgIndentStr + " = " + opResult); |
539 |
} |
500 |
} |
540 |
} |
501 |
|
541 |
|
502 |
ValueEval value = stack.pop(); |
542 |
ValueEval value = stack.pop(); |
503 |
if (!stack.isEmpty()) { |
543 |
if (!stack.isEmpty()) { |
504 |
throw new IllegalStateException("evaluation stack not empty"); |
544 |
throw new IllegalStateException("evaluation stack not empty"); |
505 |
} |
545 |
} |
506 |
return dereferenceResult(value, ec.getRowIndex(), ec.getColumnIndex()); |
546 |
ValueEval result = dereferenceResult(value, ec.getRowIndex(), ec.getColumnIndex()); |
|
|
547 |
if (dbgEvaluationOutputIndent > 0) { |
548 |
EVAL_LOG.log(POILogger.INFO, dbgIndentStr + "finshed eval of " |
549 |
+ new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() |
550 |
+ ": " + result); |
551 |
dbgEvaluationOutputIndent--; |
552 |
if (dbgEvaluationOutputIndent == 1) { |
553 |
// this evaluation is done, reset indent to stop logging |
554 |
dbgEvaluationOutputIndent = -1; |
555 |
} |
556 |
} // if |
557 |
return result; |
558 |
|
507 |
} |
559 |
} |
508 |
|
560 |
|
509 |
/** |
561 |
/** |