/// <summary>
        /// Converts the <see cref="ModifierEnum"/> to string that can be used in code
        /// </summary>
        /// <param name="modifierEnum">Modifier to convert</param>
        /// <returns>"Code compatible" modifier string</returns>
        public static string ToModifierString(this ModifierEnum modifierEnum)
        {
            switch (modifierEnum)
            {
            case ModifierEnum.NotApplicable:
                return("");

            case ModifierEnum.Public:
                return("public");

            case ModifierEnum.Private:
                return("private");

            case ModifierEnum.Protected:
                return("protected");

            case ModifierEnum.Internal:
                return("internal");

            case ModifierEnum.ProtectedInternal:
                return("protected internal");

            case ModifierEnum.PrivateProtected:
                return("private protected");

            default:
                throw new ArgumentOutOfRangeException(nameof(modifierEnum), modifierEnum, null);
            }
        }
Example #2
0
        string ConvertAccessibility(ModifierEnum modifier)
        {
            StringBuilder builder = new StringBuilder();

            if (ShowAccessibility)
            {
                if ((modifier & ModifierEnum.Public) == ModifierEnum.Public)
                {
                    builder.Append("Public");
                }
                else if ((modifier & ModifierEnum.Private) == ModifierEnum.Private)
                {
                    builder.Append("Private");
                }
                else if ((modifier & (ModifierEnum.Protected | ModifierEnum.Internal)) == (ModifierEnum.Protected | ModifierEnum.Internal))
                {
                    builder.Append("Protected Friend");
                }
                else if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal)
                {
                    builder.Append("Friend");
                }
                else if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected)
                {
                    builder.Append("Protected");
                }
                builder.Append(' ');
            }
            return(builder.ToString());
        }
Example #3
0
 void InitMemberNode(IMember member)
 {
     this.member = member;
     this.ContextmenuAddinTreePath = "/SharpDevelop/Pads/ClassBrowser/MemberContextMenu";
     declaringType = member.DeclaringType;
     modifiers     = member.Modifiers;
 }
Example #4
0
            static ModifierEnum TranslateModifiers(FieldDefinition field)
            {
                ModifierEnum m = ModifierEnum.None;

                if (field.IsStatic)
                {
                    m |= ModifierEnum.Static;
                }

                if (field.IsLiteral)
                {
                    m |= ModifierEnum.Const;
                }
                else if (field.IsReadOnly)
                {
                    m |= ModifierEnum.Readonly;
                }

                if ((field.Attributes & FieldAttributes.Public) == FieldAttributes.Public)
                {
                    m |= ModifierEnum.Public;
                }
                else
                {
                    m |= ModifierEnum.Protected;
                }

                return(m);
            }
Example #5
0
        public override string Convert(ModifierEnum modifier)
        {
            if (ShowAccessibility)
            {
                if (ModifierIsSet(modifier, ModifierEnum.Public))
                {
                    return("public ");
                }
                else if (ModifierIsSet(modifier, ModifierEnum.Private))
                {
                    return("private ");
                }
                else if (ModifierIsSet(modifier, ModifierEnum.ProtectedAndInternal))
                {
                    return("protected internal ");
                }
                else if (ModifierIsSet(modifier, ModifierEnum.Internal))
                {
                    return("internal ");
                }
                else if (ModifierIsSet(modifier, ModifierEnum.Protected))
                {
                    return("protected ");
                }
            }

            return(string.Empty);
        }
Example #6
0
        /// <summary>
        /// Calculate information from class parts (Modifier, Base classes, Type parameters etc.)
        /// </summary>
        void UpdateInformationFromParts()
        {
            // Common for all parts:
            this.ClassType = parts[0].ClassType;

            ModifierEnum       modifier = ModifierEnum.None;
            const ModifierEnum defaultClassVisibility = ModifierEnum.Internal;

            this.BaseTypes.Clear();
            this.InnerClasses.Clear();
            this.Attributes.Clear();
            this.Methods.Clear();
            this.Properties.Clear();
            this.Events.Clear();
            this.Fields.Clear();

            string shortestFileName = null;

            foreach (IClass part in parts)
            {
                if (!string.IsNullOrEmpty(part.CompilationUnit.FileName))
                {
                    if (shortestFileName == null || part.CompilationUnit.FileName.Length < shortestFileName.Length)
                    {
                        shortestFileName = part.CompilationUnit.FileName;
                        this.Region      = part.Region;
                    }
                }

                if ((part.Modifiers & ModifierEnum.VisibilityMask) != defaultClassVisibility)
                {
                    modifier |= part.Modifiers;
                }
                else
                {
                    modifier |= part.Modifiers & ~ModifierEnum.VisibilityMask;
                }
                foreach (IReturnType rt in part.BaseTypes)
                {
                    if (!rt.IsDefaultReturnType || rt.FullyQualifiedName != "System.Object")
                    {
                        this.BaseTypes.Add(rt);
                    }
                }
                this.InnerClasses.AddRange(part.InnerClasses);
                this.Attributes.AddRange(part.Attributes);
                this.Methods.AddRange(part.Methods);
                this.Properties.AddRange(part.Properties);
                this.Events.AddRange(part.Events);
                this.Fields.AddRange(part.Fields);

                this.AddDefaultConstructorIfRequired |= part.GetAddDefaultConstructorIfRequired();
            }
            this.CompilationUnit.FileName = shortestFileName;
            if ((modifier & ModifierEnum.VisibilityMask) == ModifierEnum.None)
            {
                modifier |= defaultClassVisibility;
            }
            this.Modifiers = modifier;
        }
Example #7
0
		void InitMemberNode(IMember member)
		{
			this.member = member;
			this.ContextmenuAddinTreePath = "/SharpDevelop/Pads/ClassBrowser/MemberContextMenu";
			declaringType = member.DeclaringType;
			modifiers = member.Modifiers;
		}
Example #8
0
        public ReflectionEvent(EventInfo eventInfo, IClass declaringType) : base(declaringType, eventInfo.Name)
        {
            this.ReturnType = ReflectionReturnType.Create(this, eventInfo.EventHandlerType, false);

            // get modifiers
            MethodInfo methodBase = null;

            try
            {
                methodBase = eventInfo.GetAddMethod(true);
            }
            catch (Exception) { }

            if (methodBase == null)
            {
                try
                {
                    methodBase = eventInfo.GetRemoveMethod(true);
                }
                catch (Exception) { }
            }

            ModifierEnum modifiers = ModifierEnum.None;

            if (methodBase != null)
            {
                if (methodBase.IsStatic)
                {
                    modifiers |= ModifierEnum.Static;
                }

                if (methodBase.IsAssembly)
                {
                    modifiers |= ModifierEnum.Internal;
                }

                if (methodBase.IsPrivate)
                { // I assume that private is used most and public last (at least should be)
                    modifiers |= ModifierEnum.Private;
                }
                else if (methodBase.IsFamily || methodBase.IsFamilyOrAssembly)
                {
                    modifiers |= ModifierEnum.Protected;
                }
                else if (methodBase.IsPublic)
                {
                    modifiers |= ModifierEnum.Public;
                }
                else
                {
                    modifiers |= ModifierEnum.Internal;
                }
            }
            else
            {
                // assume public property, if no methodBase could be get.
                modifiers = ModifierEnum.Public;
            }
            this.Modifiers = modifiers;
        }
Example #9
0
 public DefaultField(IReturnType type, string name, ModifierEnum m, DomRegion region, IClass declaringType)
     : base(declaringType, name)
 {
     this.ReturnType = type;
     this.Region = region;
     this.Modifiers = m;
 }
Example #10
0
 public DefaultProperty(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base(declaringType, name)
 {
     this.ReturnType = type;
     this.Region     = region;
     this.BodyRegion = bodyRegion;
     Modifiers       = m;
 }
Example #11
0
 public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType)
 {
     _compilationUnit = compilationUnit;
     _region          = region;
     _classType       = classType;
     Modifiers        = modifiers;
 }
Example #12
0
 public DefaultMethod(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType)
     : base(declaringType, name)
 {
     this.ReturnType = type;
     this.Region     = region;
     this.BodyRegion = bodyRegion;
     Modifiers = m;
 }
 int GetAccessSortValue(ModifierEnum mods)
 {
     if ((mods & ModifierEnum.Private) != 0) return 0;
     if ((mods & ModifierEnum.Internal) != 0) return 1;
     if ((mods & ModifierEnum.Protected) != 0) return 2;
     if ((mods & ModifierEnum.Public) != 0) return 3;
     return 4;
 }
		ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility)
		{
			ModifierEnum r = (ModifierEnum)m;
			if ((r & ModifierEnum.VisibilityMask) == ModifierEnum.None)
				return r | defaultVisibility;
			else
				return r;
		}
Example #15
0
		public DefaultEvent(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base(declaringType, name)
		{
			this.ReturnType = type;
			this.Region     = region;
			this.BodyRegion = bodyRegion;
			Modifiers       = (ModifierEnum)m;
			if (Modifiers == ModifierEnum.None) {
				Modifiers = ModifierEnum.Private;
			}
		}
Example #16
0
 public DefaultEvent(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base(declaringType, name)
 {
     this.ReturnType = type;
     this.Region     = region;
     this.BodyRegion = bodyRegion;
     Modifiers       = (ModifierEnum)m;
     if (Modifiers == ModifierEnum.None)
     {
         Modifiers = ModifierEnum.Private;
     }
 }
 public static Modifiers ConvertModifier(ModifierEnum modifiers, ClassFinder targetContext)
 {
     if (targetContext != null && targetContext.ProjectContent != null && targetContext.CallingClass != null)
     {
         if (targetContext.ProjectContent.Language.IsClassWithImplicitlyStaticMembers(targetContext.CallingClass))
         {
             return(((Modifiers)modifiers) & ~Modifiers.Static);
         }
     }
     return((Modifiers)modifiers);
 }
Example #18
0
 public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType)
 {
     if (compilationUnit == null)
     {
         throw new ArgumentNullException("compilationUnit");
     }
     this.compilationUnit = compilationUnit;
     this.region          = region;
     this.classType       = classType;
     Modifiers            = modifiers;
     this.UsingScope      = compilationUnit.UsingScope;
 }
Example #19
0
        public Constructor(IClass declaringType, SR.MethodInfo tinfo)
        {
            this.declaringType = declaringType;

            ModifierEnum mod = (ModifierEnum)0;

            if (tinfo.IsPrivate)
            {
                mod |= ModifierEnum.Private;
            }
            if (tinfo.IsAssembly)
            {
                mod |= ModifierEnum.Internal;
            }
            if (tinfo.IsFamily)
            {
                mod |= ModifierEnum.Protected;
            }
            if (tinfo.IsPublic)
            {
                mod |= ModifierEnum.Public;
            }
            if (tinfo.IsAbstract)
            {
                mod |= ModifierEnum.Abstract;
            }
            if (tinfo.IsFinal)
            {
                mod |= ModifierEnum.Sealed;
            }
            if (tinfo.IsStatic)
            {
                mod |= ModifierEnum.Static;
            }
            if (tinfo.IsVirtual)
            {
                mod |= ModifierEnum.Virtual;
            }

            modifiers = mod;

            this.FullyQualifiedName = tinfo.Name;
            this.region             = Class.GetRegion();
            this.bodyRegion         = Class.GetRegion();
            this._member            = null;

            // Add parameters
            foreach (SR.ParameterInfo pinfo in tinfo.GetParameters())
            {
                parameters.Add(new Parameter(this, pinfo, null));
            }
        }
		static int GetModifierOffset(ModifierEnum modifier)
		{
			if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) {
				return 0;
			}
			if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) {
				return protectedModifierOffset;
			}
			if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) {
				return internalModifierOffset;
			}
			return privateModifierOffset;
		}
Example #21
0
        ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility)
        {
            ModifierEnum r = (ModifierEnum)m;

            if ((r & ModifierEnum.VisibilityMask) == ModifierEnum.None)
            {
                return(r | defaultVisibility);
            }
            else
            {
                return(r);
            }
        }
Example #22
0
		public static AST.TypeMemberModifiers ConvertVisibilityBack(ModifierEnum modifier)
		{
			AST.TypeMemberModifiers r = AST.TypeMemberModifiers.None;
			if ((modifier & ModifierEnum.Public) == ModifierEnum.Public)
				r |= AST.TypeMemberModifiers.Public;
			if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected)
				r |= AST.TypeMemberModifiers.Protected;
			if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal)
				r |= AST.TypeMemberModifiers.Internal;
			if ((modifier & ModifierEnum.Private) == ModifierEnum.Private)
				r |= AST.TypeMemberModifiers.Private;
			return r;
		}
		static int GetModifierOffset(ModifierEnum modifier)
		{
			if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) {
				return 0;
			}
			if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) {
				return protectedModifierOffset;
			}
			if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) {
				return internalModifierOffset;
			}
			return privateModifierOffset;
		}
Example #24
0
            static ModifierEnum GetAccessorVisibility(IProperty p, MethodDefinition accessor)
            {
                ModifierEnum visibility = ModifierEnum.VisibilityMask & TranslateModifiers(accessor);

                if (visibility == (p.Modifiers & ModifierEnum.VisibilityMask))
                {
                    return(ModifierEnum.None);
                }
                else
                {
                    return(visibility);
                }
            }
Example #25
0
        public Event(Class declaringType, SR.EventInfo tinfo)
        {
            this.declaringType = declaringType;

            ModifierEnum mod = (ModifierEnum)0;

            modifiers = mod;

            this.FullyQualifiedName = tinfo.Name;
            returnType      = new ReturnType(tinfo.EventHandlerType);
            this.region     = Class.GetRegion();
            this.bodyRegion = Class.GetRegion();

            LoadXml(declaringType);
        }
Example #26
0
 public static Modifiers ConvertModifier(ModifierEnum modifiers, ClassFinder targetContext)
 {
     if (targetContext != null && targetContext.ProjectContent != null && targetContext.CallingClass != null)
     {
         if (targetContext.ProjectContent.Language.IsClassWithImplicitlyStaticMembers(targetContext.CallingClass))
         {
             return(((Modifiers)modifiers) & ~Modifiers.Static);
         }
     }
     if (modifiers.HasFlag(ModifierEnum.Static))
     {
         modifiers &= ~(ModifierEnum.Abstract | ModifierEnum.Sealed);
     }
     return((Modifiers)modifiers);
 }
Example #27
0
 static int GetModifierOffset(ModifierEnum modifier)
 {
     if ((modifier & ModifierEnum.Public) == ModifierEnum.Public)
     {
         return(0);
     }
     if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected)
     {
         return(3);
     }
     if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal)
     {
         return(4);
     }
     return(2);
 }
Example #28
0
            static ModifierEnum TranslateModifiers(MethodDefinition method)
            {
                ModifierEnum m = ModifierEnum.None;

                if (method.IsStatic)
                {
                    m |= ModifierEnum.Static;
                }
                else
                {
                    if (method.IsAbstract)
                    {
                        m |= ModifierEnum.Abstract;
                    }
                    else if (method.IsFinal)
                    {
                        m |= ModifierEnum.Sealed;
                    }
                    else if (method.Overrides.Count > 0)
                    {
                        m |= ModifierEnum.Override;
                    }
                    else if (method.IsVirtual)
                    {
                        if (method.IsNewSlot)
                        {
                            m |= ModifierEnum.Virtual;
                        }
                        else
                        {
                            m |= ModifierEnum.Override;
                        }
                    }
                }

                if ((method.Attributes & MethodAttributes.Public) == MethodAttributes.Public)
                {
                    m |= ModifierEnum.Public;
                }
                else
                {
                    m |= ModifierEnum.Protected;
                }

                return(m);
            }
Example #29
0
        public Local(Class declaringType, NCC.LocalValue tinfo)
        {
            this.declaringType = declaringType;

            ModifierEnum mod = ModifierEnum.Public;

            if (!tinfo.IsMutable)
            {
                mod |= ModifierEnum.Readonly;
            }

            modifiers = mod;

            this.FullyQualifiedName = tinfo.Name;
            returnType  = new ReturnType(tinfo.Type.Fix());
            this.region = Class.GetRegion();
        }
Example #30
0
		string ConvertAccessibility(ModifierEnum modifier)
		{
			if (ShowAccessibility) {
				if (ModifierIsSet(modifier, ModifierEnum.Public)) {
					return "public ";
				} else if (ModifierIsSet(modifier, ModifierEnum.Private)) {
					return "private ";
				} else if (ModifierIsSet(modifier, ModifierEnum.ProtectedAndInternal)) {
					return "protected internal ";
				} else if (ModifierIsSet(modifier, ModifierEnum.Internal)) {
					return "internal ";
				} else if (ModifierIsSet(modifier, ModifierEnum.Protected)) {
					return "protected ";
				}
			}
			
			return string.Empty;
		}
Example #31
0
        public ReflectionField(FieldInfo fieldInfo, IClass declaringType) : base(declaringType, fieldInfo.Name)
        {
            this.ReturnType = ReflectionReturnType.Create(this, fieldInfo.FieldType, false);

            ModifierEnum modifiers = ModifierEnum.None;

            if (fieldInfo.IsInitOnly)
            {
                modifiers |= ModifierEnum.Readonly;
            }

            if (fieldInfo.IsStatic)
            {
                modifiers |= ModifierEnum.Static;
            }

            if (fieldInfo.IsAssembly)
            {
                modifiers |= ModifierEnum.Internal;
            }

            if (fieldInfo.IsPrivate)               // I assume that private is used most and public last (at least should be)
            {
                modifiers |= ModifierEnum.Private;
            }
            else if (fieldInfo.IsFamily || fieldInfo.IsFamilyOrAssembly)
            {
                modifiers |= ModifierEnum.Protected;
            }
            else if (fieldInfo.IsPublic)
            {
                modifiers |= ModifierEnum.Public;
            }
            else
            {
                modifiers |= ModifierEnum.Internal;
            }

            if (fieldInfo.IsLiteral)
            {
                modifiers |= ModifierEnum.Const;
            }
            this.Modifiers = modifiers;
        }
        public override object VisitFieldDeclaration(NRefactoryAST.FieldDeclaration fieldDeclaration, object data)
        {
            DomRegion    region   = GetRegion(fieldDeclaration.StartLocation, fieldDeclaration.EndLocation);
            DefaultClass c        = GetCurrentClass();
            ModifierEnum modifier = ConvertModifier(fieldDeclaration.Modifier,
                                                    (c.ClassType == ClassType.Struct && this.IsVisualBasic)
                                                                ? ModifierEnum.Public : ModifierEnum.Private);
            string doku = GetDocumentation(region.BeginLine, fieldDeclaration.Attributes);

            if (currentClass.Count > 0)
            {
                for (int i = 0; i < fieldDeclaration.Fields.Count; ++i)
                {
                    NRefactoryAST.VariableDeclaration field = (NRefactoryAST.VariableDeclaration)fieldDeclaration.Fields[i];

                    IReturnType retType;
                    if (c.ClassType == ClassType.Enum)
                    {
                        retType = c.DefaultReturnType;
                    }
                    else
                    {
                        retType = CreateReturnType(fieldDeclaration.GetTypeForField(i));
                        if (!field.FixedArrayInitialization.IsNull)
                        {
                            retType = new ArrayReturnType(cu.ProjectContent, retType, 1);
                        }
                    }
                    DefaultField f = new DefaultField(retType, field.Name, modifier, region, c);
                    ConvertAttributes(fieldDeclaration, f);
                    f.Documentation = doku;
                    if (c.ClassType == ClassType.Enum)
                    {
                        f.Modifiers = ModifierEnum.Const | ModifierEnum.Public;
                    }

                    c.Fields.Add(f);
                    mapField(fieldDeclaration, f);
                }
            }

            return(null);
        }
Example #33
0
		public override string Convert(ModifierEnum modifier)
		{
			StringBuilder builder = new StringBuilder();
			if (ShowAccessibility) {
				if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) {
					builder.Append("Public");
				} else if ((modifier & ModifierEnum.Private) == ModifierEnum.Private) {
					builder.Append("Private");
				} else if ((modifier & (ModifierEnum.Protected | ModifierEnum.Internal)) == (ModifierEnum.Protected | ModifierEnum.Internal)) {
					builder.Append("Protected Friend");
				} else if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) {
					builder.Append("Friend");
				} else if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) {
					builder.Append("Protected");
				}
				builder.Append(' ');
			}
			return builder.ToString();
		}
Example #34
0
        /// <summary>
        /// Defines and returns a constructor for the given type
        /// </summary>
        /// <param name="container"></param>
        /// <param name="modifier"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static CodeConstructor DefineConstructor(CodeTypeDeclaration container,
            ModifierEnum modifier, params ParameterInfo[] parameters)
        {
            CodeConstructor ctor = new CodeConstructor();
            ctor.Attributes = (ctor.Attributes & ~MemberAttributes.AccessMask) | (MemberAttributes)modifier;

            if (parameters != null)
            {
                foreach (ParameterInfo parameter in parameters)
                {
                    CodeParameterDeclarationExpression codeParameter = new CodeParameterDeclarationExpression(
                        parameter.ParameterType, parameter.Name);
                    ctor.Parameters.Add(codeParameter);
                }
            }

            container.Members.Add(ctor);
            return ctor;
        }
Example #35
0
		public override string Convert(ModifierEnum modifier, ConversionFlags conversionFlags)
		{
			if (ShowAccessibility(conversionFlags)) {
				if (ModifierIsSet(modifier, ModifierEnum.Public)) {
					return "public ";
				} else if (ModifierIsSet(modifier, ModifierEnum.Private)) {
					return "private ";
				} else if (ModifierIsSet(modifier, ModifierEnum.ProtectedAndInternal)) {
					return "protected internal ";
				} else if (ModifierIsSet(modifier, ModifierEnum.ProtectedOrInternal)) {
					return "internal protected ";
				} else if (ModifierIsSet(modifier, ModifierEnum.Internal)) {
					return "internal ";
				} else if (ModifierIsSet(modifier, ModifierEnum.Protected)) {
					return "protected ";
				}
			}
			
			return string.Empty;
		}
Example #36
0
 public static AST.TypeMemberModifiers ConvertVisibilityBack(ModifierEnum modifier)
 {
     AST.TypeMemberModifiers r = AST.TypeMemberModifiers.None;
     if ((modifier & ModifierEnum.Public) == ModifierEnum.Public)
     {
         r |= AST.TypeMemberModifiers.Public;
     }
     if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected)
     {
         r |= AST.TypeMemberModifiers.Protected;
     }
     if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal)
     {
         r |= AST.TypeMemberModifiers.Internal;
     }
     if ((modifier & ModifierEnum.Private) == ModifierEnum.Private)
     {
         r |= AST.TypeMemberModifiers.Private;
     }
     return(r);
 }
Example #37
0
        public Indexer(Class declaringType, SR.PropertyInfo tinfo)
        {
            this.declaringType = declaringType;

            ModifierEnum mod = (ModifierEnum)0;

            modifiers = mod;

            this.FullyQualifiedName = tinfo.Name;
            returnType      = new ReturnType(tinfo.PropertyType);
            this.region     = Class.GetRegion();
            this.bodyRegion = Class.GetRegion();

            LoadXml(declaringType);

            // Add parameters
            foreach (SR.ParameterInfo pinfo in tinfo.GetIndexParameters())
            {
                parameters.Add(new Parameter(this, pinfo, node));
            }
        }
Example #38
0
        /// <summary>
        /// Re-calculate information from class parts (Modifier, Base classes, Type parameters etc.)
        /// </summary>
        internal void UpdateInformationFromParts()
        {
            // Common for all parts:
            this.ClassType = parts[0].ClassType;
            this.CompilationUnit.FileName = parts[0].CompilationUnit.FileName;
            this.Region = parts[0].Region;

            ModifierEnum       modifier = ModifierEnum.None;
            const ModifierEnum defaultClassVisibility = ModifierEnum.Internal;

            this.BaseTypes.Clear();
            this.Attributes.Clear();
            foreach (IClass part in parts)
            {
                if ((part.Modifiers & ModifierEnum.VisibilityMask) != defaultClassVisibility)
                {
                    modifier |= part.Modifiers;
                }
                else
                {
                    modifier |= part.Modifiers & ~ModifierEnum.VisibilityMask;
                }
                foreach (IReturnType rt in part.BaseTypes)
                {
                    if (!rt.IsDefaultReturnType || rt.FullyQualifiedName != "System.Object")
                    {
                        this.BaseTypes.Add(rt);
                    }
                }
                foreach (IAttribute attribute in part.Attributes)
                {
                    this.Attributes.Add(attribute);
                }
            }
            if ((modifier & ModifierEnum.VisibilityMask) == ModifierEnum.None)
            {
                modifier |= defaultClassVisibility;
            }
            this.Modifiers = modifier;
        }
Example #39
0
        public Field(Class declaringType, SR.FieldInfo tinfo)
        {
            this.declaringType = declaringType;

            ModifierEnum mod = (ModifierEnum)0;

            if (tinfo.IsPrivate)
            {
                mod |= ModifierEnum.Private;
            }
            if (tinfo.IsAssembly)
            {
                mod |= ModifierEnum.Internal;
            }
            if (tinfo.IsFamily)
            {
                mod |= ModifierEnum.Protected;
            }
            if (tinfo.IsPublic)
            {
                mod |= ModifierEnum.Public;
            }
            if (tinfo.IsStatic)
            {
                mod |= ModifierEnum.Static;
            }
            if (tinfo.IsLiteral)
            {
                mod |= ModifierEnum.Const;
            }

            modifiers = mod;

            this.FullyQualifiedName = tinfo.Name;
            returnType  = new ReturnType(tinfo.FieldType);
            this.region = Class.GetRegion();

            LoadXml(declaringType);
        }
Example #40
0
        internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList <IParameter> parameters)
        {
            ModifierEnum  modifiers    = ModifierEnum.Public | ModifierEnum.Synthetic;
            DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c);

            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c);
            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
            invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c);
            invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
        }
        /// <summary>
        /// Compares the SharpDevelop.Dom field declaration oldField to
        /// the CodeDom field declaration newField.
        /// </summary>
        /// <returns>true, if the fields are different in type or modifiers, otherwise false.</returns>
        static bool FieldChanged(IField oldField, CodeMemberField newField)
        {
            // compare types
            if (oldField.ReturnType != null && newField.Type != null)
            {
                if (AreTypesDifferent(oldField.ReturnType, newField.Type))
                {
                    LoggingService.Debug("FieldChanged (type): " + oldField.Name + ", " + oldField.ReturnType.FullyQualifiedName + " -> " + newField.Type.BaseType);
                    return(true);
                }
            }

            // compare modifiers
            ModifierEnum     oldModifiers = oldField.Modifiers & ModifierEnum.VisibilityMask;
            MemberAttributes newModifiers = newField.Attributes & MemberAttributes.AccessMask;

            // SharpDevelop.Dom always adds Private modifier, even if not specified
            // CodeDom omits Private modifier if not present (although it is the default)
            if (oldModifiers == ModifierEnum.Private)
            {
                if (newModifiers != 0 && newModifiers != MemberAttributes.Private)
                {
                    return(true);
                }
            }

            ModifierEnum[]     sdModifiers = new ModifierEnum[] { ModifierEnum.Protected, ModifierEnum.ProtectedAndInternal, ModifierEnum.Internal, ModifierEnum.Public };
            MemberAttributes[] cdModifiers = new MemberAttributes[] { MemberAttributes.Family, MemberAttributes.FamilyOrAssembly, MemberAttributes.Assembly, MemberAttributes.Public };
            for (int i = 0; i < sdModifiers.Length; i++)
            {
                if ((oldModifiers == sdModifiers[i]) ^ (newModifiers == cdModifiers[i]))
                {
                    return(true);
                }
            }

            return(false);
        }
        public override void VisitAttribute(AXmlAttribute attribute)
        {
            Debug.Assert(document != null);

            if (attribute.ParentElement != null)
            {
                if (attribute.ParentElement.Parent == document && attribute.LocalName == "Class" &&
                    attribute.Namespace == CompletionDataHelper.XamlNamespace)
                {
                    this.generatedClass = AddClass(attribute.Value, attribute.ParentElement);
                }
                else if (generatedClass != null && attribute.LocalName == "Name")
                {
                    string name = attribute.Value;

                    if (!string.IsNullOrEmpty(name))
                    {
                        IReturnType type     = TypeFromXmlNode(CompilationUnit, attribute.ParentElement);
                        DomRegion   position = CreateRegion(attribute.ParentElement.StartOffset, attribute.ParentElement.StartOffset + attribute.ParentElement.Name.Length);

                        ModifierEnum fieldModifier = ModifierEnum.Internal;

                        string modifierValue = (attribute.ParentElement.GetAttributeValue(CompletionDataHelper.XamlNamespace, "FieldModifier") ?? string.Empty).Trim();

                        string publicString = currentAmbience.ConvertAccessibility(ModifierEnum.Public).Trim();

                        if (projectContent.Language.NameComparer.Compare(modifierValue, publicString) == 0)
                        {
                            fieldModifier = ModifierEnum.Public;
                        }

                        generatedClass.Fields.Add(new DefaultField(type, name, fieldModifier, position, generatedClass));
                    }
                }
            }

            base.VisitAttribute(attribute);
        }
Example #43
0
        /// <summary>
        /// Defines an accessor (get/set)
        /// </summary>
        /// <param name="container"></param>
        /// <param name="modifier"></param>
        /// <param name="typeInfo"></param>
        /// <param name="hasGet"></param>
        /// <param name="hasSet"></param>
        /// <param name="memberVariableName"></param>
        /// <returns></returns>
        public static CodeMemberProperty DefineAccessor(CodeTypeDeclaration container,
            ModifierEnum modifier, ParameterInfo typeInfo, bool hasGet, bool hasSet, string memberVariableName)
        {
            CodeMemberProperty property = DefineProperty(container, modifier, typeInfo, hasGet, hasSet);

            if (hasGet)
            {
                property.GetStatements.Add(new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), memberVariableName
                    )
                )
                );
            }

            if (hasSet)
            {
                property.SetStatements.Add(new CodeAssignStatement(
                    new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), memberVariableName),
                    new CodePropertySetValueReferenceExpression()));
            }

            return property;
        }
Example #44
0
 public void AddModifier(ModifierEnum m)
 {
     modifiers = modifiers | m;
 }
		public string Convert(ModifierEnum modifier)
		{
			return String.Empty;
		}
 public override string Convert(ModifierEnum modifier)
 {
     return "";
 }
Example #47
0
		public override string ConvertAccessibility(ModifierEnum accessibility)
		{
			return String.Empty;
		}
Example #48
0
		public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType)
		{
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			this.compilationUnit = compilationUnit;
			this.region = region;
			this.classType = classType;
			Modifiers = modifiers;
			this.UsingScope = compilationUnit.UsingScope;
		}
Example #49
0
		public Constructor(ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType)
			: base((m & ModifierEnum.Static) != 0 ? "#cctor" : "#ctor",
			       declaringType.DefaultReturnType,
			       m, region, bodyRegion, declaringType)
		{
		}
Example #50
0
		public Constructor(ModifierEnum m, IReturnType returnType, IClass declaringType)
			: base("#ctor", returnType, m, DomRegion.Empty, DomRegion.Empty, declaringType)
		{
		}
Example #51
0
 /// <summary>
 /// Defines a member variable
 /// </summary>
 /// <param name="container"></param>
 /// <param name="modifier"></param>
 /// <param name="typeInfo"></param>
 /// <returns></returns>
 public static CodeMemberField DefineField(CodeTypeDeclaration container,
     ModifierEnum modifier, ParameterInfo typeInfo)
 {
     CodeMemberField member = new CodeMemberField(new CodeTypeReference(typeInfo.ParameterType), typeInfo.Name);
     member.Attributes = (member.Attributes & ~MemberAttributes.AccessMask) | (MemberAttributes)modifier;
     container.Members.Add(member);
     return member;
 }
		/// <summary>
		/// Compares the SharpDevelop.Dom field declaration oldField to
		/// the CodeDom field declaration newField.
		/// </summary>
		/// <returns>true, if the fields are different in type or modifiers, otherwise false.</returns>
		static bool FieldChanged(IField oldField, CodeMemberField newField)
		{
			// compare types
			if (oldField.ReturnType != null && newField.Type != null) {
				if (AreTypesDifferent(oldField.ReturnType, newField.Type)) {
					LoggingService.Debug("FieldChanged (type): "+oldField.Name+", "+oldField.ReturnType.FullyQualifiedName+" -> "+newField.Type.BaseType);
					return true;
				}
			}
			
			// compare modifiers
			ModifierEnum oldModifiers = oldField.Modifiers & ModifierEnum.VisibilityMask;
			MemberAttributes newModifiers = newField.Attributes & MemberAttributes.AccessMask;
			
			// SharpDevelop.Dom always adds Private modifier, even if not specified
			// CodeDom omits Private modifier if not present (although it is the default)
			if (oldModifiers == ModifierEnum.Private) {
				if (newModifiers != 0 && newModifiers != MemberAttributes.Private) {
					return true;
				}
			}
			
			ModifierEnum[] sdModifiers = new ModifierEnum[] {ModifierEnum.Protected, ModifierEnum.ProtectedAndInternal, ModifierEnum.Internal, ModifierEnum.Public};
			MemberAttributes[] cdModifiers = new MemberAttributes[] {MemberAttributes.Family, MemberAttributes.FamilyOrAssembly, MemberAttributes.Assembly, MemberAttributes.Public};
			for (int i = 0; i < sdModifiers.Length; i++) {
				if ((oldModifiers  == sdModifiers[i]) ^ (newModifiers  == cdModifiers[i])) {
					return true;
				}
			}
			
			return false;
		}
		public CodeGetterOrSetterFunction(IProperty property, ModifierEnum modifier)
			: base(property)
		{
			this.modifier = modifier;
		}
Example #54
0
 public void SetModifiers(ModifierEnum m)
 {
     modifiers = m;
 }
 public string Convert(ModifierEnum modifier)
 {
     return conv.Convert(modifier);
 }
 public abstract string Convert(ModifierEnum modifier);
Example #57
0
		bool ModifierIsSet(ModifierEnum modifier, ModifierEnum query)
		{
			return (modifier & query) == query;
		}
Example #58
0
		public abstract string ConvertAccessibility(ModifierEnum accessibility);
        string GetWithModifiers(ModifierEnum modifier, string mod_public, string mod_protected, string mod_internal, string mod_private)
        {
            if ((modifier & ModifierEnum.Public) == ModifierEnum.Public)
                return mod_public;

            if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected)
                return mod_protected;

            if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal)
                return mod_internal;

            return mod_private;
        }
Example #60
0
		public Constructor(ModifierEnum m, IReturnType returnType, IClass declaringType)
			: base((m & ModifierEnum.Static) != 0 ? "#cctor" : "#ctor",
			       returnType, m, DomRegion.Empty, DomRegion.Empty, declaringType)
		{
		}