In Code: System.out.println("myPackage.MyClass");
In Eclipse Console: myPackage.MyClass.myMethod
I want to click on the output (myPackage.MyClass.myMethod) in Console and it directly shows the corresponding method, similar to what happens for exception stack traces. Any Idea?
In eclipse, you can paste the link to a comment, hold down control and click it. If you want to be able to just press it without holding anything down, go to Window -> Preferences -> General -> Editors -> Text Editors -> Hyperlinking, then click on URL and remove the modifier key, click apply, click ok and you're done!
The first method is to tell Eclipse to save console output to a file. For that, go to Run → Debug Configurations on Eclipse menu. Then under Standard Input and Output section, click on checkbox next to File: , and choose the name of output file to use.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With