package ch.usi.dag.dislreserver.msg.analyze;

import java.lang.reflect.Method;
import java.util.List;

public class AnalysisInvocation {

	private Method analysisMethod;
	private Object analysisInstance;
	private List<Object> args;
	
	public AnalysisInvocation(Method analysisMethod, Object analysisInstance,
			List<Object> args) {
		super();
		this.analysisMethod = analysisMethod;
		this.analysisInstance = analysisInstance;
		this.args = args;
	}

	public void invoke() {
		
		try {
			analysisMethod.invoke(analysisInstance, args.toArray());
		}
		catch(Exception e) {
			
			// reports error during analysis
			
			Throwable cause = e.getCause();
			
			System.err.println("DiSL-RE analysis exception: "
					+ cause.getMessage());
			
			cause.printStackTrace();
		}
	}
}

@@ -225,17 +225,16 @@
 %3E args;%0A
-%09
 %0A%09public
@@ -252,17 +252,21 @@
 vocation
-(
+ (%0A%09%09
 Method a
@@ -307,17 +307,16 @@
 ance,%0A%09%09
-%09
 List%3CObj
@@ -324,16 +324,18 @@
 ct%3E args
+%0A%09
 ) %7B%0A%09%09su
@@ -472,16 +472,14 @@
 voke
+ 
 () %7B%0A
-%09%09%0A
 %09%09tr
@@ -506,16 +506,17 @@
 d.invoke
+ 
 (analysi
@@ -547,20 +547,26 @@
 ));%0A
-%09%09%7D
 %0A%09%09
+%7D 
 catch
-(
+ (final 
 Exce
@@ -576,20 +576,16 @@
 on e) %7B%0A
-%09%09%09%0A
 %09%09%09// re
@@ -588,17 +588,16 @@
 / report
-s
  error d
@@ -610,24 +610,37 @@
 analysis
-%0A%09%09%09%0A%09%09%09
+ invocation%0A%09%09%09final 
 Throwabl
@@ -663,100 +663,260 @@
 ause
+ 
 ();%0A%09%09%09
-%0A%09%09%09System.err.println(%22DiSL-RE analysis exception: %22%0A%09%09%09%09%09+ cause.getMessage());
+final String message = cause.getMessage ();%0A%0A%09%09%09System.err.format (%0A%09%09%09%09%22DiSL-RE: exception in analysis %25s.%25s(): %25s%22,%0A%09%09%09%09analysisMethod.getDeclaringClass ().getName (),%0A%09%09%09%09analysisMethod.getName (),%0A%09%09%09%09(message != null) ? message : %22%22
 %0A%09%09%09
+);%0A
 %0A%09%09%09

include analysis method name in case of exceptions during analysis method invocations