How to get Eclipse Console to hyperlink text to source code files?
Maybe this is clear to other people, but I found the other answers confusing, although correct. The eclipse console parses the pattern (FileName.java:lineNumber) to be a link to that line in that file:
(MyFile.java:2)
As the other answers point out, there are many ways to output this to the console. Location in the line does not matter, it is just a pattern match. As Colin Smith shows, log4j PatternLayout can use (%F:%L)
to get the file name and line number. To get the file name and line number programmatically see this question.
The question asks about linking to a method and I believe you could use the consolePatternMatchListeners method recommended by Tonny Madsen and described in more detail in this question.
The hyperlinking for exception stack traces is based on the file name and line number given at the end of the line. E.g.
Stack trace:
org.eclipse.jface.internal.databinding.provisional.BindingException: string property does not have a read method.
at org.eclipse.jface.internal.databinding.internal.beans.JavaBeanObservableValue.doGetValue(JavaBeanObservableValue.java:102)
at org.eclipse.jface.internal.databinding.internal.beans.JavaBeanObservableValue.setValue(JavaBeanObservableValue.java:83)
For the first stack trace, it is at line 102 in the file JavaBeanObservableValue.java
. The file is searched after in the current class path so if you have multiple classes with the same name, the first is always found...
With other words, if you want to add extended hyperlinking based on your example, you need to extend the console view a bit...
...which can be done with the org.eclipse.ui.console.consolePatternMatchListeners
extension point. It is pretty easy to use this extension point and by looking at the example from JDT, you should be able to get your example to work without too much work...