Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add CSharpAstResolver.GetResolverStateBefore

  • Loading branch information...
commit 7e95cb7446aeaff746c681d9e3ee4750fc1c2865 1 parent 4ccc313
@dgrunwald dgrunwald authored
View
27 ICSharpCode.NRefactory.CSharp/Resolver/CSharpAstResolver.cs
@@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
+using System.Diagnostics;
using System.Threading;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Semantics;
@@ -105,12 +106,32 @@ public ResolveResult Resolve(AstNode node, CancellationToken cancellationToken =
{
if (node == null || node.IsNull)
return ErrorResolveResult.UnknownError;
+ InitResolver(node);
+ lock (resolveVisitor) {
+ ResolveResult rr = resolveVisitor.GetResolveResult(node);
+ Debug.Assert(rr != null);
+ return rr;
+ }
+ }
+
+ void InitResolver(AstNode firstNodeToResolve)
+ {
if (resolveVisitor == null) {
- resolveVisitor = new ResolveVisitor(initialResolverState, parsedFile);
+ resolveVisitor = new ResolveVisitor(initialResolverState, parsedFile, new NodeListResolveVisitorNavigator(firstNodeToResolve));
resolveVisitor.Scan(rootNode);
}
- lock (resolveVisitor)
- return resolveVisitor.GetResolveResult(node);
+ }
+
+ public CSharpResolver GetResolverStateBefore(AstNode node)
+ {
+ if (node == null || node.IsNull)
+ throw new ArgumentNullException("node");
+ InitResolver(node);
+ lock (resolveVisitor) {
+ CSharpResolver resolver = resolveVisitor.GetResolverStateBefore(node);
+ Debug.Assert(resolver != null);
+ return resolver;
+ }
}
/// <summary>
View
11 ICSharpCode.NRefactory.CSharp/Resolver/FindReferences.cs
@@ -806,19 +806,22 @@ internal override bool IsMatch(ResolveResult rr)
/// <param name="variable">The variable for which to look.</param>
/// <param name="parsedFile">The type system representation of the file being searched.</param>
/// <param name="compilationUnit">The compilation unit of the file being searched.</param>
- /// <param name="context">The type resolve context to use for resolving the file.</param>
+ /// <param name="compilation">The compilation.</param>
/// <param name="callback">Callback used to report the references that were found.</param>
+ /// <param name="cancellationToken">Cancellation token that may be used to cancel the operation.</param>
public void FindLocalReferences(IVariable variable, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
- FoundReferenceCallback callback, CancellationToken cancellationToken)
+ ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
{
if (variable == null)
throw new ArgumentNullException("variable");
- FindReferencesInFile(new FindLocalReferencesNavigator(variable), parsedFile, compilationUnit, callback, cancellationToken);
+ var navigator = new FindLocalReferencesNavigator(variable);
+ navigator.compilation = compilation;
+ FindReferencesInFile(navigator, parsedFile, compilationUnit, callback, cancellationToken);
}
class FindLocalReferencesNavigator : SearchScope
{
- IVariable variable;
+ readonly IVariable variable;
public FindLocalReferencesNavigator(IVariable variable)
{
View
2  ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
@@ -381,7 +381,7 @@ public ResolveResult GetResolveResult(AstNode node)
ResetContext(
storedResolver.Clone(),
delegate {
- navigator = new NodeListResolveVisitorNavigator(nodeToResolve);
+ navigator = new NodeListResolveVisitorNavigator(node, nodeToResolve);
if (parent == nodeToResolve) {
Resolve(nodeToResolve);
} else {
View
9 ICSharpCode.NRefactory.Tests/CSharp/ContextAction/TestRefactoringContext.cs
@@ -60,13 +60,10 @@ class TestRefactoringContext : RefactoringContext
public override AstType CreateShortType (IType fullType)
{
- throw new NotImplementedException();
- /*var csResolver = new CSharpResolver (TypeResolveContext, System.Threading.CancellationToken.None);
- csResolver.CurrentMember = file.GetMember (Location);
- csResolver.CurrentTypeDefinition = file.GetInnermostTypeDefinition (Location);
- csResolver.CurrentUsingScope = file.GetUsingScope (Location);
+ AstNode node = Unit.GetNodeAt(Location);
+ CSharpResolver csResolver = resolver.GetResolverStateBefore(node);
var builder = new TypeSystemAstBuilder (csResolver);
- return builder.ConvertType (fullType);*/
+ return builder.ConvertType (fullType);
}
public override void ReplaceReferences (IMember member, MemberDeclaration replaceWidth)
Please sign in to comment.
Something went wrong with that request. Please try again.