changeset 772:bffbef96ca6d

add public static methods to LuanException for building luan stack traces
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 23 Aug 2016 00:23:36 -0600
parents dcae4dd718b8
children 47add8eeb513
files core/src/luan/LuanException.java
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
diff -r dcae4dd718b8 -r bffbef96ca6d core/src/luan/LuanException.java
--- a/core/src/luan/LuanException.java	Wed Aug 17 18:12:19 2016 -0600
+++ b/core/src/luan/LuanException.java	Tue Aug 23 00:23:36 2016 -0600
@@ -108,9 +108,8 @@
 		return sw.toString();
 	}
 
-	private List<StackTraceElement> justLuan() {
+	public static List<StackTraceElement> justLuan(StackTraceElement[] orig) {
 		List<StackTraceElement> list = new ArrayList<StackTraceElement>();
-		StackTraceElement[] orig = getStackTrace();
 		for( int i=0; i<orig.length; i++ ) {
 			StackTraceElement ste = orig[i];
 			if( !ste.getClassName().startsWith("luan.impl.EXP") )
@@ -122,14 +121,20 @@
 		return list;
 	}
 
+	public static String toString(StackTraceElement ste) {
+		StringBuilder sb = new StringBuilder();
+		sb.append( ste.getFileName() ).append( " line " ).append( ste.getLineNumber() );
+		String method = ste.getMethodName();
+		if( !method.equals("doCall") )
+			sb.append( " in function '" ).append( method.substring(1) ).append( "'" );
+		return sb.toString();
+	}
+
 	public String getLuanStackTraceString() {
 		StringBuilder sb = new StringBuilder();
 		sb.append( getMessage() );
-		for( StackTraceElement ste : justLuan() ) {
-			sb.append( "\n\t" ).append( ste.getFileName() ).append( " line " ).append( ste.getLineNumber() );
-			String method = ste.getMethodName();
-			if( !method.equals("doCall") )
-				sb.append( " in function '" ).append( method.substring(1) ).append( "'" );
+		for( StackTraceElement ste : justLuan(getStackTrace()) ) {
+			sb.append( "\n\t" ).append( toString(ste) );
 		}
 		Throwable cause = getCause();
 		if( cause != null )
@@ -139,7 +144,7 @@
 
 	public static String currentSource() {
 		LuanException ex = new LuanException("currentSource");
-		List<StackTraceElement> st = ex.justLuan();
+		List<StackTraceElement> st = ex.justLuan(ex.getStackTrace());
 		return st.isEmpty() ? null : st.get(0).getFileName();
 	}