Skip to content

Commit 919e7f1

Browse files
maca88hazzik
authored andcommitted
started to porting unit tests
1 parent 8e43a15 commit 919e7f1

File tree

975 files changed

+85044
-1749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

975 files changed

+85044
-1749
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis;
7+
using Microsoft.CodeAnalysis.CSharp.Syntax;
8+
9+
namespace NHibernate.AsyncGenerator
10+
{
11+
public class AsyncCounterpartMethod
12+
{
13+
public ExpressionSyntax MethodNode { get; set; }
14+
15+
public IMethodSymbol MethodSymbol { get; set; }
16+
17+
public IMethodSymbol AsyncMethodSymbol { get; set; }
18+
}
19+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis;
7+
using Microsoft.CodeAnalysis.CSharp.Syntax;
8+
using Microsoft.CodeAnalysis.FindSymbols;
9+
using NHibernate.AsyncGenerator.Extensions;
10+
11+
namespace NHibernate.AsyncGenerator
12+
{
13+
public class DocumentInfo
14+
{
15+
public DocumentInfo(ProjectInfo projectInfo, Document document)
16+
{
17+
ProjectInfo = projectInfo;
18+
Document = document;
19+
}
20+
21+
public ProjectInfo ProjectInfo { get; }
22+
23+
public Document Document { get; }
24+
25+
public IReadOnlyList<string> Folders => Document.Folders;
26+
27+
public string Name => Document.Name;
28+
29+
public string Path => Document.FilePath;
30+
31+
public CompilationUnitSyntax RootNode { get; set; }
32+
33+
public SemanticModel SemanticModel { get; set; }
34+
35+
public Dictionary<INamespaceSymbol, NamespaceInfo> NamespaceInfos { get; } = new Dictionary<INamespaceSymbol, NamespaceInfo>();
36+
37+
public NamespaceInfo GetNamespaceInfo(ISymbol symbol, bool create = false)
38+
{
39+
var namespaceSymbol = symbol.ContainingNamespace;
40+
if (NamespaceInfos.ContainsKey(namespaceSymbol))
41+
{
42+
return NamespaceInfos[namespaceSymbol];
43+
}
44+
if (!create)
45+
{
46+
return null;
47+
}
48+
49+
var location = namespaceSymbol.Locations.Single(o => o.SourceTree.FilePath == Path);
50+
var node = RootNode.DescendantNodes()
51+
.OfType<NamespaceDeclarationSyntax>()
52+
.FirstOrDefault(
53+
o =>
54+
{
55+
var identifier = o.ChildNodes().OfType<IdentifierNameSyntax>().SingleOrDefault();
56+
if (identifier != null)
57+
{
58+
return identifier.Span == location.SourceSpan;
59+
}
60+
return o.ChildNodes().OfType<QualifiedNameSyntax>().Single().Right.Span == location.SourceSpan;
61+
});
62+
if (node == null) // location.SourceSpan.Start == 0 -> a bug perhaps ???
63+
{
64+
node = RootNode.DescendantNodes().OfType<NamespaceDeclarationSyntax>().Single(o => o.FullSpan.End == location.SourceSpan.End);
65+
}
66+
var docNamespace = new NamespaceInfo(this, namespaceSymbol, node);
67+
NamespaceInfos.Add(namespaceSymbol, docNamespace);
68+
return docNamespace;
69+
}
70+
71+
public MethodInfo GetOrCreateMethodInfo(IMethodSymbol symbol)
72+
{
73+
return GetNamespaceInfo(symbol, true).GetTypeInfo(symbol, true).GetMethodInfo(symbol, true);
74+
}
75+
76+
public TypeInfo GetTypeInfo(INamedTypeSymbol symbol)
77+
{
78+
return GetNamespaceInfo(symbol).GetTypeInfo(symbol);
79+
}
80+
81+
public bool ContainsReference(IMethodSymbol symbol, ReferenceLocation reference)
82+
{
83+
return GetNamespaceInfo(symbol)?.GetTypeInfo(symbol)?.GetMethodInfo(symbol)?.References?.Contains(reference) == true;
84+
}
85+
86+
public bool ContainsBodyToAsyncMethodReference(IMethodSymbol symbol, ReferenceLocation reference)
87+
{
88+
return GetNamespaceInfo(symbol)?.GetTypeInfo(symbol)?.GetMethodInfo(symbol)?.BodyToAsyncMethodsReferences?.Contains(reference) == true;
89+
}
90+
91+
public ISymbol GetEnclosingMethodOrPropertyOrField(ReferenceLocation reference)
92+
{
93+
var enclosingSymbol = SemanticModel.GetEnclosingSymbol(reference.Location.SourceSpan.Start);
94+
95+
for (var current = enclosingSymbol; current != null; current = current.ContainingSymbol)
96+
{
97+
if (current.Kind == SymbolKind.Field)
98+
{
99+
return current;
100+
}
101+
102+
if (current.Kind == SymbolKind.Property)
103+
{
104+
return current;
105+
}
106+
107+
if (current.Kind == SymbolKind.Method)
108+
{
109+
var method = (IMethodSymbol)current;
110+
if (method.IsAccessor())
111+
{
112+
return method.AssociatedSymbol;
113+
}
114+
115+
if (method.MethodKind != MethodKind.AnonymousFunction)
116+
{
117+
return method;
118+
}
119+
}
120+
}
121+
// reference to a cref
122+
return null;
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)