11using System ;
22using System . Linq ;
3+ using System . Xml ;
4+ using System . Xml . XPath ;
35
46namespace MonoDroid . Generation
57{
@@ -31,25 +33,67 @@ public class Report
3133
3234 public static void Error ( int errorCode , string format , params object [ ] args )
3335 {
34- Error ( errorCode , null , format , args ) ;
36+ Error ( errorCode , null , null , - 1 , - 1 , format , args ) ;
3537 }
36-
37- public static void Error ( int errorCode , Exception innerException , string format , params object [ ] args )
38+
39+ public static void Error ( int errorCode , string sourceFile , int line , int column , string format , params object [ ] args )
3840 {
39- throw new BindingGeneratorException ( errorCode , string . Format ( format , args ) , innerException ) ;
41+ Error ( errorCode , null , sourceFile , line , column , format , args ) ;
42+ }
43+
44+ public static void Error ( int errorCode , Exception innerException , string format , params object [ ] args )
45+ {
46+ Error ( errorCode , innerException , null , - 1 , - 1 , format , args ) ;
47+ }
48+
49+ public static void Error ( int errorCode , Exception innerException , XPathNavigator nav , string format , params object [ ] args )
50+ {
51+ var hn = nav as IHasXmlNode ;
52+ var baseUri = hn != null ? hn . GetNode ( ) . OwnerDocument . BaseURI : nav . BaseURI ;
53+ Uri uri ;
54+ string file = Uri . TryCreate ( baseUri , UriKind . Absolute , out uri ) ? uri . LocalPath : null ;
55+ IXmlLineInfo li = nav as IXmlLineInfo ;
56+ li = li != null && li . HasLineInfo ( ) ? li : null ;
57+ Error ( errorCode , innerException , file , li != null ? li . LineNumber : - 1 , li != null ? li . LinePosition : - 1 , format , args ) ;
58+ }
59+
60+ public static void Error ( int errorCode , Exception innerException , string sourceFile , int line , int column , string format , params object [ ] args )
61+ {
62+ throw new BindingGeneratorException ( errorCode , sourceFile , line , column , string . Format ( format , args ) , innerException ) ;
4063 }
4164
4265 public static void Warning ( int verbosity , int errorCode , string format , params object [ ] args )
4366 {
4467 Warning ( verbosity , errorCode , null , format , args ) ;
4568 }
69+
70+ public static void Warning ( int verbosity , int errorCode , Exception innerException , XPathNavigator nav , string format , params object [ ] args )
71+ {
72+ var hn = nav as IHasXmlNode ;
73+ var baseUri = hn != null ? hn . GetNode ( ) . OwnerDocument . BaseURI : nav . BaseURI ;
74+ Uri uri ;
75+ string file = Uri . TryCreate ( baseUri , UriKind . Absolute , out uri ) ? uri . LocalPath : null ;
76+ IXmlLineInfo li = nav as IXmlLineInfo ;
77+ li = li != null && li . HasLineInfo ( ) ? li : null ;
78+ Warning ( verbosity , errorCode , innerException , file , li != null ? li . LineNumber : - 1 , li != null ? li . LinePosition : - 1 , format , args ) ;
79+ }
80+
81+ public static void Warning ( int verbosity , int errorCode , string sourceFile , int line , int column , string format , params object [ ] args )
82+ {
83+ Warning ( verbosity , errorCode , null , sourceFile , line , column , format , args ) ;
84+ }
85+
86+ public static void Warning ( int verbosity , int errorCode , Exception innerException , string format , params object [ ] args )
87+ {
88+ Warning ( verbosity , errorCode , innerException , null , - 1 , - 1 , format , args ) ;
89+ }
4690
47- public static void Warning ( int verbosity , int errorCode , Exception innerException , string format , params object [ ] args )
91+ public static void Warning ( int verbosity , int errorCode , Exception innerException , string sourceFile , int line , int column , string format , params object [ ] args )
4892 {
4993 if ( verbosity > ( Verbosity ?? 0 ) )
5094 return ;
5195 string supp = innerException != null ? " For details, see verbose output." : null ;
52- Console . Error . WriteLine ( Format ( false , errorCode , format , args ) + supp ) ;
96+ Console . Error . WriteLine ( Format ( false , errorCode , sourceFile , line , column , format , args ) + supp ) ;
5397 if ( innerException != null )
5498 Console . Error . WriteLine ( innerException ) ;
5599 }
@@ -60,10 +104,16 @@ public static void Verbose (int verbosity, string format, params object[] args)
60104 return ;
61105 Console . Error . WriteLine ( format , args ) ;
62106 }
107+
108+ public static string Format ( bool error , int errorCode , string format , params object [ ] args )
109+ {
110+ return Format ( error , errorCode , null , - 1 , - 1 , format , args ) ;
111+ }
63112
64- public static string Format ( bool error , int errorCode , string format , params object [ ] args )
113+ public static string Format ( bool error , int errorCode , string sourceFile , int line , int column , string format , params object [ ] args )
65114 {
66- return string . Format ( "{0}{1} BG{2:X04}: " , "" /* origin? */ , error ? "error" : "warning" , errorCode ) +
115+ var origin = sourceFile != null ? sourceFile + ( line > 0 ? column > 0 ? $ "({ line } , { column } )" : $ "({ line } )" : null ) + ' ' : null ;
116+ return string . Format ( "{0}{1} BG{2:X04}: " , origin , error ? "error" : "warning" , errorCode ) +
67117 string . Format ( format , args ) ;
68118 }
69119 }
@@ -75,7 +125,11 @@ public BindingGeneratorException (int errorCode, string message)
75125 {
76126 }
77127 public BindingGeneratorException ( int errorCode , string message , Exception innerException )
78- : base ( Report . Format ( true , errorCode , message ) , innerException )
128+ : this ( errorCode , null , - 1 , - 1 , message , innerException )
129+ {
130+ }
131+ public BindingGeneratorException ( int errorCode , string sourceFile , int line , int column , string message , Exception innerException )
132+ : base ( Report . Format ( true , errorCode , sourceFile , line , column , message ) , innerException )
79133 {
80134 }
81135 }
0 commit comments