Пример #1
0
        public override IMember Clone()
        {
            DefaultField field = new DefaultField(ReturnType, Name, Modifiers, Region, DeclaringType);

            field.CopyDocumentationFrom(this);
            return(field);
        }
Пример #2
0
            IField ReadField()
            {
                DefaultField p = new DefaultField(currentClass, ReadString());

                ReadMember(p);
                return(p);
            }
		DefaultField AddTestFieldDefinedAsTestMemberToClass(string name)
		{
			var field = new DefaultField(fakeClass, name);
			fakeClass.Fields.Add(field);
			fakeRegisteredTestFrameworks.AddTestMember(field);
			
			return field;
		}
		public void FindFieldFromArrayReturnsExpectedNullForUnknownField()
		{
			DefaultClass c = CreateClass();
			DefaultField field = new DefaultField(c, "field");
			
			ArrayList items = new ArrayList();
			items.Add(field);
			
			Assert.IsNull(PythonCompletionItemsHelper.FindFieldFromCollection("unknown-field-name", items));
		}
		public void FindFieldFromArrayReturnsExpectedField()
		{
			DefaultClass c = CreateClass();
			DefaultField field = new DefaultField(c, "field");
			
			ArrayList items = new ArrayList();
			items.Add(field);
			
			Assert.AreEqual(field, PythonCompletionItemsHelper.FindFieldFromCollection("field", items));
		}
Пример #6
0
		void AddFieldToDeclaringType(string fieldName)
		{
			if (fieldName != null) {
				if (!fieldNamesAdded.Contains(fieldName)) {
					DefaultField field = new DefaultField(declaringType, fieldName);
					declaringType.Fields.Add(field);
					fieldNamesAdded.Add(fieldName);
				}
			}
		}
		public void IsTestMember_FieldThatStartsWithTest_ReturnsFalse()
		{
			CreateTestFramework();
			MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
			var field = new DefaultField(c, "testField");
			
			bool result = testFramework.IsTestMember(field);
			
			Assert.IsFalse(result);
		}
Пример #8
0
		public override void OnField(AST.Field node)
		{
			DefaultField field = new DefaultField(CreateReturnType(node), node.Name, GetModifier(node), GetRegion(node), OuterClass);
			ConvertAttributes(node, field);
			OuterClass.Fields.Add(field);
		}
		public void IsTestMember_FieldHasOneAttribute_ReturnsFalseAndDoesNotThrowInvalidCastException()
		{
			CreateTestFramework();
			MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes();
			var field = new DefaultField(mockClass, "MyField");
			var testAttribute = new MockAttribute("Test");
			field.Attributes.Add(testAttribute);
			
			bool result = testFramework.IsTestMember(field);
			
			Assert.IsFalse(result);
		}
Пример #10
0
            void InitMembers(TypeDefinition type)
            {
                string defaultMemberName = null;
                foreach (CustomAttribute att in type.CustomAttributes) {
                    if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute"
                        && att.Constructor.Parameters.Count == 1)
                    {
                        defaultMemberName = att.Constructor.Parameters[0].Name;
                    }
                }

                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;
                        name = ReflectionClass.SplitTypeParameterCountFromReflectionName(name);
                        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);
                        AddAttributes(CompilationUnit.ProjectContent, f.Attributes, field.CustomAttributes);
                        Fields.Add(f);
                    }
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    AddProperty(defaultMemberName, property);
                }

                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);
                        AddAttributes(CompilationUnit.ProjectContent, e.Attributes, eventDef.CustomAttributes);
                        Events.Add(e);
                    }
                }

                this.AddDefaultConstructorIfRequired = (this.ClassType == ClassType.Struct || this.ClassType == ClassType.Enum);
                foreach (MethodDefinition method in type.Methods)
                {
                    if (!method.IsSpecialName)
                    {
                        AddMethod(method);
                    }
                }
            }
Пример #11
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);
                    }
                }
            }
Пример #12
0
		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;
		}
			IField ReadField()
			{
				DefaultField p = new DefaultField(currentClass, ReadString());
				ReadMember(p);
				return p;
			}
Пример #14
0
		public override IMember Clone()
		{
			DefaultField field = new DefaultField(ReturnType, Name, Modifiers, Region, DeclaringType);
			field.CopyDocumentationFrom(this);
			return field;
		}
Пример #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);
					}
				}
			}
Пример #16
0
            void InitMembers(TypeDefinition type)
            {
                string defaultMemberName = null;

                foreach (CustomAttribute att in type.CustomAttributes)
                {
                    if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute" &&
                        att.ConstructorArguments.Count == 1)
                    {
                        defaultMemberName = att.ConstructorArguments[0].Value 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;
                        }
                        name = ReflectionClass.SplitTypeParameterCountFromReflectionName(name);
                        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, field);
                        AddAttributes(CompilationUnit.ProjectContent, f, f.Attributes, field);
                        Fields.Add(f);
                    }
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    AddProperty(defaultMemberName, property);
                }

                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, eventDef);
                        AddAttributes(CompilationUnit.ProjectContent, e, e.Attributes, eventDef);
                        Events.Add(e);
                    }
                }

                this.AddDefaultConstructorIfRequired = (this.ClassType == ClassType.Struct || this.ClassType == ClassType.Enum);
                foreach (MethodDefinition method in type.Methods)
                {
                    if (method.IsConstructor || !method.IsSpecialName)
                    {
                        AddMethod(method);
                    }
                }
            }
Пример #17
0
		public override void OnEnumMember(AST.EnumMember node)
		{
			DefaultField field = new DefaultField(OuterClass.DefaultReturnType, node.Name, ModifierEnum.Const | ModifierEnum.Public, GetRegion(node), OuterClass);
			ConvertAttributes(node, field);
			OuterClass.Fields.Add(field);
		}
Пример #18
0
 /// <summary>
 /// Copies fields from one class to another.
 /// </summary>
 /// <param name="oldClass">Source class</param>
 /// <param name="newClass">Target class</param>
 private void copyFields(IClass oldClass, IClass newClass)
 {
     foreach(IField element in oldClass.Fields){
         DefaultField newField = new DefaultField(element.ReturnType,element.Name,element.Modifiers,element.Region,newClass);
         newClass.Fields.Add(newField);
     }
 }
Пример #19
0
		public void LocalVariableAndFieldAreNotSimilarMembers()
		{
			IField field = new DefaultField(dummyClass.DefaultReturnType, "Test", ModifierEnum.None, DomRegion.Empty, dummyClass);
			IField local = new DefaultField.LocalVariableField(dummyClass.DefaultReturnType, "Test", DomRegion.Empty, dummyClass);
			Assert.IsFalse(MemberLookupHelper.IsSimilarMember(local, field));
		}
Пример #20
0
		public DefaultField AddField(string name)
		{
			DefaultField field = new DefaultField(this, name);
			Fields.Add(field);
			return field;
		}