Search code examples
javadebuggingreportingrascal

Debug linked Java method


I have some issues with debugging Java code. I have a Rascal module from where I am calling a linked Java method. This Java method contains a couple of System.err.println statements like suggested here: https://github.com/usethesource/rascal/wiki/Error-Reporting. But where are they shown? When I execute the Rascal code from the Rascal debug console and call the linked Java method the messages are not shown. I even flush System.err directly after printing, but no luck. What am I doing wrong here?

Regards, Nico


Solution

  • System.err is hard because Eclipse will hide it if you did not start Eclipse from a commandline console. So you should use evaluator.getStdErr() as suggested on https://github.com/usethesource/rascal/wiki/Error-Reporting.

    First extend your Rascal function header to give access to the evaluator context:

    @reflect{need access to stderr}
    @javaClass{path.to.MyClass}
    java int myFunction(int myParam);
    

    Then change your interface in Java accordingly and retrieve a reference to the error stream:

    public class MyClass {
       public IValue myFunction(IInteger myParam, IEvaluatorContext ctx) {
          ctx.getStdErr().println("Hello Rascal!");
       }
    }