1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team |
---|
2 | // |
---|
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this |
---|
4 | // software and associated documentation files (the "Software"), to deal in the Software |
---|
5 | // without restriction, including without limitation the rights to use, copy, modify, merge, |
---|
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
---|
7 | // to whom the Software is furnished to do so, subject to the following conditions: |
---|
8 | // |
---|
9 | // The above copyright notice and this permission notice shall be included in all copies or |
---|
10 | // substantial portions of the Software. |
---|
11 | // |
---|
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
---|
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
---|
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
---|
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
---|
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
17 | // DEALINGS IN THE SOFTWARE. |
---|
18 | |
---|
19 | using System; |
---|
20 | using System.Collections.Generic; |
---|
21 | using System.Diagnostics; |
---|
22 | using System.Linq; |
---|
23 | |
---|
24 | namespace ICSharpCode.NRefactory.CSharp.Resolver |
---|
25 | { |
---|
26 | /// <summary> |
---|
27 | /// Resolver logging helper. |
---|
28 | /// Wraps System.Diagnostics.Debug so that resolver-specific logging can be enabled/disabled on demand. |
---|
29 | /// (it's a huge amount of debug spew and slows down the resolver quite a bit) |
---|
30 | /// </summary> |
---|
31 | static class Log |
---|
32 | { |
---|
33 | const bool logEnabled = false; |
---|
34 | #if __MonoCS__ |
---|
35 | [Conditional("MCS_DEBUG")] |
---|
36 | #else |
---|
37 | [Conditional(logEnabled ? "DEBUG" : "LOG_DISABLED")] |
---|
38 | #endif |
---|
39 | internal static void WriteLine(string text) |
---|
40 | { |
---|
41 | Debug.WriteLine(text); |
---|
42 | } |
---|
43 | |
---|
44 | #if __MonoCS__ |
---|
45 | [Conditional("MCS_DEBUG")] |
---|
46 | #else |
---|
47 | [Conditional(logEnabled ? "DEBUG" : "LOG_DISABLED")] |
---|
48 | #endif |
---|
49 | internal static void WriteLine(string format, params object[] args) |
---|
50 | { |
---|
51 | Debug.WriteLine(format, args); |
---|
52 | } |
---|
53 | |
---|
54 | #if __MonoCS__ |
---|
55 | [Conditional("MCS_DEBUG")] |
---|
56 | #else |
---|
57 | [Conditional(logEnabled ? "DEBUG" : "LOG_DISABLED")] |
---|
58 | #endif |
---|
59 | internal static void WriteCollection<T>(string text, IEnumerable<T> lines) |
---|
60 | { |
---|
61 | #if DEBUG |
---|
62 | T[] arr = lines.ToArray(); |
---|
63 | if (arr.Length == 0) { |
---|
64 | Debug.WriteLine(text + "<empty collection>"); |
---|
65 | } else { |
---|
66 | Debug.WriteLine(text + (arr[0] != null ? arr[0].ToString() : "<null>")); |
---|
67 | for (int i = 1; i < arr.Length; i++) { |
---|
68 | Debug.WriteLine(new string(' ', text.Length) + (arr[i] != null ? arr[i].ToString() : "<null>")); |
---|
69 | } |
---|
70 | } |
---|
71 | #endif |
---|
72 | } |
---|
73 | |
---|
74 | #if __MonoCS__ |
---|
75 | [Conditional("MCS_DEBUG")] |
---|
76 | #else |
---|
77 | [Conditional(logEnabled ? "DEBUG" : "LOG_DISABLED")] |
---|
78 | #endif |
---|
79 | public static void Indent() |
---|
80 | { |
---|
81 | Debug.Indent(); |
---|
82 | } |
---|
83 | |
---|
84 | #if __MonoCS__ |
---|
85 | [Conditional("MCS_DEBUG")] |
---|
86 | #else |
---|
87 | [Conditional(logEnabled ? "DEBUG" : "LOG_DISABLED")] |
---|
88 | #endif |
---|
89 | public static void Unindent() |
---|
90 | { |
---|
91 | Debug.Unindent(); |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|