Browse Source

Fixed SD2-863: Children of current Namespace resolved in wrong order

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2137 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
88cfacfba1
  1. 20
      src/Main/Base/Test/NRefactoryResolverTests.cs
  2. 8
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  3. 27
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

20
src/Main/Base/Test/NRefactoryResolverTests.cs

@ -752,6 +752,26 @@ class TestClass { @@ -752,6 +752,26 @@ class TestClass {
LocalResolveResult lr = Resolve<LocalResolveResult>(program, "a", 5);
Assert.AreEqual("System.Collections.ArrayList", lr.ResolvedType.FullyQualifiedName, "a");
}
[Test]
public void ResolveNamespaceSD2_863()
{
string program = @"using System;
namespace A.C { class D {} }
namespace A.B.C { class D {} }
namespace A.B {
class TestClass {
void Test() {
}
}
}
";
NamespaceResolveResult nrr = Resolve<NamespaceResolveResult>(program, "C", 7);
Assert.AreEqual("A.B.C", nrr.Name, "nrr.Name");
TypeResolveResult trr = Resolve<TypeResolveResult>(program, "C.D", 7);
Assert.AreEqual("A.B.C.D", trr.ResolvedClass.FullyQualifiedName, "trr.ResolvedClass.FullyQualifiedName");
}
#endregion
#region Import class tests

8
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -21,7 +21,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -21,7 +21,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
public class NRefactoryASTConvertVisitor : AbstractAstVisitor
{
ICompilationUnit cu;
Stack currentNamespace = new Stack();
Stack<string> currentNamespace = new Stack<string>();
Stack<DefaultClass> currentClass = new Stack<DefaultClass>();
public ICompilationUnit Cu {
@ -252,7 +252,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -252,7 +252,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (currentNamespace.Count == 0) {
name = namespaceDeclaration.Name;
} else {
name = (string)currentNamespace.Peek() + '.' + namespaceDeclaration.Name;
name = currentNamespace.Peek() + '.' + namespaceDeclaration.Name;
}
currentNamespace.Push(name);
@ -300,7 +300,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -300,7 +300,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (currentNamespace.Count == 0) {
c.FullyQualifiedName = typeDeclaration.Name;
} else {
c.FullyQualifiedName = (string)currentNamespace.Peek() + '.' + typeDeclaration.Name;
c.FullyQualifiedName = currentNamespace.Peek() + '.' + typeDeclaration.Name;
}
cu.Classes.Add(c);
}
@ -403,7 +403,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -403,7 +403,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (currentNamespace.Count == 0) {
c.FullyQualifiedName = name;
} else {
c.FullyQualifiedName = (string)currentNamespace.Peek() + '.' + name;
c.FullyQualifiedName = currentNamespace.Peek() + '.' + name;
}
cu.Classes.Add(c);
}

27
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

@ -737,22 +737,19 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -737,22 +737,19 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
if (curType != null) {
// Try parent namespaces of the current class
// Try relative to current namespace and relative to parent namespaces
string fullname = curType.Namespace;
if (fullname != null && fullname.Length > 0) {
string[] namespaces = fullname.Split('.');
StringBuilder curnamespace = new StringBuilder();
for (int i = 0; i < namespaces.Length; ++i) {
curnamespace.Append(namespaces[i]);
curnamespace.Append('.');
curnamespace.Append(name);
string nameSpace = curnamespace.ToString();
if (NamespaceExists(nameSpace)) {
return nameSpace;
}
// remove class name again to try next namespace
curnamespace.Length -= name.Length;
while (fullname != null && fullname.Length > 0) {
string nameSpace = fullname + '.' + name;
if (NamespaceExists(nameSpace)) {
return nameSpace;
}
int pos = fullname.LastIndexOf('.');
if (pos < 0) {
fullname = null;
} else {
fullname = fullname.Substring(0, pos);
}
}
}

Loading…
Cancel
Save