@@ -78,45 +78,59 @@ public void doReport(dotty.tools.dotc.reporting.Diagnostic dia, Context ctx) {
7878 SourcePosition pos = dia .pos ();
7979 SourceFile src = pos .source ();
8080 position = new Position () {
81- public Optional <java .io .File > sourceFile () {
82- if (!src .exists ()) return Optional .empty ();
83- else return Optional .ofNullable (src .file ().file ());
84- }
8581 public Optional <String > sourcePath () {
86- if (!src .exists ()) return Optional .empty ();
87- else return Optional .ofNullable (src .file ().path ());
82+ if (!src .exists ())
83+ return Optional .empty ();
84+
85+ return Optional .ofNullable (src .file ().path ());
86+ }
87+ public Optional <java .io .File > sourceFile () {
88+ if (!src .exists ())
89+ return Optional .empty ();
90+
91+ return Optional .ofNullable (src .file ().file ());
8892 }
8993 public Optional <Integer > line () {
94+ if (!src .file ().exists ())
95+ return Optional .empty ();
96+
9097 int line = pos .line () + 1 ;
91- if (line == -1 ) return Optional .empty ();
92- else return Optional .of (line );
98+ if (line == -1 )
99+ return Optional .empty ();
100+
101+ return Optional .of (line );
93102 }
94103 public String lineContent () {
104+ if (!src .file ().exists ())
105+ return "" ;
106+
95107 String line = pos .lineContent ();
96108 if (line .endsWith ("\r \n " ))
97109 return line .substring (0 , line .length () - 2 );
98- else if (line .endsWith ("\n " ) || line .endsWith ("\u000c " ))
110+ if (line .endsWith ("\n " ) || line .endsWith ("\u000c " ))
99111 return line .substring (0 , line .length () - 1 );
100- else
101- return line ;
112+
113+ return line ;
102114 }
103115 public Optional <Integer > offset () {
104116 return Optional .of (pos .point ());
105117 }
106118 public Optional <Integer > pointer () {
107- if (!src .exists ()) return Optional .empty ();
108- else return Optional .of (pos .point () - src .startOfLine (pos .point ()));
119+ if (!src .file ().exists ())
120+ return Optional .empty ();
121+
122+ return Optional .of (pos .point () - src .startOfLine (pos .point ()));
109123 }
110124 public Optional <String > pointerSpace () {
111- if (!src .exists ()) return Optional . empty ();
112- else {
113- String lineContent = this . lineContent ();
114- int pointer = this .pointer (). get ();
115- StringBuilder result = new StringBuilder ();
116- for ( int i = 0 ; i < pointer ; i ++)
117- result . append ( lineContent . charAt ( i ) == '\t' ? '\t' : ' ' );
118- return Optional . of ( result . toString () );
119- }
125+ if (!src .file (). exists ())
126+ return Optional . empty ();
127+
128+ String lineContent = this .lineContent ();
129+ int pointer = this . pointer (). get ();
130+ StringBuilder result = new StringBuilder ();
131+ for ( int i = 0 ; i < pointer ; i ++)
132+ result . append ( lineContent . charAt ( i ) == '\t' ? '\t' : ' ' );
133+ return Optional . of ( result . toString ());
120134 }
121135 };
122136 } else {
0 commit comments