string GetLocalMethodCode(PythonResolverContext resolverContext)
        {
            ScriptingLocalMethod localMethod = new ScriptingLocalMethod(resolverContext.FileContent);
            int beginLine = resolverContext.ExpressionRegion.BeginLine;

            return(localMethod.GetCode(beginLine));
        }
		public ResolveResult Resolve(string expression)
		{
			ExpressionResult expressionResult = new ExpressionResult(expression);
			PythonResolverContext context = new PythonResolverContext(ParseInfo, expressionResult, String.Empty);
			ResolveResult = Resolver.Resolve(context);
			return ResolveResult;
		}
        public IClass GetClass(PythonResolverContext resolverContext, string name)
        {
            this.resolverContext = resolverContext;

            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }

            IClass matchedClass = resolverContext.GetClass(name);

            if (matchedClass != null)
            {
                return(matchedClass);
            }

            matchedClass = GetClassFromImportedNames(name);
            if (matchedClass != null)
            {
                return(matchedClass);
            }

            matchedClass = GetClassFromNamespaceThatImportsEverything(name);
            if (matchedClass != null)
            {
                return(matchedClass);
            }

            return(GetClassFromDottedImport(name));
        }
Beispiel #4
0
        ResolveResult CreateResolveResult(PythonResolverContext resolverContext)
        {
            IClass      callingClass = resolverContext.CallingClass;
            IReturnType returnType   = callingClass.DefaultReturnType;

            return(new ResolveResult(callingClass, null, returnType));
        }
		public IClass GetClass(PythonResolverContext resolverContext, string name)
		{
			this.resolverContext = resolverContext;
			
			if (String.IsNullOrEmpty(name)) {
				return null;
			}
			
			IClass matchedClass = resolverContext.GetClass(name);
			if (matchedClass != null) {
				return matchedClass;
			}
			
			matchedClass = GetClassFromImportedNames(name);
			if (matchedClass != null) {
				return matchedClass;
			}
			
			matchedClass = GetClassFromNamespaceThatImportsEverything(name);
			if (matchedClass != null) {
				return matchedClass;
			}
			
			return GetClassFromDottedImport(name);
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			ResolveResult resolveResult = dotNetMethodResolver.Resolve(resolverContext, expressionResult);
			if (resolveResult != null) {
				return resolveResult;
			}
			return standardModuleMethodResolver.Resolve(resolverContext, expressionResult);
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			IClass matchingClass = GetClass(resolverContext, expressionResult.Expression);
			if (matchingClass != null) {
				return CreateTypeResolveResult(matchingClass);
			}
			return null;
		}
		public PythonStandardModuleType GetStandardModuleTypeIfImported(PythonResolverContext resolverContext, string moduleName)
		{
			if (resolverContext.HasImport(moduleName) || PythonBuiltInModuleMemberName.IsBuiltInModule(moduleName)) {
				string actualModuleName = resolverContext.UnaliasImportedModuleName(moduleName);
				return standardPythonModules.GetModuleType(actualModuleName);
			}
			return null;
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			IProperty property = FindProperty(resolverContext, expressionResult.Expression);
			if (property != null) {
				return CreateMemberResolveResult(property);
			}
			return null;
		}
		public void HasImportReturnsTrueForImportedAsName()
		{
			string code = "import sys as something";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			Assert.IsTrue(resolverContext.HasImport("something"));
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			PythonStandardModuleType type = GetStandardModuleTypeIfImported(resolverContext, expressionResult.Expression);
			if (type != null) {
				return new PythonStandardModuleResolveResult(type);
			}
			return null;
		}
		public void HasImportReturnsFalseForFromImport()
		{
			string code = "from import sys";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			Assert.IsFalse(resolverContext.HasImport("sys"));
		}
		public void HasImportReturnsTrueForImportThatDoesExistInCompilationUnitWithSingleUsingWithMultipleNamespaces()
		{
			string code = "import abc, ghi";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			Assert.IsTrue(resolverContext.HasImport("ghi"));
		}
		public void HasImportReturnsTrueForImportThatDoesExistInCompilationUnit()
		{
			string code = "import abc";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			Assert.IsTrue(resolverContext.HasImport("abc"));
		}
		public void HasDottedImportNameReturnsTrueForSystemWithSystemWindowsFormsImported()
		{
			string code = "import System.Windows.Forms";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			Assert.IsTrue(resolverContext.HasDottedImportNameThatStartsWith("System"));
		}
		IProperty FindProperty(PythonResolverContext resolverContext, MemberName memberName)
		{
			IProperty parentProperty = FindProperty(resolverContext, memberName.Type);
			if (parentProperty != null) {
				return FindPropertyInProperty(parentProperty, memberName.Name);
			}
			return null;
		}
		public void Init()
		{
			string python =
				"from sys import exit as myexit";
			
			parseInfo = PythonParserHelper.CreateParseInfo(python);
			resolverContext = new PythonResolverContext(parseInfo);
		}
		void ResolvePropertyExpression(string expression)
		{
			PythonResolverContext context = new PythonResolverContext(parseInfo);
			ExpressionResult expressionResult = new ExpressionResult(expression);
			
			PythonResolver resolver = new PythonResolver();
			result = resolver.Resolve(context, expressionResult);
		}
		public void HasDottedImportNameReturnsFalseForMyNamespaceWithMyNamespaceTestImportedWithoutDtso()
		{
			string code = "import MyNamespaceTest";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			Assert.IsFalse(resolverContext.HasDottedImportNameThatStartsWith("MyNamespace"));
		}
		/// <summary>
		/// Tries to find the type that matches the local variable name.
		/// </summary>
		LocalResolveResult GetLocalVariable(PythonResolverContext resolverContext)
		{
			string code = GetLocalMethodCode(resolverContext);
			string typeName = Resolve(resolverContext.Expression, code);
			if (typeName != null) {
				return CreateLocalResolveResult(typeName, resolverContext);
			}
			return null;
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			if (resolverContext.HasCallingClass) {
				if (IsSelfExpression(expressionResult)) {
					return CreateResolveResult(resolverContext);
				}
			}
			return null;
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			MemberName memberName = new MemberName(expressionResult.Expression);
			IClass matchingClass = classResolver.GetClass(resolverContext, memberName.Type);
			if (matchingClass != null) {
				return new PythonMethodGroupResolveResult(matchingClass, memberName.Name);
			}
			return null;
		}
 public PythonStandardModuleType GetStandardModuleTypeIfImported(PythonResolverContext resolverContext, string moduleName)
 {
     if (resolverContext.HasImport(moduleName) || PythonBuiltInModuleMemberName.IsBuiltInModule(moduleName))
     {
         string actualModuleName = resolverContext.UnaliasImportedModuleName(moduleName);
         return(standardPythonModules.GetModuleType(actualModuleName));
     }
     return(null);
 }
		public void Init()
		{
			string python =
				"import math as m\r\n" +
				"import sys as s";
			
			parseInfo = PythonParserHelper.CreateParseInfo(python);
			resolverContext = new PythonResolverContext(parseInfo);
		}
        public ResolveResult Resolve(PythonResolverContext resolverContext)
        {
            PythonStandardModuleType type = GetStandardModuleTypeIfImported(resolverContext);

            if (type != null)
            {
                return(new PythonStandardModuleResolveResult(type));
            }
            return(null);
        }
		public void GetModulesThatImportEverythingReturnsEmptyCollectionIfNotImportAll()
		{
			string code = "from math import tan";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			
			string[] expectedModules = new string[0];
			Assert.AreEqual(expectedModules, resolverContext.GetModulesThatImportEverything());
		}
Beispiel #27
0
        public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
        {
            ResolveResult resolveResult = dotNetMethodResolver.Resolve(resolverContext, expressionResult);

            if (resolveResult != null)
            {
                return(resolveResult);
            }
            return(standardModuleMethodResolver.Resolve(resolverContext, expressionResult));
        }
		public void GetModulesThatImportEverythingReturnsSysForFromSysImportAllStatement()
		{
			string code = "from sys import *";
			ParseInformation parseInfo = PythonParserHelper.CreateParseInfo(code);
			
			PythonResolverContext resolverContext = new PythonResolverContext(parseInfo);
			
			string[] expectedModules = new string[] { "sys" };
			Assert.AreEqual(expectedModules, resolverContext.GetModulesThatImportEverything());
		}
        public ResolveResult Resolve(PythonResolverContext resolverContext)
        {
            IClass matchingClass = GetClass(resolverContext);

            if (matchingClass != null)
            {
                return(CreateTypeResolveResult(matchingClass));
            }
            return(null);
        }
Beispiel #30
0
		public ResolveResult Resolve(PythonResolverContext resolverContext)
		{
			foreach (IPythonResolver resolver in resolvers) {
				ResolveResult resolveResult = resolver.Resolve(resolverContext);
				if (resolveResult != null) {
					return resolveResult;
				}
			}
			return null;
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			this.resolverContext = resolverContext;
			this.expressionResult = expressionResult;
			
			if (resolverContext.HasImport(expressionResult.Expression)) {
				return ResolveFullNamespace();
			}
			return ResolvePartialNamespaceMatch();
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext)
		{
			string methodName = GetMethodName(resolverContext.Expression);
			if (methodName != null) {
				PythonResolverContext newResolverContext = resolverContext.Clone(methodName);
				IMember member = memberResolver.FindMember(newResolverContext);
				return CreateResolveResult(member);
			}
			return null;
		}
Beispiel #33
0
		List<ICompletionEntry> CtrlSpace(PythonResolverContext resolverContext, ExpressionContext expressionContext)
		{
			if (resolverContext.HasProjectContent) {
				if (expressionContext == ExpressionContext.Namespace) {
					return GetImportCompletionItems(resolverContext.ProjectContent);
				}
				return resolverContext.GetImportedTypes();
			}
			return new List<ICompletionEntry>();
		}
        IClass FindClassFromSelfResolver()
        {
            PythonResolverContext newContext = resolverContext.Clone("self");
            ResolveResult         result     = selfResolver.Resolve(newContext);

            if (result != null)
            {
                return(result.ResolvedType.GetUnderlyingClass());
            }
            return(null);
        }
        LocalResolveResult CreateLocalResolveResult(string typeName, PythonResolverContext resolverContext)
        {
            IClass resolvedClass = classResolver.GetClass(resolverContext, typeName);

            if (resolvedClass != null)
            {
                string identifier = resolverContext.Expression;
                return(CreateLocalResolveResult(identifier, resolvedClass));
            }
            return(null);
        }
        /// <summary>
        /// Tries to find the type that matches the local variable name.
        /// </summary>
        LocalResolveResult GetLocalVariable(PythonResolverContext resolverContext)
        {
            string code     = GetLocalMethodCode(resolverContext);
            string typeName = Resolve(resolverContext.Expression, code);

            if (typeName != null)
            {
                return(CreateLocalResolveResult(typeName, resolverContext));
            }
            return(null);
        }
		IProperty FindProperty(PythonResolverContext resolverContext, string expression)
		{
			MemberName memberName = new MemberName(expression);
			IClass matchingClass = FindClass(resolverContext, memberName.Type);
			if (matchingClass != null) {
				return FindPropertyInClass(matchingClass, memberName.Name);
			} else if (memberName.HasName) {
				return FindProperty(resolverContext, memberName);
			}
			return null;
		}
Beispiel #38
0
        public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
        {
            this.resolverContext  = resolverContext;
            this.expressionResult = expressionResult;

            if (resolverContext.HasImport(expressionResult.Expression))
            {
                return(ResolveFullNamespace());
            }
            return(ResolvePartialNamespaceMatch());
        }
        public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
        {
            MemberName memberName    = new MemberName(expressionResult.Expression);
            IClass     matchingClass = classResolver.GetClass(resolverContext, memberName.Type);

            if (matchingClass != null)
            {
                return(new PythonMethodGroupResolveResult(matchingClass, memberName.Name));
            }
            return(null);
        }
		public ResolveResult Resolve(PythonResolverContext resolverContext)
		{
			if (IsNamespace(resolverContext.ExpressionResult)) {
				PythonImportExpression importExpression = new PythonImportExpression(resolverContext.Expression);
				PythonImportExpressionContext context = resolverContext.ExpressionContext as PythonImportExpressionContext;
				context.HasFromAndImport = importExpression.HasFromAndImport;
				
				return new PythonImportModuleResolveResult(importExpression);
			}
			return null;
		}
Beispiel #41
0
 public ResolveResult Resolve(PythonResolverContext resolverContext)
 {
     foreach (IPythonResolver resolver in resolvers)
     {
         ResolveResult resolveResult = resolver.Resolve(resolverContext);
         if (resolveResult != null)
         {
             return(resolveResult);
         }
     }
     return(null);
 }
Beispiel #42
0
 List <ICompletionEntry> CtrlSpace(PythonResolverContext resolverContext, ExpressionContext expressionContext)
 {
     if (resolverContext.HasProjectContent)
     {
         if (expressionContext == ExpressionContext.Namespace)
         {
             return(GetImportCompletionItems(resolverContext.ProjectContent));
         }
         return(resolverContext.GetImportedTypes());
     }
     return(new List <ICompletionEntry>());
 }
		MethodGroupResolveResult ResolveIfMethodIsImported(PythonResolverContext resolverContext, MemberName memberName)
		{
			if (!memberName.HasName) {
				memberName = new PythonBuiltInModuleMemberName(memberName.Type);
			}
			
			PythonStandardModuleType type = standardModuleResolver.GetStandardModuleTypeIfImported(resolverContext, memberName.Type);
			if (type != null) {
				return CreateResolveResult(type, memberName.Name);
			}
			return null;
		}
Beispiel #44
0
        public ResolveResult Resolve(PythonResolverContext resolverContext)
        {
            string methodName = GetMethodName(resolverContext.Expression);

            if (methodName != null)
            {
                PythonResolverContext newResolverContext = resolverContext.Clone(methodName);
                IMember member = memberResolver.FindMember(newResolverContext);
                return(CreateResolveResult(member));
            }
            return(null);
        }
		public void Init()
		{
			MockProjectContent projectContent = new MockProjectContent();
			MockProjectContent winFormsReferenceProjectContent = new MockProjectContent();
			List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>();
			winFormsReferenceProjectContent.AddExistingNamespaceContents("System.Windows.Forms", namespaceItems);
			projectContent.ReferencedContents.Add(winFormsReferenceProjectContent);
			DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent);
			parseInfo = new ParseInformation(unit);
			
			resolverContext = new PythonResolverContext(parseInfo);
		}
Beispiel #46
0
        public ResolveResult Resolve(PythonResolverContext resolverContext)
        {
            if (IsNamespace(resolverContext.ExpressionResult))
            {
                PythonImportExpression        importExpression = new PythonImportExpression(resolverContext.Expression);
                PythonImportExpressionContext context          = resolverContext.ExpressionContext as PythonImportExpressionContext;
                context.HasFromAndImport = importExpression.HasFromAndImport;

                return(new PythonImportModuleResolveResult(importExpression));
            }
            return(null);
        }
Beispiel #47
0
        public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent)
        {
            if (String.IsNullOrEmpty(fileContent))
            {
                return(null);
            }

            resolverContext = new PythonResolverContext(parseInfo, expressionResult, fileContent);
            if (!resolverContext.HasProjectContent)
            {
                return(null);
            }

            return(Resolve(resolverContext));
        }
Beispiel #48
0
        public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent)
        {
            if (String.IsNullOrEmpty(fileContent))
            {
                return(null);
            }

            resolverContext = new PythonResolverContext(parseInfo);
            if (!resolverContext.GetCallingMember(expressionResult.Region))
            {
                return(null);
            }

            return(Resolve(resolverContext, expressionResult));
        }
Beispiel #49
0
        MethodGroupResolveResult ResolveIfMethodIsImported(PythonResolverContext resolverContext, MemberName memberName)
        {
            if (!memberName.HasName)
            {
                memberName = new PythonBuiltInModuleMemberName(memberName.Type);
            }

            PythonStandardModuleType type = standardModuleResolver.GetStandardModuleTypeIfImported(resolverContext, memberName.Type);

            if (type != null)
            {
                return(CreateResolveResult(type, memberName.Name));
            }
            return(null);
        }
Beispiel #50
0
 public ResolveResult Resolve(PythonResolverContext resolverContext)
 {
     if (resolverContext.HasCallingClass)
     {
         if (IsSelfExpression(resolverContext))
         {
             return(CreateResolveResult(resolverContext));
         }
         else if (IsSelfExpressionAtStart(resolverContext))
         {
             MemberName memberName = resolverContext.CreateExpressionMemberName();
             return(new PythonMethodGroupResolveResult(resolverContext.CallingClass, memberName.Name));
         }
     }
     return(null);
 }
Beispiel #51
0
        public ResolveResult Resolve(PythonResolverContext resolverContext)
        {
            MemberName memberName           = resolverContext.CreateExpressionMemberName();
            MethodGroupResolveResult result = ResolveMethodFromImportedNames(resolverContext, memberName);

            if (result != null)
            {
                return(result);
            }
            result = ResolveIfMethodIsImported(resolverContext, memberName);
            if (result != null)
            {
                return(result);
            }
            return(ResolveMethodFromModulesThatImportEverything(resolverContext, memberName));
        }
Beispiel #52
0
 MethodGroupResolveResult ResolveMethodFromModulesThatImportEverything(PythonResolverContext resolverContext, MemberName memberName)
 {
     foreach (string module in resolverContext.GetModulesThatImportEverything())
     {
         PythonStandardModuleType type = standardModuleResolver.GetStandardModuleType(module);
         if (type != null)
         {
             MethodGroupResolveResult resolveResult = CreateResolveResult(type, memberName.Type);
             if (resolveResult != null)
             {
                 return(resolveResult);
             }
         }
     }
     return(null);
 }
Beispiel #53
0
 /// <summary>
 /// Called when Ctrl+Space is entered by the user.
 /// </summary>
 public ArrayList CtrlSpace(int caretLine, int caretColumn, ParseInformation parseInfo, string fileContent, ExpressionContext context)
 {
     resolverContext = new PythonResolverContext(parseInfo);
     if (resolverContext.HasProjectContent)
     {
         if (context == ExpressionContext.Namespace)
         {
             PythonImportCompletion importCompletion = new PythonImportCompletion(resolverContext.ProjectContent);
             return(importCompletion.GetCompletionItems());
         }
         else
         {
             return(resolverContext.GetImportedTypes());
         }
     }
     return(new ArrayList());
 }
Beispiel #54
0
 MethodGroupResolveResult ResolveMethodFromImportedNames(PythonResolverContext resolverContext, MemberName memberName)
 {
     if (!memberName.HasName)
     {
         string name       = memberName.Type;
         string moduleName = resolverContext.GetModuleForImportedName(name);
         if (moduleName != null)
         {
             PythonStandardModuleType type = standardModuleResolver.GetStandardModuleType(moduleName);
             if (type != null)
             {
                 name = resolverContext.UnaliasImportedName(name);
                 return(PythonStandardModuleMethodGroupResolveResult.Create(type, name));
             }
         }
     }
     return(null);
 }
Beispiel #55
0
        public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
        {
            foreach (IPythonResolver resolver in resolvers)
            {
                ResolveResult resolveResult = resolver.Resolve(resolverContext, expressionResult);
                if (resolveResult != null)
                {
                    return(resolveResult);
                }
            }

//			// Search for a local variable.
//			LocalResolveResult localResolveResult = GetLocalVariable(expressionResult.Expression, parseInfo.BestCompilationUnit.FileName, fileContent);
//			if (localResolveResult != null) {
//				return localResolveResult;
//			}

            return(null);
        }
 public ResolveResult Resolve(PythonResolverContext resolverContext)
 {
     return(GetLocalVariable(resolverContext));
 }
Beispiel #57
0
 public ResolveResult Resolve(PythonResolverContext resolverContext)
 {
     return(Resolve(resolverContext, resolverContext.ExpressionResult));
 }
Beispiel #58
0
 bool IsSelfExpressionAtStart(PythonResolverContext resolverContext)
 {
     return(resolverContext.Expression.StartsWith("self."));
 }
        public IClass GetClass(PythonResolverContext resolverContext)
        {
            string name = resolverContext.Expression;

            return(GetClass(resolverContext, name));
        }
        PythonStandardModuleType GetStandardModuleTypeIfImported(PythonResolverContext resolverContext)
        {
            string moduleName = resolverContext.Expression;

            return(GetStandardModuleTypeIfImported(resolverContext, moduleName));
        }