Esempio n. 1
0
 void AddProperty(string defaultMemberName, PropertyDefinition property)
 {
     if ((property.GetMethod != null && IsVisible(property.GetMethod.Attributes)) ||
         (property.SetMethod != null && IsVisible(property.SetMethod.Attributes)))
     {
         DefaultProperty p = new DefaultProperty(this, property.Name);
         if (this.ClassType == ClassType.Interface)
         {
             p.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
         }
         else
         {
             p.Modifiers = TranslateModifiers(property);
         }
         p.ReturnType = CreateType(this.ProjectContent, this, property.PropertyType, property);
         p.CanGet     = property.GetMethod != null && IsVisible(property.GetMethod.Attributes);
         p.CanSet     = property.SetMethod != null && IsVisible(property.SetMethod.Attributes);
         if (p.CanGet)
         {
             p.GetterModifiers = GetAccessorVisibility(p, property.GetMethod);
         }
         if (p.CanSet)
         {
             p.SetterModifiers = GetAccessorVisibility(p, property.SetMethod);
         }
         if (p.Name == defaultMemberName)
         {
             p.IsIndexer = true;
         }
         AddParameters(p, property.Parameters);
         AddAttributes(CompilationUnit.ProjectContent, p, p.Attributes, property);
         Properties.Add(p);
     }
 }
Esempio n. 2
0
            IProperty ReadProperty()
            {
                DefaultProperty p = new DefaultProperty(currentClass, ReadString());

                ReadMember(p);
                p.accessFlags = reader.ReadByte();
                ReadParameters(p);
                return(p);
            }
Esempio n. 3
0
		public override IMember Clone()
		{
			DefaultProperty p = new DefaultProperty(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType);
			p.parameters = DefaultParameter.Clone(this.Parameters);
			p.accessFlags = this.accessFlags;
			foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations) {
				p.InterfaceImplementations.Add(eii.Clone());
			}
			return p;
		}
Esempio n. 4
0
        public override IMember Clone()
        {
            DefaultProperty p = new DefaultProperty(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType);

            p.parameters  = DefaultParameter.Clone(this.Parameters);
            p.accessFlags = this.accessFlags;
            foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations)
            {
                p.InterfaceImplementations.Add(eii.Clone());
            }
            return(p);
        }
Esempio n. 5
0
            void ReadParameters(DefaultProperty m)
            {
                int count = reader.ReadUInt16();

                if (count > 0)
                {
                    ReadParameters(m.Parameters, count);
                }
                else
                {
                    m.Parameters = DefaultParameter.EmptyParameterList;
                }
            }
Esempio n. 6
0
            void WriteProperty(IProperty p)
            {
                WriteMember(p);
                DefaultProperty dp = p as DefaultProperty;

                if (dp != null)
                {
                    writer.Write(dp.accessFlags);
                }
                else
                {
                    writer.Write((byte)0);
                }
                WriteParameters(p.Parameters);
            }
Esempio n. 7
0
            IProperty ReadProperty()
            {
                DefaultProperty p = new DefaultProperty(currentClass, ReadString());

                ReadMember(p);
                p.accessFlags = reader.ReadByte();
                byte b = reader.ReadByte();

                if ((b & 1) == 1)
                {
                    p.GetterModifiers = (ModifierEnum)reader.ReadInt32();
                }
                if ((b & 2) == 2)
                {
                    p.SetterModifiers = (ModifierEnum)reader.ReadInt32();
                }
                ReadParameters(p);
                return(p);
            }
Esempio n. 8
0
            void WriteProperty(IProperty p)
            {
                WriteMember(p);
                DefaultProperty dp = p as DefaultProperty;

                if (dp != null)
                {
                    writer.Write(dp.accessFlags);
                }
                else
                {
                    writer.Write((byte)0);
                }
                writer.Write((byte)((p.GetterModifiers != ModifierEnum.None ? 1 : 0) + (p.SetterModifiers != ModifierEnum.None ? 2 : 0)));
                if (p.GetterModifiers != ModifierEnum.None)
                {
                    writer.Write((int)p.GetterModifiers);
                }
                if (p.SetterModifiers != ModifierEnum.None)
                {
                    writer.Write((int)p.SetterModifiers);
                }
                WriteParameters(p.Parameters);
            }
Esempio n. 9
0
        public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent)
        {
            Init(fileContent.Text);

            SimpleCocoParser parser = new SimpleCocoParser(new Scanner(new StringStream(fileContent.Text)));

            parser.Parse();

            DefaultCompilationUnit cu = new DefaultCompilationUnit(projectContent);

            Location start, end;

            if (parser.CopySection != null) {
                start = OffsetToLocation(parser.CopySection.StartOffset);
                end = OffsetToLocation(parser.CopySection.EndOffset);

                cu.FoldingRegions.Add(new FoldingRegion("[copy]", new DomRegion(start.Line, start.Column, end.Line, end.Column)));
            }

            if (parser.UsingSection != null) {
                start = OffsetToLocation(parser.UsingSection.StartOffset);
                end = OffsetToLocation(parser.UsingSection.EndOffset);

                cu.FoldingRegions.Add(new FoldingRegion("[...]", new DomRegion(start.Line, start.Column, end.Line, end.Column)));
            }

            DefaultClass parserClass = null;

            if (parser.ParserSection != null) {
                start = OffsetToLocation(parser.ParserSection.StartOffset);
                end = OffsetToLocation(parser.ParserSection.EndOffset);

                parserClass = new DefaultClass(cu, parser.ParserName);

                parserClass.ClassType = ClassType.Class;
                parserClass.Modifiers = ModifierEnum.None;
                parserClass.Region = new DomRegion(start.Line, start.Column, end.Line, end.Column);

                cu.Classes.Add(parserClass);

                foreach (var info in parser.Lists) {
                    start = OffsetToLocation(info.segment.StartOffset);
                    end = OffsetToLocation(info.segment.EndOffset);

                    var region = new DomRegion(start.Line, start.Column, start.Line, start.Column + info.name.Length);
                    var body = new DomRegion(start.Line, start.Column, end.Line, end.Column);

                    var prop = new DefaultProperty(parserClass, info.name) {
                        Region = region, BodyRegion = body, Modifiers = ModifierEnum.Public
                    };

                    parserClass.Properties.Add(prop);
                }

                foreach (var info in parser.Productions) {
                    start = OffsetToLocation(info.segment.StartOffset);
                    end = OffsetToLocation(info.segment.EndOffset);

                    var region = new DomRegion(start.Line, start.Column, start.Line, start.Column + info.name.Length);
                    var body = new DomRegion(start.Line, start.Column, end.Line, end.Column);

                    var method = new DefaultMethod(parserClass, info.name) {
                        Region = region, BodyRegion = body, Modifiers = ModifierEnum.Public
                    };

                    parserClass.Methods.Add(method);
                }
            }
            return cu;
        }
			void ReadParameters(DefaultProperty m)
			{
				int count = reader.ReadUInt16();
				if (count > 0) {
					ReadParameters(m.Parameters, count);
				} else {
					m.Parameters = DefaultParameter.EmptyParameterList;
				}
			}
			IProperty ReadProperty()
			{
				DefaultProperty p = new DefaultProperty(currentClass, ReadString());
				ReadMember(p);
				p.accessFlags = reader.ReadByte();
				byte b = reader.ReadByte();
				if ((b & 1) == 1) {
					p.GetterModifiers = (ModifierEnum)reader.ReadInt32();
				}
				if ((b & 2) == 2) {
					p.SetterModifiers = (ModifierEnum)reader.ReadInt32();
				}
				ReadParameters(p);
				return p;
			}
Esempio n. 12
0
			void InitMembers(TypeDefinition type)
			{
				string defaultMemberName = null;
				foreach (CustomAttribute att in type.CustomAttributes) {
					if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute"
					    && att.ConstructorParameters.Count == 1)
					{
						defaultMemberName = att.ConstructorParameters[0] as string;
					}
				}
				
				foreach (TypeDefinition nestedType in type.NestedTypes) {
					TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
					if (visibility == TypeAttributes.NestedPublic || visibility == TypeAttributes.NestedFamily
					    || visibility == TypeAttributes.NestedFamORAssem)
					{
						string name = nestedType.Name;
						int pos = name.LastIndexOf('/');
						if (pos > 0)
							name = name.Substring(pos + 1);
						if (name.Length == 0 || name[0] == '<')
							continue;
						if (name.Length > 2 && name[name.Length - 2] == '`')
							name = name.Substring(0, name.Length - 2);
						name = this.FullyQualifiedName + "." + name;
						InnerClasses.Add(new CecilClass(this.CompilationUnit, this, nestedType, name));
					}
				}
				
				foreach (FieldDefinition field in type.Fields) {
					if (IsVisible(field.Attributes) && !field.IsSpecialName) {
						DefaultField f = new DefaultField(this, field.Name);
						f.Modifiers = TranslateModifiers(field);
						f.ReturnType = CreateType(this.ProjectContent, this, field.FieldType);
						Fields.Add(f);
					}
				}
				
				foreach (PropertyDefinition property in type.Properties) {
					if ((property.GetMethod != null && IsVisible(property.GetMethod.Attributes))
					    || (property.SetMethod != null && IsVisible(property.SetMethod.Attributes)))
					{
						DefaultProperty p = new DefaultProperty(this, property.Name);
						if (this.ClassType == ClassType.Interface) {
							p.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
						} else {
							p.Modifiers = TranslateModifiers(property);
						}
						p.ReturnType = CreateType(this.ProjectContent, this, property.PropertyType);
						p.CanGet = property.GetMethod != null;
						p.CanSet = property.SetMethod != null;
						if (p.Name == defaultMemberName) {
							p.IsIndexer = true;
						}
						AddParameters(p, property.Parameters);
						Properties.Add(p);
					}
				}
				
				foreach (EventDefinition eventDef in type.Events) {
					if (eventDef.AddMethod != null && IsVisible(eventDef.AddMethod.Attributes)) {
						DefaultEvent e = new DefaultEvent(this, eventDef.Name);
						if (this.ClassType == ClassType.Interface) {
							e.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
						} else {
							e.Modifiers = TranslateModifiers(eventDef);
						}
						e.ReturnType = CreateType(this.ProjectContent, this, eventDef.EventType);
						Events.Add(e);
					}
				}
				
				foreach (MethodDefinition method in type.Constructors) {
					AddMethod(method);
				}
				foreach (MethodDefinition method in type.Methods) {
					if (!method.IsSpecialName) {
						AddMethod(method);
					}
				}
			}
Esempio n. 13
0
		MemberResolveResult ResolvePropertyName(IReturnType resolvedType, string propertyName, bool allowAttached)
		{
			IMember member = resolvedType.GetProperties().Find(delegate(IProperty p) { return p.Name == propertyName; });
			if (member == null) {
				member = resolvedType.GetEvents().Find(delegate(IEvent p) { return p.Name == propertyName; });
			}
			if (member == null && allowAttached) {
				IMethod method = resolvedType.GetMethods().Find(
					delegate(IMethod p) {
						return p.IsStatic && p.Parameters.Count == 1 && p.Name == "Get" + propertyName;
					});
				member = method;
				if (member != null) {
					member = new DefaultProperty(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = method.ReturnType };
				} else {
					IMethod m = resolvedType.GetMethods().Find(
						delegate(IMethod p) {
							return p.IsPublic && p.IsStatic && p.Parameters.Count == 2 && (p.Name == "Add" + propertyName + "Handler" || p.Name == "Remove" + propertyName + "Handler");
						});
					member = m;
					if (member != null)
						member = new DefaultEvent(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = m.Parameters[1].ReturnType };
				}
			}
			if (member != null)
				return new MemberResolveResult(callingClass, null, member);
			return null;
		}
Esempio n. 14
0
		public void InsertPropertyAtStart(string name)
		{
			DefaultProperty property = new DefaultProperty(this, name);
			Properties.Insert(0, property);
		}
Esempio n. 15
0
            void InitMembers(TypeDefinition type)
            {
                string defaultMemberName = null;

                foreach (CustomAttribute att in type.CustomAttributes)
                {
                    if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute" &&
                        att.ConstructorParameters.Count == 1)
                    {
                        defaultMemberName = att.ConstructorParameters[0] as string;
                    }
                }

                foreach (TypeDefinition nestedType in type.NestedTypes)
                {
                    TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
                    if (visibility == TypeAttributes.NestedPublic || visibility == TypeAttributes.NestedFamily ||
                        visibility == TypeAttributes.NestedFamORAssem)
                    {
                        string name = nestedType.Name;
                        int    pos  = name.LastIndexOf('/');
                        if (pos > 0)
                        {
                            name = name.Substring(pos + 1);
                        }
                        if (name.Length == 0 || name[0] == '<')
                        {
                            continue;
                        }
                        if (name.Length > 2 && name[name.Length - 2] == '`')
                        {
                            name = name.Substring(0, name.Length - 2);
                        }
                        name = this.FullyQualifiedName + "." + name;
                        InnerClasses.Add(new CecilClass(this.CompilationUnit, this, nestedType, name));
                    }
                }

                foreach (FieldDefinition field in type.Fields)
                {
                    if (IsVisible(field.Attributes) && !field.IsSpecialName)
                    {
                        DefaultField f = new DefaultField(this, field.Name);
                        f.Modifiers  = TranslateModifiers(field);
                        f.ReturnType = CreateType(this.ProjectContent, this, field.FieldType);
                        Fields.Add(f);
                    }
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    if ((property.GetMethod != null && IsVisible(property.GetMethod.Attributes)) ||
                        (property.SetMethod != null && IsVisible(property.SetMethod.Attributes)))
                    {
                        DefaultProperty p = new DefaultProperty(this, property.Name);
                        if (this.ClassType == ClassType.Interface)
                        {
                            p.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
                        }
                        else
                        {
                            p.Modifiers = TranslateModifiers(property);
                        }
                        p.ReturnType = CreateType(this.ProjectContent, this, property.PropertyType);
                        p.CanGet     = property.GetMethod != null;
                        p.CanSet     = property.SetMethod != null;
                        if (p.Name == defaultMemberName)
                        {
                            p.IsIndexer = true;
                        }
                        AddParameters(p, property.Parameters);
                        Properties.Add(p);
                    }
                }

                foreach (EventDefinition eventDef in type.Events)
                {
                    if (eventDef.AddMethod != null && IsVisible(eventDef.AddMethod.Attributes))
                    {
                        DefaultEvent e = new DefaultEvent(this, eventDef.Name);
                        if (this.ClassType == ClassType.Interface)
                        {
                            e.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
                        }
                        else
                        {
                            e.Modifiers = TranslateModifiers(eventDef);
                        }
                        e.ReturnType = CreateType(this.ProjectContent, this, eventDef.EventType);
                        Events.Add(e);
                    }
                }

                foreach (MethodDefinition method in type.Constructors)
                {
                    AddMethod(method);
                }
                foreach (MethodDefinition method in type.Methods)
                {
                    if (!method.IsSpecialName)
                    {
                        AddMethod(method);
                    }
                }
            }
Esempio n. 16
0
			IProperty ReadProperty()
			{
				DefaultProperty p = new DefaultProperty(currentClass, ReadString());
				ReadMember(p);
				p.accessFlags = reader.ReadByte();
				ReadParameters(p);
				return p;
			}
Esempio n. 17
0
        /// <summary>
        /// Makes a copy of <c>oldClass</c>.
        /// </summary>
        /// <param name="oldClass">Class to be copied.</param>
        /// <returns>Copy of the class.</returns>
        private IClass copyClass(IClass oldClass)
        {
            DefaultClass newClass = new DefaultClass(oldClass.CompilationUnit,oldClass.FullyQualifiedName);
            newClass.Modifiers = oldClass.Modifiers;
            foreach (ITypeParameter element in oldClass.TypeParameters) {
                newClass.TypeParameters.Add(element);
            }
            // Recursively copy inner classes.
            foreach(IClass element in oldClass.InnerClasses){
                newClass.InnerClasses.Add(copyClass(element));
            }

            // Copy events.
            foreach(IEvent element in oldClass.Events){
                DefaultEvent newEvent = new DefaultEvent(element.Name,element.ReturnType,element.Modifiers,
                                                        element.Region,element.BodyRegion,newClass);
                newClass.Events.Add(newEvent);
            }

            //Copy properties
            foreach(IProperty element in oldClass.Properties){
                DefaultProperty newProperty = new DefaultProperty(element.Name,element.ReturnType,
                                                          element.Modifiers,element.Region,element.BodyRegion,newClass);
                newClass.Properties.Add(newProperty);
            }

            //Copy methods.

            copyMethods(oldClass,newClass);
            copyFields(oldClass,newClass);

            return newClass;
        }
Esempio n. 18
0
		public override object VisitPropertyDeclaration(NRefactoryAST.PropertyDeclaration propertyDeclaration, object data)
		{
			DomRegion region     = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart,     propertyDeclaration.BodyEnd);
			
			IReturnType type = CreateReturnType(propertyDeclaration.TypeReference);
			DefaultClass c = GetCurrentClass();
			
			DefaultProperty property = new DefaultProperty(propertyDeclaration.Name, type, ConvertModifier(propertyDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
			if (propertyDeclaration.HasGetRegion) {
				property.GetterRegion = GetRegion(propertyDeclaration.GetRegion.StartLocation, propertyDeclaration.GetRegion.EndLocation);
				property.CanGet = true;
				property.GetterModifiers = ConvertModifier(propertyDeclaration.GetRegion.Modifier, ModifierEnum.None);
			}
			if (propertyDeclaration.HasSetRegion) {
				property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation);
				property.CanSet = true;
				property.SetterModifiers = ConvertModifier(propertyDeclaration.SetRegion.Modifier, ModifierEnum.None);
			}
			property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes);
			ConvertAttributes(propertyDeclaration, property);
			c.Properties.Add(property);
            mapProperty(propertyDeclaration, property);
			return null;
		}
Esempio n. 19
0
		void ConvertParameters(AST.ParameterDeclarationCollection parameters, DefaultProperty p)
		{
			if (parameters == null || parameters.Count == 0) {
				p.Parameters = DefaultParameter.EmptyParameterList;
			} else {
				AddParameters(parameters, p.Parameters, p, p.DeclaringType);
			}
		}
Esempio n. 20
0
		public override object VisitIndexerDeclaration(NRefactoryAST.IndexerDeclaration indexerDeclaration, object data)
		{
			DomRegion region     = GetRegion(indexerDeclaration.StartLocation, indexerDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(indexerDeclaration.BodyStart,     indexerDeclaration.BodyEnd);
			DefaultProperty i = new DefaultProperty("Item", CreateReturnType(indexerDeclaration.TypeReference), ConvertModifier(indexerDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
			i.IsIndexer = true;
			if (indexerDeclaration.HasGetRegion) {
				i.GetterRegion = GetRegion(indexerDeclaration.GetRegion.StartLocation, indexerDeclaration.GetRegion.EndLocation);
				i.CanGet = true;
				i.GetterModifiers = ConvertModifier(indexerDeclaration.GetRegion.Modifier, ModifierEnum.None);
			}
			if (indexerDeclaration.HasSetRegion) {
				i.SetterRegion = GetRegion(indexerDeclaration.SetRegion.StartLocation, indexerDeclaration.SetRegion.EndLocation);
				i.CanSet = true;
				i.SetterModifiers = ConvertModifier(indexerDeclaration.SetRegion.Modifier, ModifierEnum.None);
			}
			i.Documentation = GetDocumentation(region.BeginLine, indexerDeclaration.Attributes);
			ConvertAttributes(indexerDeclaration, i);
			if (indexerDeclaration.Parameters != null) {
				foreach (NRefactoryAST.ParameterDeclarationExpression par in indexerDeclaration.Parameters) {
					i.Parameters.Add(CreateParameter(par));
				}
			}
			// If an IndexerNameAttribute is specified, use the specified name
			// for the indexer instead of the default name.
			IAttribute indexerNameAttribute = i.Attributes.LastOrDefault(this.IsIndexerNameAttribute);
			if (indexerNameAttribute != null && indexerNameAttribute.PositionalArguments.Count > 0) {
				string name = indexerNameAttribute.PositionalArguments[0] as string;
				if (!String.IsNullOrEmpty(name)) {
					i.FullyQualifiedName = String.Concat(i.DeclaringType.FullyQualifiedName, ".", name);
				}
			}
			DefaultClass c = GetCurrentClass();
			c.Properties.Add(i);
			return null;
		}
Esempio n. 21
0
		public override void OnProperty(AST.Property node)
		{
			DefaultProperty property = new DefaultProperty(node.Name, CreateReturnType(node), GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass);
			ConvertAttributes(node, property);
			ConvertParameters(node.Parameters, property);
			if (node.Getter != null && node.Getter.Body != null) {
				property.GetterRegion = GetClientRegion(node.Getter);
			}
			if (node.Setter != null && node.Setter.Body != null) {
				property.SetterRegion = GetClientRegion(node.Setter);
			}
			property.IsIndexer = (node.Name == "self");
			OuterClass.Properties.Add(property);
			property.UserData = node;
		}
Esempio n. 22
0
 void AddProperty(string defaultMemberName, PropertyDefinition property)
 {
     if ((property.GetMethod != null && IsVisible(property.GetMethod.Attributes))
         || (property.SetMethod != null && IsVisible(property.SetMethod.Attributes)))
     {
         DefaultProperty p = new DefaultProperty(this, property.Name);
         if (this.ClassType == ClassType.Interface) {
             p.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
         } else {
             p.Modifiers = TranslateModifiers(property);
         }
         p.ReturnType = CreateType(this.ProjectContent, this, property.PropertyType);
         p.CanGet = property.GetMethod != null && IsVisible(property.GetMethod.Attributes);
         p.CanSet = property.SetMethod != null && IsVisible(property.SetMethod.Attributes);
         if (p.CanGet)
             p.GetterModifiers = GetAccessorVisibility(p, property.GetMethod);
         if (p.CanSet)
             p.SetterModifiers = GetAccessorVisibility(p, property.SetMethod);
         if (p.Name == defaultMemberName) {
             p.IsIndexer = true;
         }
         AddParameters(p, property.Parameters);
         AddAttributes(CompilationUnit.ProjectContent, p.Attributes, property.CustomAttributes);
         Properties.Add(p);
     }
 }
Esempio n. 23
0
		public DefaultProperty AddProperty(string name)
		{
			DefaultProperty property = new DefaultProperty(this, name);
			Properties.Add(property);
			return property;
		}