1

I am using a MessageConsole in Eclipse to display output information. The output is formatted into Error 1 - (MyClass.java:10), which is expected to generate a clickable link to code (MyClass.java line 10, in this case), since the console should be able to parse the pattern (FileName.java:LineNumber) automatically as suggested in this post.

However, it failed to work this way. But when I use System.out.println() to output this pattern directly in the plugin Eclipse, the link can be generated.

I also considered the possibility of multiple consoles in the plugin, but streaming the patterned text to other consoles did not work either. Any insights?

My code is like below:

ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
MessageConsole myConsole = new MessageConsole( name, null );
conMan.addConsoles( new IConsole[]{myConsole} );
MessageConsoleStream out = myConsole.newMessageStream();
out.println("Error 1 - (MyClass.java:10)");
Community
  • 1
  • 1
Aliu
  • 99
  • 9

1 Answers1

2

Matching for Java code links is only done for consoles which have the javaStackTraceConsole console type.

So you can use the org.eclipse.ui.console.consolePatternMatchListeners extension point to define your own pattern matcher to do the same thing for your console.

Or you can use the:

public MessageConsole(String name, String consoleType, ImageDescriptor imageDescriptor, boolean autoLifecycle)

constructor to specify the console type for your console to match the existing matchers.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • 1
    Thanks. I ended up using the messageConsole.addPatternMatchListener to do the trick, as suggest by you. I also tried the constructor approach and gave the consoleType argument a value of "javaStackTraceConsole". It won't work because the MessageConsole cannot be cast to JavaStrackTraceConsole. – Aliu Jun 28 '16 at 14:20