Esempio n. 1
0
		public NUnitTestMethod(ITestProject parentProject, IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName))
		{
			if (parentProject == null)
				throw new ArgumentNullException("parentProject");
			this.parentProject = parentProject;
			UpdateTestMethod(method, derivedFixture);
		}
Esempio n. 2
0
 /// <summary>
 /// Creates a new unknown type.
 /// </summary>
 /// <param name="namespaceName">Namespace name, if known. Can be null if unknown.</param>
 /// <param name="name">Name of the type, must not be null.</param>
 /// <param name="typeParameterCount">Type parameter count, zero if unknown.</param>
 public UnknownType(string namespaceName, string name, int typeParameterCount = 0)
 {
     if (name == null)
         throw new ArgumentNullException("name");
     this.namespaceKnown = namespaceName != null;
     this.fullTypeName = new TopLevelTypeName(namespaceName ?? string.Empty, name, typeParameterCount);
 }
Esempio n. 3
0
		public NUnitTestClass(NUnitTestProject parentProject, FullTypeName fullTypeName)
		{
			if (parentProject == null)
				throw new ArgumentNullException("parentProject");
			this.parentProject = parentProject;
			this.fullTypeName = fullTypeName;
			BindResultToCompositeResultOfNestedTests();
			// No need to call UpdateTestClass() here as NestedTestsInitialized still is false
		}
Esempio n. 4
0
 /// <summary>
 /// Creates a new unknown type.
 /// </summary>
 /// <param name="fullTypeName">Full name of the unknown type.</param>
 public UnknownType(FullTypeName fullTypeName)
 {
     if (fullTypeName.Name == null) {
         Debug.Assert(fullTypeName == default(FullTypeName));
         this.namespaceKnown = false;
         this.fullTypeName = new TopLevelTypeName(string.Empty, "?", 0);
     } else {
         this.namespaceKnown = true;
         this.fullTypeName = fullTypeName;
     }
 }
Esempio n. 5
0
		IType GetFieldType(string type)
		{
			var fieldTypeName = new FullTypeName(type);
			
			IType fieldType = typeDefinition.Compilation.FindType(fieldTypeName);
			if (fieldType != null) {
				return fieldType;
			}
			
			return new UnknownType(fieldTypeName);
		}
Esempio n. 6
0
 /// <summary>
 /// Retrieves the specified type in this compilation.
 /// Returns an <see cref="UnknownType"/> if the type cannot be found in this compilation.
 /// </summary>
 /// <remarks>
 /// There can be multiple types with the same full name in a compilation, as a
 /// full type name is only unique per assembly.
 /// If there are multiple possible matches, this method will return just one of them.
 /// When possible, use <see cref="IAssembly.GetTypeDefinition"/> instead to
 /// retrieve a type from a specific assembly.
 /// </remarks>
 public static IType FindType(this ICompilation compilation, FullTypeName fullTypeName)
 {
     if (compilation == null)
         throw new ArgumentNullException("compilation");
     foreach (IAssembly asm in compilation.Assemblies) {
         ITypeDefinition def = asm.GetTypeDefinition(fullTypeName);
         if (def != null)
             return def;
     }
     return new UnknownType(fullTypeName);
 }
Esempio n. 7
0
		IType GetMethodReturnType(string typeName)
		{
			var fullTypeName = new FullTypeName(typeName);
			
			IType type = typeDefinition.Compilation.FindType(fullTypeName);
			if (type != null) {
				return type;
			}
			
			return new UnknownType(fullTypeName);
		}
Esempio n. 8
0
		public virtual global::EnvDTE.CodeVariable AddVariable(string name, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic, object Location = null)
		{
			var fieldTypeName = new FullTypeName((string)type);
			var td = typeModel.Resolve();
			if (td == null)
				return null;
			IType fieldType = td.Compilation.FindType(fieldTypeName);
			context.CodeGenerator.AddField(td, Access.ToAccessibility(), fieldType, name);
			var fieldModel = typeModel.Members.OfType<IFieldModel>().FirstOrDefault(f => f.Name == name);
			if (fieldModel != null) {
				return new CodeVariable(context, fieldModel);
			}
			return null;
		}
Esempio n. 9
0
		public void UpdateTestMethod(IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName))
		{
			if (method == null)
				throw new ArgumentNullException("method");
			string oldDisplayName = this.displayName;
			this.derivedFixture = derivedFixture;
			this.method = method;
			if (this.IsInherited)
				displayName = method.DeclaringTypeDefinition.Name + "." + method.Name;
			else
				displayName = method.Name;
			
			if (displayName != oldDisplayName && DisplayNameChanged != null)
				DisplayNameChanged(this, EventArgs.Empty);
		}
Esempio n. 10
0
 /// <summary>
 /// Gets the attributes of the specified attribute type (or derived attribute types).
 /// </summary>
 /// <param name="entity">The entity on which the attributes are declared.</param>
 /// <param name="attributeType">The attribute type to look for.</param>
 /// <param name="inherit">
 /// Specifies whether attributes inherited from base classes and base members (if the given <paramref name="entity"/> in an <c>override</c>)
 /// should be returned. The default is <c>true</c>.
 /// </param>
 /// <returns>
 /// Returns the list of attributes that were found.
 /// If inherit is true, attributes from the entity itself are returned first; followed by attributes inherited from the base entity.
 /// </returns>
 public static IEnumerable<IAttribute> GetAttributes(this IEntity entity, FullTypeName attributeType, bool inherit = true)
 {
     if (entity == null)
         throw new ArgumentNullException("entity");
     return GetAttributes(entity, attrType => {
                          	ITypeDefinition typeDef = attrType.GetDefinition();
                          	return typeDef != null && typeDef.FullTypeName == attributeType;
                          }, inherit);
 }
Esempio n. 11
0
 /// <summary>
 /// Gets the attribute of the specified attribute type (or derived attribute types).
 /// </summary>
 /// <param name="entity">The entity on which the attributes are declared.</param>
 /// <param name="attributeType">The attribute type to look for.</param>
 /// <param name="inherit">
 /// Specifies whether attributes inherited from base classes and base members (if the given <paramref name="entity"/> in an <c>override</c>)
 /// should be returned. The default is <c>true</c>.
 /// </param>
 /// <returns>
 /// Returns the attribute that was found; or <c>null</c> if none was found.
 /// If inherit is true, an from the entity itself will be returned if possible;
 /// and the base entity will only be searched if none exists.
 /// </returns>
 public static IAttribute GetAttribute(this IEntity entity, FullTypeName attributeType, bool inherit = true)
 {
     return GetAttributes(entity, attributeType, inherit).FirstOrDefault();
 }
Esempio n. 12
0
		public void RemoveInheritedClass(FullTypeName baseClassName, NUnitTestClass inheritedClass)
		{
			inheritedTestClasses.Remove(baseClassName.TopLevelTypeName, inheritedClass);
		}
Esempio n. 13
0
		public void RegisterInheritedClass(FullTypeName baseClassName, NUnitTestClass inheritedClass)
		{
			inheritedTestClasses.Add(baseClassName.TopLevelTypeName, inheritedClass);
		}
Esempio n. 14
0
		public NUnitTestClass GetTestClass(FullTypeName fullTypeName)
		{
			var testClass = (NUnitTestClass)base.GetTestClass(fullTypeName.TopLevelTypeName);
			int tpc = fullTypeName.TopLevelTypeName.TypeParameterCount;
			for (int i = 0; i < fullTypeName.NestingLevel; i++) {
				if (testClass == null)
					break;
				tpc += fullTypeName.GetNestedTypeAdditionalTypeParameterCount(i);
				testClass = testClass.FindNestedTestClass(fullTypeName.GetNestedTypeName(i), tpc);
			}
			return testClass;
		}
Esempio n. 15
0
		/// <summary>
		/// Looks for the specified type in all the projects in the open solution
		/// excluding the current project.
		/// </summary>
		static IProject FindProjectContainingType(FullTypeName type)
		{
			IProject currentProject = SD.ProjectService.CurrentProject;
			if (currentProject == null) return null;
			
			foreach (IProject project in SD.ProjectService.CurrentSolution.Projects.Where(p => p != currentProject)) {
				if (project.ProjectContent.TopLevelTypeDefinitions.Any(t => t.FullTypeName == type)) {
					SD.Log.Debug("Found project containing type: " + project.FileName);
					return project;
				}
			}
			return null;
		}
Esempio n. 16
0
		public MSpecTestClass(MSpecTestProject parentProject, FullTypeName fullTypeName)
		{
			this.parentProject = parentProject;
			this.fullTypeName = fullTypeName;
			BindResultToCompositeResultOfNestedTests();
		}
Esempio n. 17
0
		public void UpdateTestClass(ITypeDefinition typeDefinition)
		{
			fullTypeName = typeDefinition.FullTypeName;
			if (this.NestedTestsInitialized) {
				int baseClassIndex = 0;
				foreach (IType baseType in typeDefinition.GetNonInterfaceBaseTypes()) {
					ITypeDefinition baseTypeDef = baseType.GetDefinition();
					// Check that the base type isn't equal to System.Object or the current class itself
					if (baseTypeDef == null || baseTypeDef == typeDefinition || baseTypeDef.KnownTypeCode == KnownTypeCode.Object)
						continue;
					if (baseTypeDef.DeclaringTypeDefinition != null)
						continue; // we only support inheriting from top-level classes
					var baseClassName = baseTypeDef.FullTypeName;
					if (baseClassIndex < baseClassNames.Count && baseClassName == baseClassNames[baseClassIndex]) {
						// base class is already in the list, just keep it
						baseClassIndex++;
					} else {
						// base class is not in the list, or the remaining portion of the list differs
						// remove remaining portion of the list:
						RemoveBaseClasses(baseClassIndex);
						// Add new base class:
						parentProject.RegisterInheritedClass(baseClassName, this);
						baseClassNames.Add(baseClassName);
						baseClassIndex++;
					}
				}
				
				HashSet<ITest> newOrUpdatedNestedTests = new HashSet<ITest>();
				// Update nested test classes:
				foreach (ITypeDefinition nestedClass in typeDefinition.NestedTypes) {
					if (!NUnitTestFramework.IsTestClass(nestedClass))
						continue;
					
					NUnitTestClass nestedTestClass = FindNestedTestClass(nestedClass.Name, nestedClass.TypeParameterCount);
					if (nestedTestClass != null) {
						nestedTestClass.UpdateTestClass(nestedClass);
					} else {
						nestedTestClass = new NUnitTestClass(parentProject, nestedClass.FullTypeName);
						this.NestedTestCollection.Add(nestedTestClass);
					}
					newOrUpdatedNestedTests.Add(nestedTestClass);
				}
				// Get methods (not operators etc.)
				foreach (IMethod method in typeDefinition.GetMethods(m => m.SymbolKind == SymbolKind.Method)) {
					if (!NUnitTestFramework.IsTestMethod(method))
						continue;
					
					IUnresolvedMethod unresolvedMethod = (IUnresolvedMethod)method.UnresolvedMember;
					string methodNameWithDeclaringType;
					FullTypeName derivedFixture;
					if (method.DeclaringTypeDefinition == typeDefinition) {
						derivedFixture = default(FullTypeName); // method is not inherited
						methodNameWithDeclaringType = method.Name;
					} else {
						if (method.DeclaringTypeDefinition == null)
							continue;
						derivedFixture = fullTypeName; // method is inherited
						methodNameWithDeclaringType = method.DeclaringTypeDefinition.Name + "." + method.Name;
					}
					
					NUnitTestMethod testMethod;
					if (method.IsOverride) {
						testMethod = FindTestMethodWithShortName(method.Name);
					} else {
						testMethod = FindTestMethod(methodNameWithDeclaringType);
					}
					if (testMethod != null) {
						testMethod.UpdateTestMethod(unresolvedMethod, derivedFixture);
					} else {
						testMethod = new NUnitTestMethod(parentProject, unresolvedMethod, derivedFixture);
						this.NestedTestCollection.Add(testMethod);
					}
					newOrUpdatedNestedTests.Add(testMethod);
				}
				// Remove all tests that weren't contained in the new type definition anymore:
				this.NestedTestCollection.RemoveAll(t => !newOrUpdatedNestedTests.Contains(t));
			}
		}
Esempio n. 18
0
			public override object Visit (TypeExpression typeExpression)
			{
				var result = new FullTypeName ();
				if (typeExpression.Type != null) {
					result.AddChild (new Identifier (typeExpression.Type.Name, Convert (typeExpression.Location)));
				}
//				if (!string.IsNullOrEmpty (typeExpression.)) {
//					result.AddChild (new Identifier (typeExpression.Namespace + "." + typeExpression.Name, Convert (typeExpression.Location)));
//				} else {
//					result.AddChild (new Identifier (typeExpression.Name, Convert (typeExpression.Location)));
//				}
				return result;
			}
Esempio n. 19
0
		protected IType FindType(string type)
		{
			var fieldTypeName = new FullTypeName(type);
			return typeDefinition.Compilation.FindType(fieldTypeName);
		}
Esempio n. 20
0
 /// <summary>
 /// Creates a new GetClassTypeReference that searches a top-level type in the specified assembly.
 /// </summary>
 /// <param name="assembly">A reference to the assembly containing this type.
 /// If this parameter is null, the GetClassTypeReference will search in all assemblies belonging to the ICompilation.</param>
 /// <param name="namespaceName">The namespace name containing the type, e.g. "System.Collections.Generic".</param>
 /// <param name="name">The name of the type, e.g. "List".</param>
 /// <param name="typeParameterCount">The number of type parameters, (e.g. 1 for List&lt;T&gt;).</param>
 public GetClassTypeReference(IAssemblyReference assembly, string namespaceName, string name, int typeParameterCount = 0)
 {
     this.assembly = assembly;
     this.fullTypeName = new TopLevelTypeName(namespaceName, name, typeParameterCount);
 }
Esempio n. 21
0
 /// <summary>
 /// Creates a new GetClassTypeReference that searches a type definition.
 /// </summary>
 /// <param name="fullTypeName">The full name of the type.</param>
 /// <param name="assembly">A reference to the assembly containing this type.
 /// If this parameter is null, the GetClassTypeReference will search in all
 /// assemblies belonging to the compilation.
 /// </param>
 public GetClassTypeReference(FullTypeName fullTypeName, IAssemblyReference assembly = null)
 {
     this.fullTypeName = fullTypeName;
     this.assembly = assembly;
 }
Esempio n. 22
0
 /// <summary>
 /// Gets the type definition for the specified unresolved type.
 /// Returns null if the unresolved type does not belong to this assembly.
 /// </summary>
 public static ITypeDefinition GetTypeDefinition(this IAssembly assembly, FullTypeName fullTypeName)
 {
     if (assembly == null)
         throw new ArgumentNullException("assembly");
     TopLevelTypeName topLevelTypeName = fullTypeName.TopLevelTypeName;
     ITypeDefinition typeDef = assembly.GetTypeDefinition(topLevelTypeName);
     if (typeDef == null)
         return null;
     int typeParameterCount = topLevelTypeName.TypeParameterCount;
     for (int i = 0; i < fullTypeName.NestingLevel; i++) {
         string name = fullTypeName.GetNestedTypeName(i);
         typeParameterCount += fullTypeName.GetNestedTypeAdditionalTypeParameterCount(i);
         typeDef = FindNestedType(typeDef, name, typeParameterCount);
         if (typeDef == null)
             break;
     }
     return typeDef;
 }
Esempio n. 23
0
		static void SelectedToolUsedHandler(object sender, EventArgs e)
		{
			SD.Log.Debug("SelectedToolUsedHandler");
			SideTab tab = sideBar.ActiveTab;
			
			// try to add project reference
			if (sender is ICSharpCode.FormsDesigner.Services.ToolboxService) {
				ToolboxItem selectedItem = ((IToolboxService)sender).GetSelectedToolboxItem();
				if (tab is CustomComponentsSideTab) {
					if (selectedItem != null && selectedItem.TypeName != null) {
						SD.Log.Debug("Checking for reference to CustomComponent: " + selectedItem.TypeName);
						// Check current project has the custom component first.
						ICompilation currentCompilation = GetCompilationForCurrentProject();
						var typeName = new FullTypeName(selectedItem.TypeName);
						if (currentCompilation != null && currentCompilation.FindType(typeName).Kind == TypeKind.Unknown) {
							// Check other projects in the solution.
							SD.Log.Debug("Checking other projects in the solution.");
							IProject projectContainingType = FindProjectContainingType(typeName);
							if (projectContainingType != null) {
								AddProjectReferenceToProject(SD.ProjectService.CurrentProject, projectContainingType);
							}
						}
					}
				} else {
					if (selectedItem != null && selectedItem.AssemblyName != null) {
						IProject currentProject = ProjectService.CurrentProject;
						if (currentProject != null) {
							if (!ProjectContainsReference(currentProject, selectedItem.AssemblyName)) {
								AddReferenceToProject(currentProject, selectedItem.AssemblyName);
							}
						}
					}
				}
			}
			
			if (tab.Items.Count > 0) {
				tab.ChosenItem = tab.Items[0];
			}
			sideBar.Refresh();
		}
Esempio n. 24
0
		MSTestClass GetMSTestClass(FullTypeName fullTypeName)
		{
			return GetTestClass(fullTypeName.TopLevelTypeName) as MSTestClass;
		}
Esempio n. 25
0
			public override object Visit (SimpleName simpleName)
			{
				var result = new FullTypeName ();
				result.AddChild (new Identifier (simpleName.Name, Convert (simpleName.Location)), FullTypeName.Roles.Identifier);
				if (simpleName.TypeArguments != null)  {
					var location = LocationsBag.GetLocations (simpleName);
					if (location != null)
						result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FullTypeName.Roles.LChevron);
//					AddTypeArguments (result, location, simpleName.TypeArguments);
					if (location != null && location.Count > 1)
						result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), FullTypeName.Roles.RChevron);
				}
				return result;
			}
Esempio n. 26
0
 public AstType ConvertType(FullTypeName fullTypeName)
 {
     if (resolver != null) {
         foreach (var asm in resolver.Compilation.Assemblies) {
             var def = asm.GetTypeDefinition(fullTypeName);
             if (def != null) {
                 return ConvertType(def);
             }
         }
     }
     TopLevelTypeName top = fullTypeName.TopLevelTypeName;
     AstType type;
     if (string.IsNullOrEmpty(top.Namespace)) {
         type = new SimpleType(top.Name);
     } else {
         type = new SimpleType(top.Namespace).MemberType(top.Name);
     }
     for (int i = 0; i < fullTypeName.NestingLevel; i++) {
         type = type.MemberType(fullTypeName.GetNestedTypeName(i));
     }
     return type;
 }