public static ResolveResult ResolveLowLevel(string fileName, string fileContent, int caretLine, int caretColumn, CompilationUnit compilationUnit, string expressionString, Expression expression, ExpressionContext context)
		{
			if (fileName == null) {
				throw new ArgumentNullException("fileName");
			}
			if (fileContent == null) {
				throw new ArgumentNullException("fileName");
			}
			if (expression == null) {
				throw new ArgumentNullException("expression");
			}
			
			IProject p = ProjectFileDictionaryService.GetProjectForFile(fileName);
			if (p == null) {
				LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. Project is null for file '"+fileName+"'");
				return null;
			}
			
			IProjectContent pc = ResourceResolverService.GetProjectContent(p);
			if (pc == null) {
				LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. ProjectContent is null for project '"+p.ToString()+"'");
				return null;
			}
			
			NRefactoryResolver resolver = ResourceResolverService.CreateResolver(fileName) as NRefactoryResolver;
			if (resolver == null) {
				resolver = new NRefactoryResolver(LanguageProperties.CSharp);
			}
			
			if (compilationUnit == null) {
				compilationUnit = GetFullAst(resolver.Language, fileName, fileContent);
			}
			if (compilationUnit == null) {
				LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed due to the compilation unit being unavailable.");
				return null;
			}
			
			if (!resolver.Initialize(ParserService.GetParseInformation(fileName), caretLine, caretColumn)) {
				LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. NRefactoryResolver.Initialize returned false.");
				return null;
			}
			
			if (resolver.CallingClass != null) {
				ResolveResult rr;
				if (expressionString == null) {
					// HACK: Re-generate the code for the expression from the expression object by using the code generator.
					// This is necessary when invoking from inside an AST visitor where the
					// code belonging to this expression is unavailable.
					expressionString = resolver.LanguageProperties.CodeGenerator.GenerateCode(expression, String.Empty);
				}
				if ((rr = CtrlSpaceResolveHelper.GetResultFromDeclarationLine(resolver.CallingClass, resolver.CallingMember as IMethodOrProperty, caretLine, caretColumn, new ExpressionResult(expressionString))) != null) {
					return rr;
				}
			}
			
			if (resolver.CallingMember != null) {
				
				// Cache member->node mappings to improve performance
				// (if cache is enabled)
				INode memberNode;
				if (!CacheEnabled || !cachedMemberMappings.TryGetValue(resolver.CallingMember, out memberNode)) {
					MemberFindAstVisitor visitor = new MemberFindAstVisitor(resolver.CallingMember);
					compilationUnit.AcceptVisitor(visitor, null);
					memberNode = visitor.MemberNode;
					if (CacheEnabled && memberNode != null) {
						cachedMemberMappings.Add(resolver.CallingMember, memberNode);
					}
				}
				
				if (memberNode == null) {
					LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: Could not find member in AST: "+resolver.CallingMember.ToString());
				} else {
					resolver.RunLookupTableVisitor(memberNode);
				}
				
			}
			
			return resolver.ResolveInternal(expression, context);
		}
Exemple #2
0
        public static ResolveResult ResolveLowLevel(string fileName, string fileContent, int caretLine, int caretColumn, CompilationUnit compilationUnit, string expressionString, Expression expression, ExpressionContext context)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (fileContent == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            IProject p = ProjectFileDictionaryService.GetProjectForFile(fileName);

            if (p == null)
            {
                LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. Project is null for file '" + fileName + "'");
                return(null);
            }

            IProjectContent pc = ResourceResolverService.GetProjectContent(p);

            if (pc == null)
            {
                LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. ProjectContent is null for project '" + p.ToString() + "'");
                return(null);
            }

            NRefactoryResolver resolver = ResourceResolverService.CreateResolver(fileName) as NRefactoryResolver;

            if (resolver == null)
            {
                resolver = new NRefactoryResolver(LanguageProperties.CSharp);
            }

            if (compilationUnit == null)
            {
                compilationUnit = GetFullAst(resolver.Language, fileName, fileContent);
            }
            if (compilationUnit == null)
            {
                LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed due to the compilation unit being unavailable.");
                return(null);
            }

            if (!resolver.Initialize(ParserService.GetParseInformation(fileName), caretLine, caretColumn))
            {
                LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. NRefactoryResolver.Initialize returned false.");
                return(null);
            }

            if (resolver.CallingClass != null)
            {
                ResolveResult rr;
                if (expressionString == null)
                {
                    // HACK: Re-generate the code for the expression from the expression object by using the code generator.
                    // This is necessary when invoking from inside an AST visitor where the
                    // code belonging to this expression is unavailable.
                    expressionString = resolver.LanguageProperties.CodeGenerator.GenerateCode(expression, String.Empty);
                }
                if ((rr = CtrlSpaceResolveHelper.GetResultFromDeclarationLine(resolver.CallingClass, resolver.CallingMember as IMethodOrProperty, caretLine, caretColumn, new ExpressionResult(expressionString))) != null)
                {
                    return(rr);
                }
            }

            if (resolver.CallingMember != null)
            {
                // Cache member->node mappings to improve performance
                // (if cache is enabled)
                INode memberNode;
                if (!CacheEnabled || !cachedMemberMappings.TryGetValue(resolver.CallingMember, out memberNode))
                {
                    MemberFindAstVisitor visitor = new MemberFindAstVisitor(resolver.CallingMember);
                    compilationUnit.AcceptVisitor(visitor, null);
                    memberNode = visitor.MemberNode;
                    if (CacheEnabled && memberNode != null)
                    {
                        cachedMemberMappings.Add(resolver.CallingMember, memberNode);
                    }
                }

                if (memberNode == null)
                {
                    LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: Could not find member in AST: " + resolver.CallingMember.ToString());
                }
                else
                {
                    resolver.RunLookupTableVisitor(memberNode);
                }
            }

            return(resolver.ResolveInternal(expression, context));
        }