Browse Source

Fixed the finding of classes to also check name-spaces.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/346/head
Dimitar Dobrev 11 years ago
parent
commit
4385ecac76
  1. 4
      src/AST/Namespace.cs
  2. 6
      src/Generator.Tests/AST/TestAST.cs
  3. 8
      src/Generator.Tests/QueryHelpers.cs
  4. 7
      tests/Native/AST.h

4
src/AST/Namespace.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
namespace CppSharp.AST
@ -254,7 +255,8 @@ namespace CppSharp.AST @@ -254,7 +255,8 @@ namespace CppSharp.AST
if (entries.Count <= 1)
{
var @class = Classes.Find(c => c.Name.Equals(name, stringComparison));
var @class = Classes.Find(c => c.Name.Equals(name, stringComparison)) ??
Namespaces.Select(n => n.FindClass(name, stringComparison)).FirstOrDefault(c => c != null);
if (@class != null)
return @class.CompleteDeclaration == null ?
@class : (Class) @class.CompleteDeclaration;

6
src/Generator.Tests/AST/TestAST.cs

@ -225,5 +225,11 @@ namespace CppSharp.Generator.Tests.AST @@ -225,5 +225,11 @@ namespace CppSharp.Generator.Tests.AST
Assert.IsTrue(typeDef.Type.TryGetClass(out classTemplate));
Assert.AreEqual(classTemplate, template.TemplatedClass);
}
[Test]
public void TestFindClassInNamespace()
{
Assert.IsNotNull(AstContext.FindClass("HiddenInNamespace").FirstOrDefault());
}
}
}

8
src/Generator.Tests/QueryHelpers.cs

@ -12,22 +12,22 @@ namespace CppSharp.Generator.Tests @@ -12,22 +12,22 @@ namespace CppSharp.Generator.Tests
public static Class Class(this ASTContext context, string name)
{
return context.FindClass(name).ToList().First();
return context.FindClass(name).First();
}
public static Function Function(this ASTContext context, string name)
{
return context.FindFunction(name).ToList().First();
return context.FindFunction(name).First();
}
public static Enumeration Enum(this ASTContext context, string name)
{
return context.FindEnum(name).ToList().First();
return context.FindEnum(name).First();
}
public static TypedefDecl Typedef(this ASTContext context, string name)
{
return context.FindTypedef(name).ToList().First();
return context.FindTypedef(name).First();
}
public static Field Field(this Class @class, string name)

7
tests/Native/AST.h

@ -57,3 +57,10 @@ class TestTemplateClass2 @@ -57,3 +57,10 @@ class TestTemplateClass2
public:
TestTemplateClassInt* CreateIntTemplate();
};
namespace HidesClass
{
class HiddenInNamespace
{
};
}

Loading…
Cancel
Save