diff --git a/src/AddIns/Analysis/UnitTesting/Model/TestProjectBase.cs b/src/AddIns/Analysis/UnitTesting/Model/TestProjectBase.cs index 472f42687b..a7d205ff4e 100644 --- a/src/AddIns/Analysis/UnitTesting/Model/TestProjectBase.cs +++ b/src/AddIns/Analysis/UnitTesting/Model/TestProjectBase.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.UnitTesting public abstract class TestProjectBase : TestBase, ITestProject { IProject project; - Dictionary topLevelTestClasses = new Dictionary(); + Dictionary topLevelTestClasses = new Dictionary(); public TestProjectBase(IProject project) { @@ -70,7 +70,7 @@ namespace ICSharpCode.UnitTesting } #region NotifyParseInformationChanged - HashSet dirtyTypeDefinitions = new HashSet(); + HashSet dirtyTypeDefinitions = new HashSet(); public void NotifyParseInformationChanged(IUnresolvedFile oldUnresolvedFile, IUnresolvedFile newUnresolvedFile) { @@ -93,7 +93,7 @@ namespace ICSharpCode.UnitTesting { var compilation = SD.ParserService.GetCompilation(project); foreach (var typeDef in compilation.MainAssembly.TopLevelTypeDefinitions) { - UpdateType(new FullNameAndTypeParameterCount(typeDef.Namespace, typeDef.Name, typeDef.TypeParameterCount), typeDef); + UpdateType(new TopLevelTypeName(typeDef.Namespace, typeDef.Name, typeDef.TypeParameterCount), typeDef); } base.OnNestedTestsInitialized(); } @@ -102,12 +102,12 @@ namespace ICSharpCode.UnitTesting { if (unresolvedFile != null) { foreach (var td in unresolvedFile.TopLevelTypeDefinitions) { - AddToDirtyList(new FullNameAndTypeParameterCount(td.Namespace, td.Name, td.TypeParameters.Count)); + AddToDirtyList(new TopLevelTypeName(td.Namespace, td.Name, td.TypeParameters.Count)); } } } - protected virtual void AddToDirtyList(FullNameAndTypeParameterCount className) + protected virtual void AddToDirtyList(TopLevelTypeName className) { dirtyTypeDefinitions.Add(className); } @@ -127,7 +127,7 @@ namespace ICSharpCode.UnitTesting /// /// Adds/Updates/Removes the test class for the type definition. /// - void UpdateType(FullNameAndTypeParameterCount dirtyTypeDef, ITypeDefinition typeDef) + void UpdateType(TopLevelTypeName dirtyTypeDef, ITypeDefinition typeDef) { ITest test; if (topLevelTestClasses.TryGetValue(dirtyTypeDef, out test)) { @@ -152,20 +152,20 @@ namespace ICSharpCode.UnitTesting #endregion #region Namespace Management - protected ITest GetTestClass(FullNameAndTypeParameterCount fullName) + protected ITest GetTestClass(TopLevelTypeName fullName) { EnsureNestedTestsInitialized(); return topLevelTestClasses.GetOrDefault(fullName); } - void AddTestClass(FullNameAndTypeParameterCount fullName, ITest test) + void AddTestClass(TopLevelTypeName fullName, ITest test) { topLevelTestClasses.Add(fullName, test); TestCollection testNamespace = FindOrCreateNamespace(NestedTestCollection, project.RootNamespace, fullName.Namespace); testNamespace.Add(test); } - void RemoveTestClass(FullNameAndTypeParameterCount fullName, ITest test) + void RemoveTestClass(TopLevelTypeName fullName, ITest test) { topLevelTestClasses.Remove(fullName); TestCollection testNamespace = FindNamespace(NestedTestCollection, project.RootNamespace, fullName.Namespace); diff --git a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestClass.cs b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestClass.cs index 5a67853946..10acdd0067 100644 --- a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestClass.cs +++ b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestClass.cs @@ -17,16 +17,17 @@ namespace ICSharpCode.UnitTesting public class NUnitTestClass : TestBase { readonly NUnitTestProject parentProject; - IUnresolvedTypeDefinition primaryPart; - List baseClassNames = new List(); + FullTypeName fullTypeName; + List baseClassNames = new List(); - public NUnitTestClass(NUnitTestProject parentProject, ITypeDefinition typeDefinition) + public NUnitTestClass(NUnitTestProject parentProject, FullTypeName fullTypeName) { if (parentProject == null) throw new ArgumentNullException("parentProject"); this.parentProject = parentProject; - UpdateTestClass(typeDefinition); + this.fullTypeName = fullTypeName; BindResultToCompositeResultOfNestedTests(); + // No need to call UpdateTestClass() here as NestedTestsInitialized still is false } public override ITestProject ParentProject { @@ -34,32 +35,23 @@ namespace ICSharpCode.UnitTesting } public override string DisplayName { - get { return primaryPart.Name; } + get { return fullTypeName.Name; } } - /// - /// For top-level classes: returns the full name of the class. - /// For nested classes: returns the full name of the top-level class that contains this test class. - /// - public FullNameAndTypeParameterCount TopLevelClassName { - get { - IUnresolvedTypeDefinition top = primaryPart; - while (top.DeclaringTypeDefinition != null) - top = top.DeclaringTypeDefinition; - return new FullNameAndTypeParameterCount(top.Namespace, top.Name, top.TypeParameters.Count); - } + public FullTypeName FullTypeName { + get { return fullTypeName; } } public string ClassName { - get { return primaryPart.Name; } + get { return fullTypeName.Name; } } public int TypeParameterCount { - get { return primaryPart.TypeParameters.Count; } + get { return fullTypeName.TypeParameterCount; } } public string ReflectionName { - get { return primaryPart.ReflectionName; } + get { return fullTypeName.ReflectionName; } } public override System.Windows.Input.ICommand GoToDefinition { @@ -76,7 +68,7 @@ namespace ICSharpCode.UnitTesting ITypeDefinition Resolve() { ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project); - IType type = primaryPart.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly)); + IType type = compilation.MainAssembly.GetTypeDefinition(fullTypeName); return type.GetDefinition(); } @@ -116,7 +108,7 @@ namespace ICSharpCode.UnitTesting public void UpdateTestClass(ITypeDefinition typeDefinition) { - primaryPart = typeDefinition.Parts[0]; + fullTypeName = typeDefinition.FullTypeName; if (this.NestedTestsInitialized) { int baseClassIndex = 0; foreach (IType baseType in typeDefinition.GetNonInterfaceBaseTypes()) { @@ -126,7 +118,7 @@ namespace ICSharpCode.UnitTesting continue; if (baseTypeDef.DeclaringTypeDefinition != null) continue; // we only support inheriting from top-level classes - var baseClassName = new FullNameAndTypeParameterCount(baseTypeDef.Namespace, baseTypeDef.Name, baseTypeDef.TypeParameterCount); + var baseClassName = baseTypeDef.FullTypeName; if (baseClassIndex < baseClassNames.Count && baseClassName == baseClassNames[baseClassIndex]) { // base class is already in the list, just keep it baseClassIndex++; @@ -151,7 +143,7 @@ namespace ICSharpCode.UnitTesting if (nestedTestClass != null) { nestedTestClass.UpdateTestClass(nestedClass); } else { - nestedTestClass = new NUnitTestClass(parentProject, nestedClass); + nestedTestClass = new NUnitTestClass(parentProject, nestedClass.FullTypeName); this.NestedTestCollection.Add(nestedTestClass); } newOrUpdatedNestedTests.Add(nestedTestClass); @@ -162,11 +154,11 @@ namespace ICSharpCode.UnitTesting continue; IUnresolvedMethod unresolvedMethod = (IUnresolvedMethod)method.UnresolvedMember; - IUnresolvedTypeDefinition derivedFixture; + FullTypeName derivedFixture; if (method.DeclaringTypeDefinition == typeDefinition) - derivedFixture = null; // method is not inherited + derivedFixture = default(FullTypeName); // method is not inherited else - derivedFixture = primaryPart; // method is inherited + derivedFixture = fullTypeName; // method is inherited NUnitTestMethod testMethod = FindTestMethod(method.Name); if (testMethod != null) { diff --git a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestMethod.cs b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestMethod.cs index 5f313ec598..4a913f7cfc 100644 --- a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestMethod.cs +++ b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestMethod.cs @@ -15,19 +15,19 @@ namespace ICSharpCode.UnitTesting public class NUnitTestMethod : TestBase { readonly ITestProject parentProject; - IUnresolvedTypeDefinition derivedFixture; + FullTypeName derivedFixture; IUnresolvedMethod method; string displayName; - public NUnitTestMethod(ITestProject parentProject, IUnresolvedMethod method, IUnresolvedTypeDefinition fixture = null) + public NUnitTestMethod(ITestProject parentProject, IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName)) { if (parentProject == null) throw new ArgumentNullException("parentProject"); this.parentProject = parentProject; - UpdateTestMethod(method, fixture); + UpdateTestMethod(method, derivedFixture); } - public void UpdateTestMethod(IUnresolvedMethod method, IUnresolvedTypeDefinition derivedFixture = null) + public void UpdateTestMethod(IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName)) { if (method == null) throw new ArgumentNullException("method"); @@ -54,7 +54,7 @@ namespace ICSharpCode.UnitTesting public override event EventHandler DisplayNameChanged; public bool IsInherited { - get { return derivedFixture != null; } + get { return derivedFixture.Name != null; } } public string MethodName { @@ -66,7 +66,7 @@ namespace ICSharpCode.UnitTesting } public string FixtureReflectionName { - get { return (derivedFixture ?? method.DeclaringTypeDefinition).ReflectionName; } + get { return IsInherited ? derivedFixture.ReflectionName : method.DeclaringTypeDefinition.ReflectionName; } } public void UpdateTestResult(TestResult result) diff --git a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestProject.cs b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestProject.cs index 5039116491..53a6cc45d7 100644 --- a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestProject.cs +++ b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestProject.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.UnitTesting protected override ITest CreateTestClass(ITypeDefinition typeDefinition) { if (NUnitTestFramework.IsTestClass(typeDefinition)) - return new NUnitTestClass(this, typeDefinition); + return new NUnitTestClass(this, typeDefinition.FullTypeName); else return null; } @@ -61,9 +61,9 @@ namespace ICSharpCode.UnitTesting if (typeDefinition.IsAbstract) { tests = from c in entity.ParentAssembly.GetAllTypeDefinitions() where c.IsDerivedFrom(typeDefinition) - select GetTestForEntityInClass(FindTestClass(c.ToTypeReference()), entity); + select GetTestForEntityInClass(FindTestClass(c.FullTypeName), entity); } else { - NUnitTestClass c = FindTestClass(typeDefinition.ToTypeReference()); + NUnitTestClass c = FindTestClass(typeDefinition.FullTypeName); tests = new [] { GetTestForEntityInClass(c, entity) }; } // GetTestForEntityInClass might return null, so filter those out: @@ -89,13 +89,13 @@ namespace ICSharpCode.UnitTesting return; string fixtureName = result.Name.Substring(0, lastDot); string methodName = result.Name.Substring(lastDot + 1); - NUnitTestClass testClass = FindTestClass(fixtureName); + NUnitTestClass testClass = FindTestClass(new FullTypeName(fixtureName)); if (testClass == null) { // maybe it's an inherited test int secondToLastDot = result.Name.LastIndexOf('.', lastDot - 1); if (secondToLastDot >= 0) { string fixtureName2 = result.Name.Substring(0, secondToLastDot); - testClass = FindTestClass(fixtureName2); + testClass = FindTestClass(new FullTypeName(fixtureName2)); } } if (testClass != null) { @@ -106,46 +106,38 @@ namespace ICSharpCode.UnitTesting } } - NUnitTestClass FindTestClass(string fixtureName) + NUnitTestClass FindTestClass(FullTypeName fullTypeName) { - ITypeReference r = ReflectionHelper.ParseReflectionName(fixtureName); - return FindTestClass(r); - } - - NUnitTestClass FindTestClass(ITypeReference r) - { - var gctr = r as GetClassTypeReference; - if (gctr != null) { - return (NUnitTestClass)GetTestClass(new FullNameAndTypeParameterCount(gctr.Namespace, gctr.Name, gctr.TypeParameterCount)); - } - var ntc = r as NestedTypeReference; - if (ntc != null) { - NUnitTestClass declaringTestClass = FindTestClass(ntc.DeclaringTypeReference); - if (declaringTestClass != null) - return declaringTestClass.FindNestedTestClass(ntc.Name, declaringTestClass.TypeParameterCount + ntc.AdditionalTypeParameterCount); + var testClass = (NUnitTestClass)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 null; + return testClass; } #region Test Inheritance - MultiDictionary inheritedTestClasses = new MultiDictionary(); + MultiDictionary inheritedTestClasses = new MultiDictionary(); - public void RegisterInheritedClass(FullNameAndTypeParameterCount baseClassName, NUnitTestClass inheritedClass) + public void RegisterInheritedClass(FullTypeName baseClassName, NUnitTestClass inheritedClass) { - inheritedTestClasses.Add(baseClassName, inheritedClass); + inheritedTestClasses.Add(baseClassName.TopLevelTypeName, inheritedClass); } - public void RemoveInheritedClass(FullNameAndTypeParameterCount baseClassName, NUnitTestClass inheritedClass) + public void RemoveInheritedClass(FullTypeName baseClassName, NUnitTestClass inheritedClass) { - inheritedTestClasses.Remove(baseClassName, inheritedClass); + inheritedTestClasses.Remove(baseClassName.TopLevelTypeName, inheritedClass); } - protected override void AddToDirtyList(FullNameAndTypeParameterCount className) + protected override void AddToDirtyList(TopLevelTypeName className) { // When a base class is invalidated, also invalidate all derived classes base.AddToDirtyList(className); foreach (var derivedClass in inheritedTestClasses[className]) { - base.AddToDirtyList(derivedClass.TopLevelClassName); + base.AddToDirtyList(derivedClass.FullTypeName.TopLevelTypeName); } } #endregion diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs index de02e08932..a2afbf1fe5 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs @@ -116,6 +116,11 @@ namespace CSharpBinding.Completion return CreateMethodDataProvider(startOffset, type.GetConstructors()); } + IParameterDataProvider IParameterCompletionDataFactory.CreateConstructorProvider(int startOffset, IType type, AstNode thisInitializer) + { + return CreateMethodDataProvider(startOffset, type.GetConstructors()); + } + IParameterDataProvider IParameterCompletionDataFactory.CreateMethodDataProvider(int startOffset, IEnumerable methods) { return CreateMethodDataProvider(startOffset, methods);