35
35
import java .util .Date ;
36
36
import java .util .HashSet ;
37
37
import java .util .Iterator ;
38
+ import java .util .Map ;
38
39
import java .util .Random ;
39
40
import java .util .Set ;
40
41
import java .util .TreeMap ;
@@ -476,11 +477,28 @@ public String getErrorMessage(StackTraceElement[] elements) {
476
477
return sb .toString ();
477
478
}
478
479
480
+ public record LeekScriptPosition (int file , int line ) {}
481
+
482
+ public LeekScriptPosition getCurrentLeekScriptPosition () {
483
+ for (StackTraceElement element : Thread .currentThread ().getStackTrace ()) {
484
+ if (element .getClassName ().startsWith ("AI_" )) {
485
+ var mapping = getLineMapping (element .getLineNumber ());
486
+ if (mapping != null ) {
487
+ var files = getErrorFilesID ();
488
+ var f = mapping .getAI ();
489
+ int file = f < files .length ? files [f ] : 0 ;
490
+ return new LeekScriptPosition (file , mapping .getLeekScriptLine ());
491
+ }
492
+ }
493
+ }
494
+ return null ;
495
+ }
496
+
479
497
public String getErrorMessage (Throwable e ) {
480
498
return getErrorMessage (e .getStackTrace ());
481
499
}
482
500
483
- protected String getErrorLocalisation (int javaLine ) {
501
+ protected LineMapping getLineMapping (int javaLine ) {
484
502
if (mLinesMapping .isEmpty () && this .filesLines != null && this .filesLines .exists ()) {
485
503
try (Stream <String > stream = Files .lines (this .filesLines .toPath ())) {
486
504
stream .forEach (l -> {
@@ -490,7 +508,11 @@ protected String getErrorLocalisation(int javaLine) {
490
508
} catch (IOException e ) {}
491
509
thisObject = getAIString ();
492
510
}
493
- var lineMapping = mLinesMapping .get (javaLine );
511
+ return mLinesMapping .get (javaLine );
512
+ }
513
+
514
+ protected String getErrorLocalisation (int javaLine ) {
515
+ var lineMapping = getLineMapping (javaLine );
494
516
if (lineMapping != null ) {
495
517
var files = getErrorFiles ();
496
518
var f = lineMapping .getAI ();
@@ -639,6 +661,8 @@ else if (type == AILog.STANDARD)
639
661
640
662
protected String [] getErrorFiles () { return null ; }
641
663
664
+ protected int [] getErrorFilesID () { return null ; }
665
+
642
666
protected String getAIString () { return "" ; }
643
667
644
668
public Object runIA () throws LeekRunException {
0 commit comments