public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            MethodVisibility visibility = MethodVisibility.Public;

            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration != null)
            {
                IMethodReference   setMethodReference = propertyDeclaration.SetMethod;
                IMethodDeclaration setMethod          = (setMethodReference == null) ? null : setMethodReference.Resolve();

                IMethodReference   getMethodReference = propertyDeclaration.GetMethod;
                IMethodDeclaration getMethod          = (getMethodReference == null) ? null : getMethodReference.Resolve();

                if ((setMethod != null) && (getMethod != null))
                {
                    if (getMethod.Visibility == setMethod.Visibility)
                    {
                        visibility = getMethod.Visibility;
                    }
                }
                else if (setMethod != null)
                {
                    visibility = setMethod.Visibility;
                }
                else if (getMethod != null)
                {
                    visibility = getMethod.Visibility;
                }
            }

            return(visibility);
        }
        public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            IMethodDeclaration getMethod = Helper.GetGetMethod(value);
            IMethodDeclaration setMethod = Helper.GetSetMethod(value);

            MethodVisibility visibility = MethodVisibility.Public;

            if ((setMethod != null) && (getMethod != null))
            {
                if (getMethod.Visibility == setMethod.Visibility)
                {
                    visibility = getMethod.Visibility;
                }
            }
            else if (setMethod != null)
            {
                visibility = setMethod.Visibility;
            }
            else if (getMethod != null)
            {
                visibility = getMethod.Visibility;
            }

            return(visibility);
        }
        public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            MethodVisibility     result = MethodVisibility.Public;
            IPropertyDeclaration propertyDeclaration = value.Resolve();

            if (propertyDeclaration != null)
            {
                IMethodReference   setMethod          = propertyDeclaration.SetMethod;
                IMethodDeclaration methodDeclaration  = setMethod?.Resolve();
                IMethodReference   getMethod          = propertyDeclaration.GetMethod;
                IMethodDeclaration methodDeclaration2 = getMethod?.Resolve();
                if (methodDeclaration != null && methodDeclaration2 != null)
                {
                    if (methodDeclaration2.Visibility == methodDeclaration.Visibility)
                    {
                        result = methodDeclaration2.Visibility;
                    }
                }
                else if (methodDeclaration != null)
                {
                    result = methodDeclaration.Visibility;
                }
                else if (methodDeclaration2 != null)
                {
                    result = methodDeclaration2.Visibility;
                }
            }
            return(result);
        }
            private void __WriteVisibilitySpecifier(MethodVisibility visibility, bool inline)
            {
                switch (visibility)
                {
                case MethodVisibility.PrivateScope:
                    this.__WriteVisibilitySpecifier(AccessSpecifier.PrivateScope, inline);
                    break;

                case MethodVisibility.Private:
                    this.__WriteVisibilitySpecifier(AccessSpecifier.Private, inline);
                    break;

                case MethodVisibility.FamilyAndAssembly:
                    this.__WriteVisibilitySpecifier(AccessSpecifier.PrivateProtected, inline);
                    break;

                case MethodVisibility.Assembly:
                    this.__WriteVisibilitySpecifier(AccessSpecifier.Internal, inline);
                    break;

                case MethodVisibility.Family:
                    this.__WriteVisibilitySpecifier(AccessSpecifier.Protected, inline);
                    break;

                case MethodVisibility.FamilyOrAssembly:
                    this.__WriteVisibilitySpecifier(AccessSpecifier.InternalProtected, inline);
                    break;

                case MethodVisibility.Public:
                    this.__WriteVisibilitySpecifier(AccessSpecifier.Public, inline);
                    break;
                }
            }
 private static void GenerateMethod(StringBuilder sb, MethodVisibility methodVisibility, string methodName, string methodBody)
 {
     sb.AppendLine(@"#line 1 """"");
     sb.AppendFormat("    {0} {1}void {2}", methodVisibility.ToString().ToLowerInvariant(), methodVisibility == MethodVisibility.Private ? "static " : "", methodName);
     sb.AppendLine();
     sb.AppendLine("    {");
     sb.AppendLine(@"#line 1 """"");
     sb.AppendFormat("        {0};", methodBody);
     sb.AppendLine();
     sb.AppendLine("    }");
 }
Beispiel #6
0
 public void WriteVisibility(string instance, MethodVisibility visibility)
 {
     if ((visibility & MethodVisibility.Assembly) != MethodVisibility.PrivateScope)
     {
         Write("{0}.Attributes |= System.CodeDom.MethodVisibility.Assembly", instance);
         WriteEndStatement();
     }
     if ((visibility & MethodVisibility.Family) != MethodVisibility.PrivateScope)
     {
         Write("{0}.Attributes |= System.CodeDom.MethodVisibility.Family", instance);
         WriteEndStatement();
     }
     if ((visibility & MethodVisibility.Private) != MethodVisibility.PrivateScope)
     {
         Write("{0}.Attributes |= System.CodeDom.MethodVisibility.Private", instance);
         WriteEndStatement();
     }
 }
Beispiel #7
0
        /// <summary>
        /// hack to set visibility of events - must be last added as it is a comments that hacks it
        /// </summary>
        /// <param name="targetMethod"></param>
        /// <param name="evt"></param>
        public static void SetMethodVisibility(CodeMemberMethod targetMethod, EventType evt)
        {
            targetMethod.Attributes = MemberAttributes.Overloaded;
            MethodVisibility visibility = MethodVisibility.none;

            string vTag = visibility.ToString( );

            switch (evt.visibility)
            {
            case "public":
                visibility = MethodVisibility.@public;
                targetMethod.Attributes = MemberAttributes.Public;
                break;

            case "protected":
                visibility = MethodVisibility.@protected;
                break;

            case "internal":
                visibility = MethodVisibility.@internal;
                break;

            case "none":
                visibility = MethodVisibility.none;
                break;

            case "private":
                visibility = MethodVisibility.@private;
                targetMethod.Attributes = MemberAttributes.Private;
                break;

            default:
                visibility = MethodVisibility.@public;
                break;
            }

            //targetMethod.Comments.Add(new CodeCommentStatement(CoderBase.LineReplacementFlag + visibility ));
            if (visibility != MethodVisibility.@public && visibility != MethodVisibility.@private && visibility != MethodVisibility.none)
            {
                targetMethod.CustomAttributes.Add(
                    new CodeAttributeDeclaration(CoderBase.MethodVisibilityHackReplacementFlag + visibility));
            }
        }
Beispiel #8
0
        private static MethodVisibility DetermineVisibility(IPropertyDeclaration propertyDeclaration)
        {
            if (propertyDeclaration.SetMethod == null)
            {
                return(propertyDeclaration.GetMethod.Resolve().Visibility);
            }

            if (propertyDeclaration.GetMethod == null)
            {
                return(propertyDeclaration.SetMethod.Resolve().Visibility);
            }

            MethodVisibility getMethodVisibility = propertyDeclaration.GetMethod.Resolve().Visibility;
            MethodVisibility setMethodVisibility = propertyDeclaration.SetMethod.Resolve().Visibility;

            if (getMethodVisibility < setMethodVisibility)
            {
                return(setMethodVisibility);
            }

            return(getMethodVisibility);
        }
Beispiel #9
0
        public static MethodVisibility GetVisibility(IPropertyReference value)
        {
            IMethodDeclaration getMethod = GetGetMethod(value);
            IMethodDeclaration setMethod = GetSetMethod(value);
            MethodVisibility   @public   = MethodVisibility.Public;

            if ((setMethod != null) && (getMethod != null))
            {
                if (getMethod.Visibility == setMethod.Visibility)
                {
                    @public = getMethod.Visibility;
                }
                return(@public);
            }
            if (setMethod != null)
            {
                return(setMethod.Visibility);
            }
            if (getMethod != null)
            {
                @public = getMethod.Visibility;
            }
            return(@public);
        }
            private static MethodVisibility __GetPropertyVisibility(IPropertyDeclaration propDecl, out IMethodDeclaration getter, out IMethodDeclaration setter)
            {
                IMethodReference getref = propDecl.GetMethod;
                IMethodReference setref = propDecl.SetMethod;

                if (getref == null)
                {
                    getter = null;
                    if (setref == null)
                    {
                        setter = null;
                        return(MethodVisibility.Private);
                    }
                    else
                    {
                        setter = setref.Resolve();
                        return(setter.Visibility);
                    }
                }
                else
                {
                    getter = getref.Resolve();
                    if (setref == null)
                    {
                        setter = null;
                        return(getter.Visibility);
                    }
                    else
                    {
                        setter = setref.Resolve();
                        MethodVisibility max = (MethodVisibility)System.Math.Max((int)getter.Visibility, (int)setter.Visibility);
                        MethodVisibility min = (MethodVisibility)System.Math.Min((int)getter.Visibility, (int)setter.Visibility);
                        return(min == MethodVisibility.Assembly && max == MethodVisibility.Family?MethodVisibility.FamilyOrAssembly:max);
                    }
                }
            }
Beispiel #11
0
        private void BuildTypeTreeNode(ITypeDeclaration typeDeclaration, TreeNode parentNode)
        {
            SortedList <String, TreeNode> list = new SortedList <string, TreeNode>();

            // Types
            foreach (ITypeDeclaration nestedTypeDeclaration in typeDeclaration.Types)
            {
                StringBuilder builder = new StringBuilder();
                MakeTypeDeclarationName(nestedTypeDeclaration, builder);

                TreeNode typeNode = new TreeNode(builder.ToString());
                typeNode.Tag = nestedTypeDeclaration;

                if (nestedTypeDeclaration.IsEnum)
                {
                    typeNode.ImageIndex         = EnumImageIndex;
                    typeNode.SelectedImageIndex = EnumImageIndex;
                }
                else if (nestedTypeDeclaration.IsInterface)
                {
                    typeNode.ImageIndex         = InterfaceImageIndex;
                    typeNode.SelectedImageIndex = InterfaceImageIndex;
                }
                else
                {
                    typeNode.ImageIndex         = ClassImageIndex;
                    typeNode.SelectedImageIndex = ClassImageIndex;
                }

                BuildTypeTreeNode(nestedTypeDeclaration, typeNode);

                list.Add(builder.ToString(), typeNode);
            }

            parentNode.Nodes.AddRange(list.Values.ToArray());

            list.Clear();

            // Methods
            foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Constructors)
            {
                TreeNode methodNode = GenerateMethodNode(methodDeclaration);

                if (!list.ContainsKey(methodNode.Text))
                {
                    list.Add(methodNode.Text, methodNode);
                }
                else
                {
                    list.Add(methodNode.Text + Guid.NewGuid(), methodNode);
                }
            }

            parentNode.Nodes.AddRange(list.Values.ToArray());

            list.Clear();

            // Methods
            foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Methods)
            {
                TreeNode methodNode = GenerateMethodNode(methodDeclaration);

                if (!list.ContainsKey(methodNode.Text))
                {
                    list.Add(methodNode.Text, methodNode);
                }
                else
                {
                    list.Add(methodNode.Text + Guid.NewGuid(), methodNode);
                }
            }

            parentNode.Nodes.AddRange(list.Values.ToArray());

            list.Clear();

            // Properties
            foreach (IPropertyDeclaration propertyDeclaration in typeDeclaration.Properties)
            {
                TreeNode propertyNode = new TreeNode(propertyDeclaration.Name);
                propertyNode.Tag = propertyDeclaration;

                MethodVisibility propertyVisibility = DetermineVisibility(propertyDeclaration);

                if (propertyVisibility == MethodVisibility.Assembly)
                {
                    propertyNode.ImageIndex         = ProtectedPropertyImageIndex;
                    propertyNode.SelectedImageIndex = ProtectedPropertyImageIndex;
                }
                else if ((propertyVisibility == MethodVisibility.Family) || (propertyVisibility == MethodVisibility.FamilyOrAssembly))
                {
                    propertyNode.ImageIndex         = InternalPropertyImageIndex;
                    propertyNode.SelectedImageIndex = InternalPropertyImageIndex;
                }
                else if (propertyVisibility == MethodVisibility.Private)
                {
                    propertyNode.ImageIndex         = PrivatePropertyImageIndex;
                    propertyNode.SelectedImageIndex = PrivatePropertyImageIndex;
                }
                else
                {
                    propertyNode.ImageIndex         = PublicPropertyImageIndex;
                    propertyNode.SelectedImageIndex = PublicPropertyImageIndex;
                }

                list.Add(propertyDeclaration.Name, propertyNode);

                if (propertyDeclaration.GetMethod != null)
                {
                    propertyNode.Nodes.Add(GenerateMethodNode(propertyDeclaration.GetMethod.Resolve()));
                }

                if (propertyDeclaration.SetMethod != null)
                {
                    propertyNode.Nodes.Add(GenerateMethodNode(propertyDeclaration.SetMethod.Resolve()));
                }
            }

            parentNode.Nodes.AddRange(list.Values.ToArray());

            list.Clear();

            // Non-Constant fields
            foreach (IFieldDeclaration fieldDeclaration in typeDeclaration.Fields)
            {
                if (!fieldDeclaration.IsConst)
                {
                    TreeNode fieldNode = new TreeNode(fieldDeclaration.Name);
                    fieldNode.Tag = fieldDeclaration;

                    if (fieldDeclaration.Visibility == FieldVisibility.Public)
                    {
                        fieldNode.ImageIndex         = PublicFieldIndex;
                        fieldNode.SelectedImageIndex = PublicFieldIndex;
                    }
                    else if (fieldDeclaration.Visibility == FieldVisibility.Private)
                    {
                        fieldNode.ImageIndex         = PrivateFieldIndex;
                        fieldNode.SelectedImageIndex = PrivateFieldIndex;
                    }
                    else if (fieldDeclaration.Visibility == FieldVisibility.Assembly)
                    {
                        fieldNode.ImageIndex         = InternalFieldIndex;
                        fieldNode.SelectedImageIndex = InternalFieldIndex;
                    }
                    else
                    {
                        fieldNode.ImageIndex         = ProtectedFieldIndex;
                        fieldNode.SelectedImageIndex = ProtectedFieldIndex;
                    }

                    list.Add(fieldDeclaration.Name, fieldNode);
                }
            }

            parentNode.Nodes.AddRange(list.Values.ToArray());

            list.Clear();

            // Events
            foreach (IEventDeclaration eventDeclaration in typeDeclaration.Events)
            {
                TreeNode eventNode = new TreeNode(eventDeclaration.Name);
                eventNode.Tag = eventDeclaration;

                eventNode.Nodes.Add(GenerateMethodNode(eventDeclaration.AddMethod.Resolve()));
                eventNode.Nodes.Add(GenerateMethodNode(eventDeclaration.RemoveMethod.Resolve()));

                list.Add(eventDeclaration.Name, eventNode);
            }

            parentNode.Nodes.AddRange(list.Values.ToArray());

            list.Clear();

            // Constant fields
            foreach (IFieldDeclaration fieldDeclaration in typeDeclaration.Fields)
            {
                if (fieldDeclaration.IsConst)
                {
                    TreeNode fieldNode = new TreeNode(fieldDeclaration.Name);
                    fieldNode.Tag = fieldDeclaration;

                    if (fieldDeclaration.Visibility == FieldVisibility.Public)
                    {
                        fieldNode.ImageIndex         = PublicConstIndex;
                        fieldNode.SelectedImageIndex = PublicConstIndex;
                    }
                    else if (fieldDeclaration.Visibility == FieldVisibility.Private)
                    {
                        fieldNode.ImageIndex         = PrivateConstIndex;
                        fieldNode.SelectedImageIndex = PrivateConstIndex;
                    }
                    else if (fieldDeclaration.Visibility == FieldVisibility.Assembly)
                    {
                        fieldNode.ImageIndex         = InternalConstIndex;
                        fieldNode.SelectedImageIndex = InternalConstIndex;
                    }
                    else
                    {
                        fieldNode.ImageIndex         = ProtectedConstIndex;
                        fieldNode.SelectedImageIndex = ProtectedConstIndex;
                    }

                    list.Add(fieldDeclaration.Name, fieldNode);
                }
            }

            parentNode.Nodes.AddRange(list.Values.ToArray());
        }
            //===========================================================
            //		宣言
            //===========================================================
            public virtual void WritePropertyDeclaration(IPropertyDeclaration propDecl)
            {
                // アクセス修飾子情報
                IMethodDeclaration getter;
                IMethodDeclaration setter;
                MethodVisibility   vis = __GetPropertyVisibility(propDecl, out getter, out setter);

                this.__WriteVisibilitySpecifier(vis);

#warning generic property
                // 修飾子
                if (getter != null && getter.Static || setter != null && setter.Static)
                {
                    this.WriteKeyword("static");
                    this.Write(" ");
                }
                this.WriteKeyword("property");
                this.Write(" ");
                this.WriteType(propDecl.PropertyType, null, null, null, false);
                this.Write(" ");
                this.WriteDeclaration(propDecl.Name);
                IParameterDeclarationCollection parameters = propDecl.Parameters;
                if (parameters != null)
                {
                    this.WritePropertyIndices(parameters);
                }

                //
                // 内容の書込
                //
                //---------------------------------------------------
                // inline == true → 宣言だけを書く場合
                // inline == false → アクセサのロジックも書く場合
                bool inline = !(getter != null && getter.Body != null || setter != null && setter.Body != null);
                this.Write("{");
                if (inline)
                {
                    this.Write(" ");
                }
                else
                {
                    this.WriteIndent();
                    this.WriteLine();
                }
                //-----------------------------------------
                this.PushScope();
                //-----------------------------------------
                if (getter != null)
                {
                    if (getter.Visibility != vis)
                    {
                        this.__WriteVisibilitySpecifier(getter.Visibility, inline);
                    }
                    this.__WritePropertyAccessorSignature("get", getter, inline);
                    this.__WriteMethodBody(getter.Body as IBlockStatement);                     //,true
                    if (inline)
                    {
                        this.Write(" ");
                    }
                    else
                    {
                        this.WriteLine();
                    }
                }
                //-----------------------------------------
                this.PopScope();
                this.PushScope();
                //-----------------------------------------
                if (setter != null)
                {
                    if (getter != null && setter.Visibility != getter.Visibility)
                    {
                        this.__WriteVisibilitySpecifier(setter.Visibility, inline);
                    }
                    this.__WritePropertyAccessorSignature("set", setter, inline);
                    this.__WriteMethodBody(setter.Body as IBlockStatement);                     //,true
                    if (inline)
                    {
                        this.Write(" ");
                    }
                    else
                    {
                        this.WriteLine();
                    }
                }
                //-----------------------------------------
                this.PopScope();
                //-----------------------------------------
                if (!inline)
                {
                    this.WriteOutdent();
                }
                this.Write("}");
            }
 public void WriteMethodVisibility(MethodVisibility visibility, IFormatter formatter)
 {
     switch (visibility)
     {
         case MethodVisibility.Public: formatter.WriteKeyword("public"); break;
         case MethodVisibility.Private: formatter.WriteKeyword("strict private"); break;
         case MethodVisibility.PrivateScope: formatter.WriteKeyword("private");
             formatter.Write(" ");
             formatter.WriteComment("{scope}"); break;
         case MethodVisibility.Family: formatter.WriteKeyword("strict protected"); break;
         case MethodVisibility.Assembly: formatter.WriteKeyword("private"); break;
         case MethodVisibility.FamilyOrAssembly: formatter.WriteKeyword("protected"); break;
         case MethodVisibility.FamilyAndAssembly: formatter.WriteKeyword("protected");
             formatter.Write(" ");
             formatter.WriteComment("{internal}"); break;
         default: throw new NotSupportedException();
     }
     formatter.Write(" ");
 }
Beispiel #14
0
        public static void SetMethodVisibility(CodeMemberMethod targetMethod, MethodVisibility visibility)
        {
            targetMethod.Attributes = MemberAttributes.Overloaded;

            targetMethod.Comments.Add(new CodeCommentStatement(CoderBase.LineReplacementFlag + visibility));
        }