How to get Eclipse Console to hyperlink text to source code files?

前端 未结 7 1779
生来不讨喜
生来不讨喜 2020-12-09 10:37

In Code: System.out.println(\"myPackage.MyClass\");

In Eclipse Console: myPackage.MyClass.myMethod

I want to click on the output (myPackage.MyClass.myM

相关标签:
7条回答
  • 2020-12-09 11:38

    Here's a simple wrapper method based on everyone else's answers that can be used anywhere to get a string formatted so that the Eclipse console will link to the line in any file where getSourceCodeLine() is called. I also discovered that printing to System.err in Eclipse will be shown in red.

    public static String getSourceCodeLine() {
        // An index of 1 references the calling method
        StackTraceElement ste = new Throwable().getStackTrace()[1]; 
        return "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")";
    }
    
    public static void main( String[] args )
        System.out.println("Here's a link to " + getSourceCodeLine());
        System.err.println("And a red link to " + getSourceCodeLine());
    }
    
    0 讨论(0)
提交回复
热议问题