@@ -50,32 +50,39 @@ private String formatDiagnostic(Diagnostic<? extends JavaFileObject> d) {
5050 StringBuilder sb = new StringBuilder ();
5151 String sourceName = d .getSource () == null ? "Unknown Source"
5252 : new File (d .getSource ().getName ()).getName ();
53- sb .append (sourceName ).append (':' ).append (d .getLineNumber ()).append (':' )
54- .append (' ' ).append (d .getKind ().toString ().toLowerCase (Locale .ENGLISH ))
55- .append (':' ).append (' ' ).append (d .getMessage (Locale .ENGLISH ));
5653
54+ boolean appendedSource = false ;
5755 try {
5856 if (d .getSource () != null ) {
5957 CharSequence content = d .getSource ().getCharContent (true );
6058 String [] lines = content .toString ().split ("\r ?\n " );
6159 long lineNo = d .getLineNumber ();
6260 if (lineNo > 0 && lineNo <= lines .length ) {
6361 String line = lines [(int ) lineNo - 1 ];
64- sb .append (System .lineSeparator ()).append (line )
65- .append (System .lineSeparator ());
62+ sb .append (line ).append (System .lineSeparator ());
6663 long col = d .getColumnNumber ();
6764 if (col > 0 ) {
6865 for (int i = 1 ; i < col ; i ++) {
6966 sb .append (' ' );
7067 }
7168 sb .append ('^' );
7269 }
70+ sb .append (System .lineSeparator ());
71+ appendedSource = true ;
7372 }
7473 }
7574 } catch (IOException e ) {
7675 // ignore - if we can't read the source, just return the basic message
7776 }
7877
78+ if (!appendedSource && sb .length () > 0 ) {
79+ sb .append (System .lineSeparator ());
80+ }
81+
82+ sb .append (sourceName ).append (':' ).append (d .getLineNumber ()).append (':' )
83+ .append (' ' ).append (d .getKind ().toString ().toLowerCase (Locale .ENGLISH ))
84+ .append (':' ).append (' ' ).append (d .getMessage (Locale .ENGLISH ));
85+
7986 return sb .toString ();
8087 }
8188}
0 commit comments