public void CompilationUnitUsingScopeHasParentUsingScopeWithNamespaceNameOfEmptyString()
        {
            IUsingScope parentUsingScope = compilationUnit.UsingScope.Parent;
            string      namespaceName    = parentUsingScope.NamespaceName;

            Assert.AreEqual(String.Empty, namespaceName);
        }
Exemplo n.º 2
0
 public DefaultClass(ICompilationUnit compilationUnit, IClass declaringType) : base(declaringType)
 {
     if (compilationUnit == null)
     {
         throw new ArgumentNullException("compilationUnit");
     }
     this.compilationUnit = compilationUnit;
     this.UsingScope      = compilationUnit.UsingScope;
 }
Exemplo n.º 3
0
 public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType)
 {
     if (compilationUnit == null)
     {
         throw new ArgumentNullException("compilationUnit");
     }
     this.compilationUnit = compilationUnit;
     this.region          = region;
     this.classType       = classType;
     Modifiers            = modifiers;
     this.UsingScope      = compilationUnit.UsingScope;
 }
Exemplo n.º 4
0
 public DefaultClass(ICompilationUnit compilationUnit, string fullyQualifiedName) : base(null)
 {
     if (compilationUnit == null)
     {
         throw new ArgumentNullException("compilationUnit");
     }
     if (fullyQualifiedName == null)
     {
         throw new ArgumentNullException("fullyQualifiedName");
     }
     this.compilationUnit    = compilationUnit;
     this.FullyQualifiedName = fullyQualifiedName;
     this.UsingScope         = compilationUnit.UsingScope;
 }
Exemplo n.º 5
0
        public SearchTypeRequest(string name, int typeParameterCount, IClass currentType, ICompilationUnit currentCompilationUnit, int caretLine, int caretColumn)
        {
            if (currentCompilationUnit == null)
            {
                throw new ArgumentNullException("currentCompilationUnit");
            }
            this.Name = name;
            this.TypeParameterCount     = typeParameterCount;
            this.CurrentCompilationUnit = currentCompilationUnit;
            this.CurrentType            = currentType != null?currentType.GetCompoundClass() : null;

            this.CaretLine         = caretLine;
            this.CaretColumn       = caretColumn;
            this.CurrentUsingScope = (currentType != null) ? currentType.UsingScope : currentCompilationUnit.UsingScope;
        }
Exemplo n.º 6
0
 static bool CheckImports(IUsingScope scope)
 {
     foreach (IUsing u in scope.Usings)
     {
         if (CheckImports(u))
         {
             return(true);
         }
     }
     foreach (IUsingScope childscope in scope.ChildScopes)
     {
         if (CheckImports(childscope))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Adds contents of all namespaces that this <paramref name="callingClass" /> imports to the <paramref name="result" /> list.
        /// Also adds contents of <paramref name="callingClass" />.
        /// </summary>
        public static void AddImportedNamespaceContents(List <ICompletionEntry> result, ICompilationUnit cu, IClass callingClass)
        {
            IProjectContent projectContent = cu.ProjectContent;

            projectContent.AddNamespaceContents(result, "", projectContent.Language, true);
            IUsingScope scope = (callingClass != null) ? callingClass.UsingScope : cu.UsingScope;

            while (scope != null)
            {
                foreach (IUsing u in scope.Usings)
                {
                    AddUsing(result, u, projectContent);
                }
                scope = scope.Parent;
            }
            AddUsing(result, projectContent.DefaultImports, projectContent);
            AddContentsFromCallingClass(result, projectContent, callingClass);
        }
		public SearchTypeRequest(string name, int typeParameterCount, IClass currentType, ICompilationUnit currentCompilationUnit, int caretLine, int caretColumn)
		{
			if (currentCompilationUnit == null)
				throw new ArgumentNullException("currentCompilationUnit");
			this.Name = name;
			this.TypeParameterCount = typeParameterCount;
			this.CurrentCompilationUnit = currentCompilationUnit;
			this.CurrentType = currentType != null ? currentType.GetCompoundClass() : null;
			this.CaretLine = caretLine;
			this.CaretColumn = caretColumn;
			this.CurrentUsingScope = (currentType != null) ? currentType.UsingScope : currentCompilationUnit.UsingScope;
		}
Exemplo n.º 9
0
        public SearchTypeResult SearchType(SearchTypeRequest request)
        {
            string name = request.Name;

            if (string.IsNullOrEmpty(name))
            {
                return(SearchTypeResult.Empty);
            }

            // 'result' holds the fall-back result if no result with the right type parameter count is found.
            SearchTypeResult result = SearchTypeResult.Empty;

            if (name.IndexOf('.') < 0)
            {
                for (IClass outerClass = request.CurrentType; outerClass != null; outerClass = outerClass.DeclaringType)
                {
                    // Try inner classes (in full inheritance tree)
                    // Don't use loop with cur = cur.BaseType because of inheritance cycles
                    foreach (IClass baseClass in outerClass.ClassInheritanceTree)
                    {
                        if (baseClass.ClassType == ClassType.Class || baseClass.ClassType == ClassType.Struct || baseClass.ClassType == ClassType.Module)
                        {
                            foreach (IClass innerClass in baseClass.InnerClasses)
                            {
                                if (language.NameComparer.Equals(innerClass.Name, name))
                                {
                                    result = new SearchTypeResult(innerClass);
                                    if (MatchesRequest(ref request, ref result))
                                    {
                                        return(result);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (IUsingScope usingScope = request.CurrentUsingScope; usingScope != null; usingScope = usingScope.Parent)
            {
                string fullname;
                if (string.IsNullOrEmpty(usingScope.NamespaceName))
                {
                    // Try if name is already the full type name
                    fullname = name;
                }
                else
                {
                    fullname = usingScope.NamespaceName + "." + name;
                }
                IClass c = GetClass(fullname, request.TypeParameterCount);
                if (c != null)
                {
                    result = new SearchTypeResult(c);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }
                if (NamespaceExists(fullname))
                {
                    result = new SearchTypeResult(fullname, null);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }

                foreach (IUsing u in usingScope.Usings)
                {
                    foreach (IReturnType r in u.SearchType(name, request.TypeParameterCount))
                    {
                        result = new SearchTypeResult(r, u);
                        if (MatchesRequest(ref request, ref result))
                        {
                            return(result);
                        }
                    }
                    string nsResult = u.SearchNamespace(name);
                    if (nsResult != null)
                    {
                        result = new SearchTypeResult(nsResult, null);
                        if (MatchesRequest(ref request, ref result))
                        {
                            return(result);
                        }
                    }
                }
            }

            if (defaultImports != null)
            {
                foreach (IReturnType r in defaultImports.SearchType(name, request.TypeParameterCount))
                {
                    result = new SearchTypeResult(r, defaultImports);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }
                string nsResult = defaultImports.SearchNamespace(name);
                if (nsResult != null)
                {
                    result = new SearchTypeResult(nsResult, null);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 10
0
		public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType)
		{
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			this.compilationUnit = compilationUnit;
			this.region = region;
			this.classType = classType;
			Modifiers = modifiers;
			this.UsingScope = compilationUnit.UsingScope;
		}
Exemplo n.º 11
0
		public DefaultClass(ICompilationUnit compilationUnit, IClass declaringType) : base(declaringType)
		{
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			this.compilationUnit = compilationUnit;
			this.UsingScope = compilationUnit.UsingScope;
		}
Exemplo n.º 12
0
		public DefaultClass(ICompilationUnit compilationUnit, string fullyQualifiedName) : base(null)
		{
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			if (fullyQualifiedName == null)
				throw new ArgumentNullException("fullyQualifiedName");
			this.compilationUnit = compilationUnit;
			this.FullyQualifiedName = fullyQualifiedName;
			this.UsingScope = compilationUnit.UsingScope;
		}
		static bool CheckImports(IUsingScope scope)
		{
			foreach (IUsing u in scope.Usings) {
				if (CheckImports(u)) {
					return true;
				}
			}
			foreach (IUsingScope childscope in scope.ChildScopes) {
				if (CheckImports(childscope))
					return true;
			}
			return false;
		}
Exemplo n.º 14
0
 public UsingScopeHelper()
 {
     UsingScope = MockRepository.GenerateStub <IUsingScope>();
     UsingScope.Stub(scope => scope.Usings).Return(Usings);
 }
Exemplo n.º 15
0
		public UsingScopeHelper()
		{
			UsingScope = MockRepository.GenerateStub<IUsingScope>();
			UsingScope.Stub(scope => scope.Usings).Return(Usings);
		}