2005-01-22 Ben Maurer <bmaurer@ximian.com>
authorBen Maurer <benm@mono-cvs.ximian.com>
Sat, 22 Jan 2005 23:53:30 +0000 (23:53 -0000)
committerBen Maurer <benm@mono-cvs.ximian.com>
Sat, 22 Jan 2005 23:53:30 +0000 (23:53 -0000)
* options.cs: Make things public.

* outline.cs: Use the Options class, rather than being passed
binding flags.
(.ctor): Add Options param
(OutlineType): remove bindingFlags param
(DefaultFlags): Get the correct binding flags
(ShowMember): Return true if we should show this member given the
Options. Way too long due to MSFT stupidity.
(OutlineType): call the above.

* monop.cs (Main): Don't fiddle with binding flags ourselves.

svn path=/trunk/mcs/; revision=39367

mcs/tools/monop/ChangeLog
mcs/tools/monop/monop.cs
mcs/tools/monop/options.cs
mcs/tools/monop/outline.cs

index cc06a03d695ad355e2a21e676c579510b7b623d8..f75e162434a9d3e057357a61a5f8436684d8349c 100644 (file)
@@ -1,3 +1,19 @@
+2005-01-22  Ben Maurer  <bmaurer@ximian.com>
+
+       * options.cs: Make things public.
+
+       * outline.cs: Use the Options class, rather than being passed
+       binding flags.
+       (.ctor): Add Options param
+       (OutlineType): remove bindingFlags param
+       (DefaultFlags): Get the correct binding flags
+       (ShowMember): Return true if we should show this member given the
+       Options. Way too long due to MSFT stupidity.
+       (OutlineType): call the above.
+
+       * monop.cs (Main): Don't fiddle with binding flags ourselves.
+       
+
 2005-01-08  John Luke  <john.luke@gmail.com>
 
        * monop.cs: use Options class
index d8ca8278af9aaec4959872e35b8ecb2fab872b3e..8840975980f617b255ed8e93431180196c651720 100644 (file)
@@ -41,10 +41,6 @@ using System.Text;
 
 class MonoP {
        static string assembly;
-       static BindingFlags default_flags = 
-               BindingFlags.Instance |
-               BindingFlags.Static |
-               BindingFlags.Public;
        
        // very common namespaces, all in corlib
        static readonly string [] v_common_ns = {
@@ -267,12 +263,6 @@ class MonoP {
                Options options = new Options ();
                if (!options.ProcessArgs (args))
                        return;
-
-               if (options.ShowPrivate)
-                       default_flags |= BindingFlags.NonPublic;
-
-               if (options.DeclaredOnly)
-                       default_flags |= BindingFlags.DeclaredOnly;
                
                if (options.AssemblyReference != null) {
                        assembly = options.AssemblyReference;
@@ -350,7 +340,7 @@ class MonoP {
                // This gets us nice buffering
                //
                StreamWriter sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);                               
-               new Outline (t, sw).OutlineType (default_flags);
+               new Outline (t, sw, options).OutlineType ();
                sw.Flush ();
 
                if (message != null)
index a4bfe4016b92782a4e2f4228d344c112c1c7e110..a03f2483f4708fc0a4b572942e63b0a0bf23e327 100644 (file)
 
 using System;
 
-internal class Options
+public class Options
 {
-       internal bool DeclaredOnly = false;
-       internal bool Search = false;
-       internal bool ShowPrivate = false;
-       internal string AssemblyReference = null;
-       internal string Type = null;
+       public bool DeclaredOnly = false;
+       public bool Search = false;
+       public bool ShowPrivate = false;
+       public string AssemblyReference = null;
+       public string Type = null;
 
-       internal Options ()
+       public Options ()
        {
        }
 
index bfed3379e642e5686b94e92e0a5accee2224a481..c1207840587e49146654ec89476ecab3f94a2b46 100644 (file)
@@ -37,16 +37,18 @@ using System.IO;
        
 public class Outline {
        
+       Options options;
        IndentedTextWriter o;
        Type t;
        
-       public Outline (Type t, TextWriter output)
+       public Outline (Type t, TextWriter output, Options options)
        {
                this.t = t;
                this.o = new IndentedTextWriter (output, "    ");
+               this.options = options;
        }
 
-       public void OutlineType (BindingFlags flags)
+       public void OutlineType ()
         {
                bool first;
                
@@ -125,7 +127,11 @@ public class Outline {
                
                first = true;
                
-               foreach (ConstructorInfo ci in t.GetConstructors (flags)) {
+               foreach (ConstructorInfo ci in t.GetConstructors (DefaultFlags)) {
+                       
+                       if (! ShowMember (ci))
+                               continue;
+                       
                        if (first)
                                o.WriteLine ();
                        first = false;
@@ -138,7 +144,11 @@ public class Outline {
 
                first = true;
                
-               foreach (MethodInfo m in Comparer.Sort (t.GetMethods (flags))) {
+               foreach (MethodInfo m in Comparer.Sort (t.GetMethods (DefaultFlags))) {
+                       
+                       if (! ShowMember (m))
+                               continue;               
+                       
                        if ((m.Attributes & MethodAttributes.SpecialName) != 0)
                                continue;
                        
@@ -153,7 +163,11 @@ public class Outline {
                
                first = true;
                
-               foreach (MethodInfo m in t.GetMethods (flags)) {
+               foreach (MethodInfo m in t.GetMethods (DefaultFlags)) {
+                       
+                       if (! ShowMember (m))
+                               continue;
+                       
                        if ((m.Attributes & MethodAttributes.SpecialName) == 0)
                                continue;
                        if (!(m.Name.StartsWith ("op_")))
@@ -170,7 +184,11 @@ public class Outline {
 
                first = true;
                
-               foreach (PropertyInfo pi in Comparer.Sort (t.GetProperties (flags))) {
+               foreach (PropertyInfo pi in Comparer.Sort (t.GetProperties (DefaultFlags))) {
+                       
+                       if (! ((pi.CanRead  && ShowMember (pi.GetGetMethod (true))) ||
+                              (pi.CanWrite && ShowMember (pi.GetSetMethod (true)))))
+                               continue;
                        
                        if (first)
                                o.WriteLine ();
@@ -183,7 +201,10 @@ public class Outline {
                
                first = true;
 
-               foreach (FieldInfo fi in t.GetFields (flags)) {
+               foreach (FieldInfo fi in t.GetFields (DefaultFlags)) {
+                       
+                       if (! ShowMember (fi))
+                               continue;
                        
                        if (first)
                                o.WriteLine ();
@@ -196,7 +217,10 @@ public class Outline {
 
                first = true;
                
-               foreach (EventInfo ei in Comparer.Sort (t.GetEvents (flags))) {
+               foreach (EventInfo ei in Comparer.Sort (t.GetEvents (DefaultFlags))) {
+                       
+                       if (! ShowMember (ei.GetAddMethod ()))
+                               continue;
                        
                        if (first)
                                o.WriteLine ();
@@ -209,17 +233,31 @@ public class Outline {
 
                first = true;
 
-               foreach (Type ntype in Comparer.Sort (t.GetNestedTypes (flags))) {
+               foreach (Type ntype in Comparer.Sort (t.GetNestedTypes (DefaultFlags))) {
+                       
+                       if (! ShowMember (ntype))
+                               continue;
                        
                        if (first)
                                o.WriteLine ();
                        first = false;
                        
-                       new Outline (ntype, o).OutlineType (flags);
+                       new Outline (ntype, o, options).OutlineType ();
                }
                
                o.Indent--; o.WriteLine ("}");
        }
+       
+       BindingFlags DefaultFlags {
+               get {
+                       BindingFlags f = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
+                       
+                       if (options.DeclaredOnly)
+                               f |= BindingFlags.DeclaredOnly;
+                       
+                       return f;
+               }
+       }
 
        // FIXME: add other interesting attributes?
        void OutlineAttributes ()
@@ -494,6 +532,50 @@ public class Outline {
                default: return name;
                }
        }
+       
+       bool ShowMember (MemberInfo mi)
+       {
+               if (options.ShowPrivate)
+                       return true;
+               
+               switch (mi.MemberType) {
+               case MemberTypes.Constructor:
+               case MemberTypes.Method:
+                       MethodBase mb = mi as MethodBase;
+               
+                       if (mb.IsFamily || mb.IsPublic || mb.IsFamilyOrAssembly)
+                               return true;
+                       
+                       return false;
+               
+               
+               case MemberTypes.Field:
+                       FieldInfo fi = mi as FieldInfo;
+               
+                       if (fi.IsFamily || fi.IsPublic || fi.IsFamilyOrAssembly)
+                               return true;
+                       
+                       return false;
+               
+               
+               case MemberTypes.NestedType:
+               case MemberTypes.TypeInfo:
+                       Type t = mi as Type;
+               
+                       switch (t.Attributes & TypeAttributes.VisibilityMask){
+                       case TypeAttributes.Public:
+                       case TypeAttributes.NestedPublic:
+                       case TypeAttributes.NestedFamily:
+                       case TypeAttributes.NestedFamORAssem:
+                               return true;
+                       }
+                       
+                       return false;
+               }
+               
+               // What am I !!!
+               return true;
+       }
 }
 
 public class Comparer : IComparer  {