Example #1
0
		public void MemberNameIsEqualReturnsFalseWhenTypeNameIsDifferent()
		{
			MemberName lhs = new MemberName("type1", "method");
			MemberName rhs = new MemberName("type2", "method");
			
			Assert.IsFalse(lhs.Equals(rhs));
		}
Example #2
0
		public void MemberNameIsEqualReturnsTrueWhenNameAndTypeAreSame()
		{
			MemberName lhs = new MemberName("type", "member");
			MemberName rhs = new MemberName("type", "member");
			
			Assert.IsTrue(lhs.Equals(rhs));
		}
		IProperty FindProperty(PythonResolverContext resolverContext, MemberName memberName)
		{
			IProperty parentProperty = FindProperty(resolverContext, memberName.Type);
			if (parentProperty != null) {
				return FindPropertyInProperty(parentProperty, memberName.Name);
			}
			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;
		}
		IClass FindClassFromLocalVariableResolver(string localVariableName)
		{
			 MemberName memberName = new MemberName(localVariableName);
			 if (!memberName.HasName) {
			 	string typeName = localVariableResolver.Resolve(localVariableName, resolverContext.FileContent);
		 		return FindClassFromClassResolver(typeName);
			 }
			 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;
		}
		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;
		}
		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;
		}
		IMember FindMember(string expression)
		{
			MemberName memberName = new MemberName(expression);
			if (memberName.HasName) {
				IClass c = FindClass(memberName.Type);
				if (c != null) {
					return FindMemberInClass(c, memberName.Name);
				} else {
					return FindMemberInParent(memberName);
				}
			}
			return null;
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult)
		{
			MemberName memberName = new MemberName(expressionResult.Expression);
			MethodGroupResolveResult result = ResolveMethodFromImportedNames(resolverContext, memberName);
			if (result != null) {
				return result;
			}
			result = ResolveIfMethodIsImported(resolverContext, memberName);
			if (result != null) {
				return result;
			}
			return ResolveMethodFromModulesThatImportEverything(resolverContext, memberName);
		}
		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;
		}
		IMember FindMemberInParent(MemberName memberName)
		{
			IMember parentMember = FindMember(memberName.Type);
			if (parentMember != null) {
				return FindMemberInParent(parentMember, memberName.Name);
			}
			return null;
		}
Example #13
0
		public void CreateMemberNameWithExpressionWithoutDotCharReturnsMemberNameOfEmptyStringAndExpressionAsTypeName()
		{
			MemberName methodName = new MemberName("test");
			MemberName expectedMemberName = new MemberName("test", String.Empty);
			Assert.AreEqual(expectedMemberName, methodName);
		}
		public string FindStartOfDottedModuleNameInImports(string fullDottedModuleName)
		{
			MemberName memberName = new MemberName(fullDottedModuleName);
			while (memberName.HasName) {
				string partialNamespace = memberName.Type;
				if (HasImport(partialNamespace)) {
					return partialNamespace;
				}
				memberName = new MemberName(partialNamespace);
			}
			return null;
		}
Example #15
0
		public void MemberNameTypePropertyReturnsType()
		{
			MemberName methodName = new MemberName("type", "method");
			Assert.AreEqual("type", methodName.Type);
		}
		/// <summary>
		/// Removes the last part of the expression.
		/// </summary>
		/// <example>
		/// "array[i]" => "array"
		/// "myObject.Field" => "myObject"
		/// "myObject.Method(arg1, arg2)" => "myObject.Method"
		/// </example>
		public string RemoveLastPart(string expression)
		{
			MemberName memberName = new MemberName(expression);
			return memberName.Type;
		}
Example #17
0
		public void HasNameReturnsFalseForMemberNameWithEmptyStringForMemberName()
		{
			MemberName memberName = new MemberName("System", String.Empty);
			Assert.IsFalse(memberName.HasName);
		}
Example #18
0
		public void CreateMemberNameWithSystemDotConsoleDotWriteLineReturnsMemberNameWriteLineAndTypeNameSystemDotConsole()
		{
			MemberName methodName = new MemberName("System.Console.WriteLine");
			MemberName expectedMemberName = new MemberName("System.Console", "WriteLine");
			
			Assert.AreEqual(expectedMemberName, methodName);
		}
Example #19
0
		public void CreateMemberNameWithEmptyStringReturnsMemberNameWithEmptyTypeAndMemberName()
		{
			MemberName methodName = new MemberName(String.Empty);
			MemberName expectedMemberName = new MemberName(String.Empty, String.Empty);
			Assert.AreEqual(expectedMemberName, methodName);
		}
Example #20
0
		public void MemberNameToStringShowsTypeNameAndMemberName()
		{
			MemberName methodName = new MemberName("type", "method");
			string expectedText = "Type: type, Member: method";
			Assert.AreEqual(expectedText, methodName.ToString());
		}
Example #21
0
		public void HasNameReturnsTrueForMemberNameWithNonEmptyStringForMemberName()
		{
			MemberName memberName = new MemberName("System", "Console");
			Assert.IsTrue(memberName.HasName);
		}
Example #22
0
        /// <summary>
        /// Removes the last part of the expression.
        /// </summary>
        /// <example>
        /// "array[i]" => "array"
        /// "myObject.Field" => "myObject"
        /// "myObject.Method(arg1, arg2)" => "myObject.Method"
        /// </example>
        public string RemoveLastPart(string expression)
        {
            MemberName memberName = new MemberName(expression);

            return(memberName.Type);
        }
Example #23
0
		public void MemberNameIsEqualsReturnsFalseWhenMemberNameIsNull()
		{
			MemberName lhs = new MemberName("type", "Member");
			Assert.IsFalse(lhs.Equals(null));
		}