@@ -53,10 +53,6 @@ public static void main(String... args) throws IOException {
53
53
compiler .getTask (null , fileManager , diagnosticsCollector , options , null , compilationUnits );
54
54
boolean success = task .call ();
55
55
for (Diagnostic <? extends JavaFileObject > diagnostic : diagnosticsCollector .getDiagnostics ()) {
56
-
57
- LineNumberReader reader = new LineNumberReader (new StringReader (diagnostic .getSource ().getCharContent (true ).toString ()));
58
- String line = reader .lines ().skip (diagnostic .getLineNumber () - 1 ).limit (1 ).findAny ().get ();
59
-
60
56
String type = null ;
61
57
switch (diagnostic .getKind ()) {
62
58
case ERROR :
@@ -73,21 +69,34 @@ public static void main(String... args) throws IOException {
73
69
continue ;
74
70
}
75
71
76
- System .err .println (String .format ("%s:%d: %s: %s\n %s\n %" +diagnostic .getColumnNumber ()+"s" ,
77
- diagnostic .getSource ().getName (),
78
- diagnostic .getLineNumber (),
79
- diagnostic .getKind ().name ().toLowerCase (),
80
- diagnostic .getMessage (null ),
81
- line ,
82
- "^"
83
- ));
72
+ if (diagnostic .getLineNumber () >= 0 && diagnostic .getColumnNumber () >= 0 ) {
73
+ LineNumberReader reader = new LineNumberReader (new StringReader (diagnostic .getSource ().getCharContent (true ).toString ()));
74
+ String line = reader .lines ().skip (diagnostic .getLineNumber () - 1 ).limit (1 ).findAny ().get ();
75
+
76
+ System .err .println (String .format ("%s:%d: %s: %s\n %s\n %" +diagnostic .getColumnNumber ()+"s" ,
77
+ diagnostic .getSource ().getName (),
78
+ diagnostic .getLineNumber (),
79
+ diagnostic .getKind ().name ().toLowerCase (),
80
+ diagnostic .getMessage (null ),
81
+ line ,
82
+ "^"
83
+ ));
84
+ } else {
85
+ System .err .println (String .format ("%s: %s: %s" ,
86
+ diagnostic .getSource ().getName (),
87
+ diagnostic .getKind ().name ().toLowerCase (),
88
+ diagnostic .getMessage (null )
89
+ ));
90
+ }
84
91
85
- System .out .println (String .format ("CG> annotate --type \" %s\" --file \" %s\" --position \" %s\" --message \" %s\" " ,
86
- type ,
87
- diagnostic .getSource ().getName (),
88
- diagnostic .getLineNumber ()+":" +diagnostic .getColumnNumber (),
89
- diagnostic .getMessage (null ).replaceAll ("\" " ,"\\ \" " )
90
- ));
92
+ if (files .contains (diagnostic .getSource ().getName ())) {
93
+ System .out .println (String .format ("CG> annotate --type \" %s\" --file \" %s\" --position \" %s\" --message \" %s\" " ,
94
+ type ,
95
+ diagnostic .getSource ().getName (),
96
+ diagnostic .getLineNumber ()+":" +diagnostic .getColumnNumber (),
97
+ diagnostic .getMessage (null ).replaceAll ("\" " ,"\\ \" " )
98
+ ));
99
+ }
91
100
}
92
101
resultCode = success ? 0 : 1 ;
93
102
}
0 commit comments