Browse Source

Add "IUsingScope" to allow representing the nesting of usings in namespaces in SharpDevelop.Dom.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3675 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
ba290b6bf9
  1. 8
      src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs
  2. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonResolver.cs
  4. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseImportTestFixture.cs
  5. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/NamespaceContentsAddedToCtrlSpaceTestFixture.cs
  6. 11
      src/AddIns/Misc/CodeAnalysis/Src/SuppressMessageCommand.cs
  7. 6
      src/AddIns/Misc/UnitTesting/Test/Utils/MockClass.cs
  8. 8
      src/Main/Base/Project/Src/Services/RefactoringService/NamespaceRefactoringService.cs
  9. 8
      src/Main/Base/Test/MemberLookupHelperTests.cs
  10. 6
      src/Main/Base/Test/SearchClassTests.cs
  11. 8
      src/Main/Base/Test/SearchGenericClassTests.cs
  12. 6
      src/Main/Base/Test/Utils/MockClass.cs
  13. 2
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj
  14. 2
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CtrlSpaceResolveHelper.cs
  15. 29
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExtensionMethods.cs
  16. 11
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AbstractEntity.cs
  17. 25
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs
  18. 14
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultCompilationUnit.cs
  19. 70
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultUsingScope.cs
  20. 7
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IClass.cs
  21. 6
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/ICompilationUnit.cs
  22. 46
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IUsingScope.cs
  23. 53
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  24. 25
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs
  25. 6
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs
  26. 6
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs

8
src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs

@ -137,7 +137,7 @@ namespace Grunwald.BooBinding.CodeCompletion @@ -137,7 +137,7 @@ namespace Grunwald.BooBinding.CodeCompletion
u.Usings.Add(p.Namespace);
else
u.AddAlias(p.Alias.Name, new GetClassReturnType(_cu.ProjectContent, p.Namespace, 0));
_cu.Usings.Add(u);
_cu.UsingScope.Usings.Add(u);
}
private IClass OuterClass {
@ -504,6 +504,12 @@ namespace Grunwald.BooBinding.CodeCompletion @@ -504,6 +504,12 @@ namespace Grunwald.BooBinding.CodeCompletion
OuterClass.Properties.Add(property);
property.UserData = node;
}
public override void OnNamespaceDeclaration(Boo.Lang.Compiler.Ast.NamespaceDeclaration node)
{
_cu.UsingScope = new DefaultUsingScope { NamespaceName = node.Name };
base.OnNamespaceDeclaration(node);
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs

@ -108,7 +108,7 @@ namespace ICSharpCode.PythonBinding @@ -108,7 +108,7 @@ namespace ICSharpCode.PythonBinding
Console.WriteLine("Name: " + name.MakeString());
newUsing.Usings.Add(name.MakeString());
}
compilationUnit.Usings.Add(newUsing);
compilationUnit.UsingScope.Usings.Add(newUsing);
return false;
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonResolver.cs

@ -287,7 +287,7 @@ namespace ICSharpCode.PythonBinding @@ -287,7 +287,7 @@ namespace ICSharpCode.PythonBinding
if (typeName != null) {
IClass resolvedClass = GetClass(typeName);
if (resolvedClass != null) {
DefaultClass dummyClass = new DefaultClass(null, "Global");
DefaultClass dummyClass = new DefaultClass(DefaultCompilationUnit.DummyCompilationUnit, "Global");
DefaultMethod dummyMethod = new DefaultMethod(dummyClass, String.Empty);
DefaultField.LocalVariableField field = new DefaultField.LocalVariableField(resolvedClass.DefaultReturnType, expression, DomRegion.Empty, dummyClass);
return new LocalResolveResult(dummyMethod, field);

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseImportTestFixture.cs

@ -38,13 +38,13 @@ namespace PythonBinding.Tests.Parsing @@ -38,13 +38,13 @@ namespace PythonBinding.Tests.Parsing
[Test]
public void OneUsing()
{
Assert.AreEqual(1, compilationUnit.Usings.Count);
Assert.AreEqual(1, compilationUnit.UsingScope.Usings.Count);
}
[Test]
public void UsingSystem()
{
Assert.AreEqual("System", compilationUnit.Usings[0].Usings[0]);
Assert.AreEqual("System", compilationUnit.UsingScope.Usings[0].Usings[0]);
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/NamespaceContentsAddedToCtrlSpaceTestFixture.cs

@ -44,7 +44,7 @@ namespace PythonBinding.Tests.Resolver @@ -44,7 +44,7 @@ namespace PythonBinding.Tests.Resolver
// Add usings.
DefaultUsing newUsing = new DefaultUsing(cu.ProjectContent);
newUsing.Usings.Add("MyNamespace");
cu.Usings.Add(newUsing);
cu.UsingScope.Usings.Add(newUsing);
results = resolver.CtrlSpace(0, "".Length, parseInfo, "", ExpressionContext.Default);
}

11
src/AddIns/Misc/CodeAnalysis/Src/SuppressMessageCommand.cs

@ -141,11 +141,20 @@ namespace ICSharpCode.CodeAnalysis @@ -141,11 +141,20 @@ namespace ICSharpCode.CodeAnalysis
{
if (CheckImports(cu.ProjectContent.DefaultImports))
return true;
foreach (IUsing u in cu.Usings) {
return CheckImports(cu.UsingScope);
}
static bool CheckImports(IUsingScope scope)
{
foreach (IUsing u in scope.Usings) {
if (CheckImports(u)) {
return true;
}
}
foreach (IUsingScope childscope in scope.ChildScopes) {
if (CheckImports(childscope))
return true;
}
return false;
}

6
src/AddIns/Misc/UnitTesting/Test/Utils/MockClass.cs

@ -127,6 +127,12 @@ namespace UnitTesting.Tests.Utils @@ -127,6 +127,12 @@ namespace UnitTesting.Tests.Utils
}
}
public IUsingScope UsingScope {
get {
throw new NotImplementedException();
}
}
public DomRegion BodyRegion {
get {
throw new NotImplementedException();

8
src/Main/Base/Project/Src/Services/RefactoringService/NamespaceRefactoringService.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -46,7 +46,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (info == null) return;
ICompilationUnit cu = info.MostRecentCompilationUnit;
List<IUsing> newUsings = new List<IUsing>(cu.Usings);
List<IUsing> newUsings = new List<IUsing>(cu.UsingScope.Usings);
if (sort) {
newUsings.Sort(CompareUsings);
}
@ -72,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -72,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
PutEmptyLineAfterLastSystemNamespace(newUsings);
}
cu.ProjectContent.Language.CodeGenerator.ReplaceUsings(new TextEditorDocument(document), cu.Usings, newUsings);
cu.ProjectContent.Language.CodeGenerator.ReplaceUsings(new TextEditorDocument(document), cu.UsingScope.Usings, newUsings);
}
static void PutEmptyLineAfterLastSystemNamespace(List<IUsing> newUsings)
@ -98,7 +98,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -98,7 +98,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
IUsing newUsingDecl = new DefaultUsing(cu.ProjectContent);
newUsingDecl.Usings.Add(newNamespace);
List<IUsing> newUsings = new List<IUsing>(cu.Usings);
List<IUsing> newUsings = new List<IUsing>(cu.UsingScope.Usings);
if (sortExistingUsings) {
newUsings.Sort(CompareUsings);
}
@ -118,7 +118,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -118,7 +118,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (sortExistingUsings) {
PutEmptyLineAfterLastSystemNamespace(newUsings);
}
cu.ProjectContent.Language.CodeGenerator.ReplaceUsings(new TextEditorDocument(document), cu.Usings, newUsings);
cu.ProjectContent.Language.CodeGenerator.ReplaceUsings(new TextEditorDocument(document), cu.UsingScope.Usings, newUsings);
}
}
}

8
src/Main/Base/Test/MemberLookupHelperTests.cs

@ -89,8 +89,8 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -89,8 +89,8 @@ namespace ICSharpCode.SharpDevelop.Tests
DefaultProjectContent dpc = new DefaultProjectContent();
dpc.ReferencedContents.Add(msc);
DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc);
cu.Usings.Add(new DefaultUsing(dpc, new DomRegion(1,1, 5,5)));
cu.Usings[0].Usings.Add("System.Collections.Generic");
cu.UsingScope.Usings.Add(new DefaultUsing(dpc, new DomRegion(1,1, 5,5)));
cu.UsingScope.Usings[0].Usings.Add("System.Collections.Generic");
DefaultClass listDerivingClass = new DefaultClass(cu, "DerivesFromList");
cu.Classes.Add(listDerivingClass);
@ -108,8 +108,8 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -108,8 +108,8 @@ namespace ICSharpCode.SharpDevelop.Tests
DefaultProjectContent dpc = new DefaultProjectContent();
dpc.ReferencedContents.Add(msc);
DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc);
cu.Usings.Add(new DefaultUsing(dpc, new DomRegion(1,1, 5,5)));
cu.Usings[0].Usings.Add("System.Collections.Generic");
cu.UsingScope.Usings.Add(new DefaultUsing(dpc, new DomRegion(1,1, 5,5)));
cu.UsingScope.Usings[0].Usings.Add("System.Collections.Generic");
DefaultClass listDerivingClass = new DefaultClass(cu, "DerivesFromList");
cu.Classes.Add(listDerivingClass);

6
src/Main/Base/Test/SearchClassTests.cs

@ -25,9 +25,9 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -25,9 +25,9 @@ namespace ICSharpCode.SharpDevelop.Tests
pc.Language = language;
DefaultCompilationUnit cu = new DefaultCompilationUnit(pc);
if (language == LanguageProperties.VBNet)
cu.Usings.Add(CreateUsing(pc, "syStEm"));
cu.UsingScope.Usings.Add(CreateUsing(pc, "syStEm"));
else
cu.Usings.Add(CreateUsing(pc, "System"));
cu.UsingScope.Usings.Add(CreateUsing(pc, "System"));
return cu;
}
@ -168,7 +168,7 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -168,7 +168,7 @@ namespace ICSharpCode.SharpDevelop.Tests
ICompilationUnit cu = Prepare(LanguageProperties.CSharp);
cu.ProjectContent.ReferencedContents.Add(ref1.ProjectContent);
cu.ProjectContent.ReferencedContents.Add(ref2.ProjectContent);
cu.Usings.Add(new DefaultUsing(cu.ProjectContent) { Usings = { "NS1", "NS2" } });
cu.UsingScope.Usings.Add(new DefaultUsing(cu.ProjectContent) { Usings = { "NS1", "NS2" } });
SearchTypeResult r = cu.ProjectContent.SearchType(new SearchTypeRequest("ClassName", 0, null, cu, 1, 1));
Assert.AreEqual(ModifierEnum.Public, r.Result.GetUnderlyingClass().Modifiers);

8
src/Main/Base/Test/SearchGenericClassTests.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -29,7 +29,7 @@ namespace ICSharpCode.SharpDevelop.Tests
pc.Language = language;
DefaultCompilationUnit cu = new DefaultCompilationUnit(pc);
if (usingMode == 1) {
cu.Usings.Add(CreateUsing(pc, "syStEm.coLLectIons"));
cu.UsingScope.Usings.Add(CreateUsing(pc, "syStEm.coLLectIons"));
pc.DefaultImports = new DefaultUsing(pc);
pc.DefaultImports.Usings.Add("syStEm");
pc.DefaultImports.Usings.Add("syStEm.coLLEctionS.GeNeRic");
@ -39,9 +39,9 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -39,9 +39,9 @@ namespace ICSharpCode.SharpDevelop.Tests
pc.DefaultImports.Usings.Add("syStEm.coLLEctioNs");
pc.DefaultImports.Usings.Add("syStEm.coLLEctionS.GeNeRic");
} else { // usingMode == 0
cu.Usings.Add(CreateUsing(pc, "System"));
cu.Usings.Add(CreateUsing(pc, "System.Collections"));
cu.Usings.Add(CreateUsing(pc, "System.Collections.Generic"));
cu.UsingScope.Usings.Add(CreateUsing(pc, "System"));
cu.UsingScope.Usings.Add(CreateUsing(pc, "System.Collections"));
cu.UsingScope.Usings.Add(CreateUsing(pc, "System.Collections.Generic"));
}
return cu;
}

6
src/Main/Base/Test/Utils/MockClass.cs

@ -61,6 +61,12 @@ namespace ICSharpCode.SharpDevelop.Tests.Utils @@ -61,6 +61,12 @@ namespace ICSharpCode.SharpDevelop.Tests.Utils
}
}
public IUsingScope UsingScope {
get {
throw new NotImplementedException();
}
}
public DomRegion Region {
get {
throw new NotImplementedException();

2
src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj

@ -88,6 +88,7 @@ @@ -88,6 +88,7 @@
<Compile Include="Src\Implementations\DefaultReturnType.cs" />
<Compile Include="Src\Implementations\DefaultTypeParameter.cs" />
<Compile Include="Src\Implementations\DefaultUsing.cs" />
<Compile Include="Src\Implementations\DefaultUsingScope.cs" />
<Compile Include="Src\Implementations\ElementReturnType.cs" />
<Compile Include="Src\Implementations\GenericReturnType.cs" />
<Compile Include="Src\Implementations\GetClassReturnType.cs" />
@ -102,6 +103,7 @@ @@ -102,6 +103,7 @@
<Compile Include="Src\Interfaces\ExplicitInterfaceImplementation.cs" />
<Compile Include="Src\Interfaces\IDomProgressMonitor.cs" />
<Compile Include="Src\Interfaces\IFreezable.cs" />
<Compile Include="Src\Interfaces\IUsingScope.cs" />
<Compile Include="Src\LazyList.cs" />
<Compile Include="Src\NRefactoryResolver\CodeSnippetConverter.cs" />
<Compile Include="Src\NRefactoryResolver\CSharpToVBNetConvertVisitor.cs" />

2
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CtrlSpaceResolveHelper.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -84,7 +84,7 @@ namespace ICSharpCode.SharpDevelop.Dom
{
IProjectContent projectContent = cu.ProjectContent;
projectContent.AddNamespaceContents(result, "", projectContent.Language, true);
foreach (IUsing u in cu.Usings) {
foreach (IUsing u in cu.GetAllUsings()) {
AddUsing(result, u, projectContent);
}
AddUsing(result, projectContent.DefaultImports, projectContent);

29
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExtensionMethods.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.SharpDevelop.Dom
{
@ -27,5 +28,33 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -27,5 +28,33 @@ namespace ICSharpCode.SharpDevelop.Dom
foreach (T o in elements)
list.Add(o);
}
public static IEnumerable<T> Flatten<T>(this IEnumerable<T> input, Func<T, IEnumerable<T>> recursion)
{
Stack<IEnumerator<T>> stack = new Stack<IEnumerator<T>>();
try {
stack.Push(input.GetEnumerator());
while (stack.Count > 0) {
while (stack.Peek().MoveNext()) {
T element = stack.Peek().Current;
yield return element;
IEnumerable<T> children = recursion(element);
if (children != null) {
stack.Push(children.GetEnumerator());
}
}
stack.Pop();
}
} finally {
while (stack.Count > 0) {
stack.Pop().Dispose();
}
}
}
public static IEnumerable<IUsing> GetAllUsings(this ICompilationUnit cu)
{
return (new[]{cu.UsingScope}).Flatten(s=>s.ChildScopes).SelectMany(s=>s.Usings);
}
}
}

11
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AbstractEntity.cs

@ -18,9 +18,9 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -18,9 +18,9 @@ namespace ICSharpCode.SharpDevelop.Dom
IClass declaringType;
string fullyQualifiedName = null;
string name = null;
string nspace = null;
string fullyQualifiedName;
string name;
string nspace;
public AbstractEntity(IClass declaringType)
{
@ -29,11 +29,10 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -29,11 +29,10 @@ namespace ICSharpCode.SharpDevelop.Dom
public AbstractEntity(IClass declaringType, string name)
{
if (declaringType == null)
throw new ArgumentNullException("declaringType");
this.declaringType = declaringType;
this.name = name;
nspace = declaringType.FullyQualifiedName;
if (declaringType != null)
nspace = declaringType.FullyQualifiedName;
// lazy-computing the fully qualified name for class members saves ~7 MB RAM (when loading the SharpDevelop solution).
//fullyQualifiedName = nspace + '.' + name;

25
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -26,6 +26,7 @@ namespace ICSharpCode.SharpDevelop.Dom
IList<IMethod> methods;
IList<IEvent> events;
IList<ITypeParameter> typeParameters;
IUsingScope usingScope;
protected override void FreezeInternal()
{
@ -119,23 +120,47 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -119,23 +120,47 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
/// <summary>
/// Gets the using scope of contains this class.
/// </summary>
public IUsingScope UsingScope {
get { return usingScope; }
set {
if (value == null)
throw new ArgumentNullException("UsingScope");
CheckBeforeMutation();
usingScope = value;
}
}
public DefaultClass(ICompilationUnit compilationUnit, string fullyQualifiedName) : base(null)
{
if (compilationUnit == null)
throw new ArgumentNullException("compilationUnit");
if (fullyQualifiedName == null)
throw new ArgumentNullException("fullyQualifiedName");
this.compilationUnit = compilationUnit;
this.FullyQualifiedName = fullyQualifiedName;
this.UsingScope = compilationUnit.UsingScope;
}
public DefaultClass(ICompilationUnit compilationUnit, IClass declaringType) : base(declaringType)
{
if (compilationUnit == null)
throw new ArgumentNullException("compilationUnit");
this.compilationUnit = compilationUnit;
this.UsingScope = compilationUnit.UsingScope;
}
public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType)
{
if (compilationUnit == null)
throw new ArgumentNullException("compilationUnit");
this.compilationUnit = compilationUnit;
this.region = region;
this.classType = classType;
Modifiers = modifiers;
this.UsingScope = compilationUnit.UsingScope;
}
// fields must be volatile to ensure that the optimizer doesn't reorder accesses to it

14
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultCompilationUnit.cs

@ -21,7 +21,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -21,7 +21,7 @@ namespace ICSharpCode.SharpDevelop.Dom
return this;
}
IList<IUsing> usings = new List<IUsing>();
IUsingScope usingScope = new DefaultUsingScope();
IList<IClass> classes = new List<IClass>();
IList<IAttribute> attributes = new List<IAttribute>();
IList<FoldingRegion> foldingRegions = new List<FoldingRegion>();
@ -30,11 +30,11 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -30,11 +30,11 @@ namespace ICSharpCode.SharpDevelop.Dom
protected override void FreezeInternal()
{
// Deep Freeze: freeze lists and their contents
usings = FreezeList(usings);
classes = FreezeList(classes);
attributes = FreezeList(attributes);
foldingRegions = FreezeList(foldingRegions);
tagComments = FreezeList(tagComments);
usingScope.Freeze();
base.FreezeInternal();
}
@ -85,9 +85,13 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -85,9 +85,13 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
public virtual IList<IUsing> Usings {
get {
return usings;
public virtual IUsingScope UsingScope {
get { return usingScope; }
set {
if (value == null)
throw new ArgumentNullException("UsingScope");
CheckBeforeMutation();
usingScope = value;
}
}

70
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultUsingScope.cs

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.SharpDevelop.Dom
{
public class DefaultUsingScope : AbstractFreezable, IUsingScope
{
DomRegion region;
IUsingScope parent;
IList<IUsing> usings;
IList<IUsingScope> childScopes;
string namespaceName = "";
protected override void FreezeInternal()
{
base.FreezeInternal();
usings = FreezeList(usings);
childScopes = FreezeList(childScopes);
}
public DomRegion Region {
get { return region; }
set {
CheckBeforeMutation();
region = value;
}
}
public IUsingScope Parent {
get { return parent; }
set {
CheckBeforeMutation();
parent = value;
}
}
public virtual IList<IUsing> Usings {
get {
if (usings == null)
usings = new List<IUsing>();
return usings;
}
}
public virtual IList<IUsingScope> ChildScopes {
get {
if (childScopes == null)
childScopes = new List<IUsingScope>();
return childScopes;
}
}
public string NamespaceName {
get { return namespaceName; }
set {
if (value == null)
throw new ArgumentNullException("NamespaceName");
CheckBeforeMutation();
namespaceName = value;
}
}
}
}

7
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IClass.cs

@ -43,6 +43,13 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -43,6 +43,13 @@ namespace ICSharpCode.SharpDevelop.Dom
get;
}
/// <summary>
/// Gets the using scope of contains this class.
/// </summary>
IUsingScope UsingScope {
get;
}
IList<IReturnType> BaseTypes {
get;
}

6
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/ICompilationUnit.cs

@ -30,7 +30,11 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -30,7 +30,11 @@ namespace ICSharpCode.SharpDevelop.Dom
get;
}
IList<IUsing> Usings {
/// <summary>
/// Gets the main using scope of the compilation unit.
/// That scope usually represents the root namespace.
/// </summary>
IUsingScope UsingScope {
get;
}

46
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IUsingScope.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.SharpDevelop.Dom
{
/// <summary>
/// A scope that can contain using declarations.
/// In C#, every file is a using scope, and every "namespace" declaration inside
/// the file is a nested using scope.
/// </summary>
public interface IUsingScope : IFreezable
{
/// <summary>
/// Gets the region of the using scope.
/// </summary>
DomRegion Region { get; }
/// <summary>
/// Gets the parent scope.
/// Returns null if this is a root scope.
/// </summary>
IUsingScope Parent { get; }
/// <summary>
/// Gets the usings in this using scope.
/// </summary>
IList<IUsing> Usings { get; }
/// <summary>
/// Gets the list of child scopes. Child scopes usually represent "namespace" declarations.
/// </summary>
IList<IUsingScope> ChildScopes { get; }
/// <summary>
/// Gets the name of the namespace represented by the using scope.
/// </summary>
string NamespaceName { get; }
}
}

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

@ -19,8 +19,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -19,8 +19,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
{
public class NRefactoryASTConvertVisitor : AbstractAstVisitor
{
ICompilationUnit cu;
Stack<string> currentNamespace = new Stack<string>();
DefaultCompilationUnit cu;
DefaultUsingScope currentNamespace;
Stack<DefaultClass> currentClass = new Stack<DefaultClass>();
public string VBRootNamespace { get; set; }
@ -181,13 +181,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -181,13 +181,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (compilationUnit == null) {
return null;
}
currentNamespace = new DefaultUsingScope();
if (!string.IsNullOrEmpty(VBRootNamespace)) {
currentNamespace.Push(VBRootNamespace);
compilationUnit.AcceptChildren(this, data);
currentNamespace.Pop();
} else {
compilationUnit.AcceptChildren(this, data);
currentNamespace.NamespaceName = VBRootNamespace;
}
cu.UsingScope = currentNamespace;
compilationUnit.AcceptChildren(this, data);
return cu;
}
@ -197,7 +196,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -197,7 +196,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
foreach (AST.Using u in usingDeclaration.Usings) {
u.AcceptVisitor(this, us);
}
cu.Usings.Add(us);
currentNamespace.Usings.Add(us);
return data;
}
@ -313,18 +312,24 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -313,18 +312,24 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return null;
}
string PrependCurrentNamespace(string name)
{
if (string.IsNullOrEmpty(currentNamespace.NamespaceName))
return name;
else
return currentNamespace.NamespaceName + "." + name;
}
public override object VisitNamespaceDeclaration(AST.NamespaceDeclaration namespaceDeclaration, object data)
{
string name;
if (currentNamespace.Count == 0) {
name = namespaceDeclaration.Name;
} else {
name = currentNamespace.Peek() + '.' + namespaceDeclaration.Name;
}
currentNamespace.Push(name);
DefaultUsingScope oldNamespace = currentNamespace;
currentNamespace = new DefaultUsingScope {
Parent = oldNamespace,
NamespaceName = PrependCurrentNamespace(namespaceDeclaration.Name),
};
oldNamespace.ChildScopes.Add(currentNamespace);
object ret = namespaceDeclaration.AcceptChildren(this, data);
currentNamespace.Pop();
currentNamespace = oldNamespace;
return ret;
}
@ -364,13 +369,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -364,13 +369,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
cur.InnerClasses.Add(c);
c.FullyQualifiedName = cur.FullyQualifiedName + '.' + typeDeclaration.Name;
} else {
if (currentNamespace.Count == 0) {
c.FullyQualifiedName = typeDeclaration.Name;
} else {
c.FullyQualifiedName = currentNamespace.Peek() + '.' + typeDeclaration.Name;
}
c.FullyQualifiedName = PrependCurrentNamespace(typeDeclaration.Name);
cu.Classes.Add(c);
}
c.UsingScope = currentNamespace;
currentClass.Push(c);
ConvertTemplates(typeDeclaration.Templates, c); // resolve constrains in context of the class
@ -468,13 +470,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -468,13 +470,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
cur.InnerClasses.Add(c);
c.FullyQualifiedName = cur.FullyQualifiedName + '.' + name;
} else {
if (currentNamespace.Count == 0) {
c.FullyQualifiedName = name;
} else {
c.FullyQualifiedName = currentNamespace.Peek() + '.' + name;
}
c.FullyQualifiedName = PrependCurrentNamespace(name);
cu.Classes.Add(c);
}
c.UsingScope = currentNamespace;
currentClass.Push(c); // necessary for CreateReturnType
ConvertTemplates(templates, c);

25
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs

@ -205,7 +205,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -205,7 +205,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
} else if ("global".Equals(expression, StringComparison.InvariantCultureIgnoreCase)) {
return new NamespaceResolveResult(null, null, "");
}
// array
// array
} else if (language == NR.SupportedLanguage.CSharp && expressionResult.Context.IsTypeContext && !expressionResult.Context.IsObjectCreation) {
expr = ParseTypeReference(expression);
}
@ -596,16 +596,19 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -596,16 +596,19 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
if (languageProperties.CanImportClasses) {
foreach (IUsing @using in cu.Usings) {
foreach (string import in @using.Usings) {
IClass c = GetClass(import, 0);
if (c != null) {
ResolveResult rr = ResolveMember(c.DefaultReturnType, identifier,
identifierExpression.TypeArguments,
IsInvoked(identifierExpression),
false, null);
if (rr != null && rr.IsValid)
return rr;
IUsingScope scope = callingClass != null ? callingClass.UsingScope : cu.UsingScope;
for (; scope != null; scope = scope.Parent) {
foreach (IUsing @using in scope.Usings) {
foreach (string import in @using.Usings) {
IClass c = GetClass(import, 0);
if (c != null) {
ResolveResult rr = ResolveMember(c.DefaultReturnType, identifier,
identifierExpression.TypeArguments,
IsInvoked(identifierExpression),
false, null);
if (rr != null && rr.IsValid)
return rr;
}
}
}
}

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

@ -238,7 +238,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -238,7 +238,7 @@ namespace ICSharpCode.SharpDevelop.Dom
/// </summary>
private class GenericClassContainer : DefaultClass
{
public GenericClassContainer(string fullyQualifiedName) : base(null, fullyQualifiedName) {}
public GenericClassContainer(string fullyQualifiedName) : base(DefaultCompilationUnit.DummyCompilationUnit, fullyQualifiedName) {}
IClass[] realClasses = new IClass[4];
@ -744,7 +744,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -744,7 +744,7 @@ namespace ICSharpCode.SharpDevelop.Dom
return null;
}
foreach (IUsing u in unit.Usings) {
foreach (IUsing u in unit.GetAllUsings()) {
if (u != null) {
string nameSpace = u.SearchNamespace(name);
if (nameSpace != null) {
@ -854,7 +854,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -854,7 +854,7 @@ namespace ICSharpCode.SharpDevelop.Dom
}
if (request.CurrentCompilationUnit != null) {
// Combine name with usings
foreach (IUsing u in request.CurrentCompilationUnit.Usings) {
foreach (IUsing u in request.CurrentCompilationUnit.GetAllUsings()) {
if (u != null) {
foreach (IReturnType r in u.SearchType(name, request.TypeParameterCount)) {
if (MatchesRequest(ref request, r)) {

6
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ICSharpCode.NRefactory.Ast;
@ -510,7 +511,8 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -510,7 +511,8 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
if (tr.ExtensionMethod != null) {
// the invocation of an extension method can implicitly use a using
StringComparer nameComparer = cu.ProjectContent.Language.NameComparer;
foreach (IUsing import in cu.Usings) {
// go through all usings in all nested child scopes
foreach (IUsing import in cu.GetAllUsings()) {
foreach (string i in import.Usings) {
if (nameComparer.Equals(tr.ExtensionMethod.DeclaringType.Namespace, i)) {
usedUsings.Add(import);
@ -528,7 +530,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -528,7 +530,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
}
List<IUsing> unusedUsings = new List<IUsing>();
foreach (IUsing import in cu.Usings) {
foreach (IUsing import in cu.GetAllUsings()) {
if (!usedUsings.Contains(import)) {
if (import.HasAliases) {
foreach (string key in import.Aliases.Keys) {

Loading…
Cancel
Save