1616package com .intellij .java .compiler .impl ;
1717
1818import com .intellij .java .compiler .impl .javaCompiler .FileObject ;
19+ import consulo .compiler .CompileContext ;
1920import consulo .compiler .CompilerMessageCategory ;
21+ import consulo .localize .LocalizeValue ;
2022import consulo .util .lang .StringUtil ;
2123
2224import java .util .ArrayList ;
2325import java .util .List ;
2426
2527public abstract class OutputParser {
26- protected final List <ParserAction > myParserActions = new ArrayList <ParserAction >(10 );
27-
28- public interface Callback {
29- String getNextLine ();
30- String getCurrentLine ();
31- void pushBack (String line );
32- void setProgressText (String text );
33- void fileProcessed (String path );
34- void fileGenerated (FileObject path );
35- void message (CompilerMessageCategory category , String message , String url , int lineNum , int columnNum );
36- }
37-
38- public boolean processMessageLine (Callback callback ) {
39- final String line = callback .getNextLine ();
40- if (line == null ) {
41- return false ;
42- }
43- // common statistics messages (javac & jikes)
44- for (ParserAction action : myParserActions ) {
45- if (action .execute (line , callback )) {
46- return true ;
47- }
48- }
49- if (StringUtil .startsWithChar (line , '[' ) && StringUtil .endsWithChar (line , ']' )) {
50- // at this point any meaningful output surrounded with '[' and ']' characters is processed, so
51- // suppress messages like "[total 4657ms]" or "[search path for source files: []]"
52- return true ;
53- }
54- return false ;
55- }
28+ protected final List <ParserAction > myParserActions = new ArrayList <>(10 );
29+
30+ public interface Callback {
31+ String getNextLine ();
32+
33+ String getCurrentLine ();
34+
35+ void pushBack (String line );
36+
37+ void setProgressText (LocalizeValue text );
38+
39+ void fileProcessed (String path );
40+
41+ void fileGenerated (FileObject path );
5642
57- protected static void addMessage (Callback callback , CompilerMessageCategory type , String message ) {
58- if (message == null || message .trim ().length () == 0 ) {
59- return ;
43+ default CompileContext .MessageBuilder newInfo (LocalizeValue message ) {
44+ return newMessage (CompilerMessageCategory .INFORMATION , message );
45+ }
46+
47+ default CompileContext .MessageBuilder newInfo (String message ) {
48+ return newInfo (LocalizeValue .of (message ));
49+ }
50+
51+ default CompileContext .MessageBuilder newWarning (LocalizeValue message ) {
52+ return newMessage (CompilerMessageCategory .WARNING , message );
53+ }
54+
55+ default CompileContext .MessageBuilder newWarning (String message ) {
56+ return newWarning (LocalizeValue .of (message ));
57+ }
58+
59+ default CompileContext .MessageBuilder newError (LocalizeValue message ) {
60+ return newMessage (CompilerMessageCategory .ERROR , message );
61+ }
62+
63+ default CompileContext .MessageBuilder newError (String message ) {
64+ return newError (LocalizeValue .of (message ));
65+ }
66+
67+ CompileContext .MessageBuilder newMessage (CompilerMessageCategory category , LocalizeValue message );
68+
69+ default CompileContext .MessageBuilder newMessage (CompilerMessageCategory category , String message ) {
70+ return newMessage (category , LocalizeValue .of (message ));
71+ }
6072 }
61- addMessage (callback , type , message , null , -1 , -1 );
62- }
6373
64- protected static void addMessage (Callback callback , CompilerMessageCategory type , String text , String url , int line , int column ){
65- callback .message (type , text , url , line , column );
66- }
74+ public boolean processMessageLine (Callback callback ) {
75+ String line = callback .getNextLine ();
76+ if (line == null ) {
77+ return false ;
78+ }
79+ // common statistics messages (javac & jikes)
80+ for (ParserAction action : myParserActions ) {
81+ if (action .execute (line , callback )) {
82+ return true ;
83+ }
84+ }
85+ if (StringUtil .startsWithChar (line , '[' ) && StringUtil .endsWithChar (line , ']' )) {
86+ // at this point any meaningful output surrounded with '[' and ']' characters is processed, so
87+ // suppress messages like "[total 4657ms]" or "[search path for source files: []]"
88+ return true ;
89+ }
90+ return false ;
91+ }
6792
68- public boolean isTrimLines () {
69- return true ;
70- }
93+ public boolean isTrimLines () {
94+ return true ;
95+ }
7196}
0 commit comments