1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Rook
.Compiler
.Services
.Default
21 /// Default Error Report outputs to Console
23 public class ErrorReport
: IErrorReport
25 private int errorCount
, warningCount
;
26 private int enableLevel
= 0;
32 #region IErrorReport Members
44 public void Error(String filename
, LexicalPosition pos
, String contents
, params object[] args
)
46 if (enableLevel
> 0) return;
52 ErrorWriter
.Write("{0}:{1}\terror: ", filename
, pos
.Line
);
56 ErrorWriter
.Write("{0}:{1},{2}\terror: ", filename
, pos
.Line
, pos
.Column
);
59 ErrorWriter
.WriteLine(contents
, args
);
62 public void Error(String contents
, params object[] args
)
64 if (enableLevel
> 0) return;
68 ErrorWriter
.Write("compiler error: ");
69 ErrorWriter
.WriteLine(contents
, args
);
72 public void Warning(String filename
, LexicalPosition pos
, Severity severity
, String contents
, params object[] args
)
74 if (enableLevel
> 0) return;
80 OutWriter
.Write("{0}:{1}\twarning: ", filename
, pos
.Line
);
84 OutWriter
.Write("{0}:{1},{2}\twarning: ", filename
, pos
.Line
, pos
.Column
);
87 OutWriter
.WriteLine(contents
, args
);
90 public void Warning(String contents
, params object[] args
)
92 if (enableLevel
> 0) return;
96 OutWriter
.Write("warning: ");
97 OutWriter
.WriteLine(contents
, args
);
100 public bool HasErrors
102 get { return errorCount != 0; }
105 public bool HasWarnings
107 get { return warningCount != 0; }
112 protected virtual TextWriter OutWriter
114 get { return Console.Out; }
117 protected virtual TextWriter ErrorWriter
119 get { return Console.Error; }