Esempio n. 1
0
 public void AddClassToNamespaceList(IClass addClass)
 {
     lock (namespaces) {
         AddClassToNamespaceListInternal(addClass);
     }
     DomCache.Clear();
 }
Esempio n. 2
0
        public void UpdateCompilationUnit(ICompilationUnit oldUnit, ICompilationUnit parserOutput, string fileName)
        {
            // DC: Since we need to update the compilation units with more data, the Freeze below makes the classes to be ReadOnly (which prevent adding new ones)
            // so for now I'm commenting out this line (and need to figure out what are its side effects)

            // maybe I need this after all

            parserOutput.Freeze();
            lock (namespaces) {
                if (oldUnit != null)
                {
                    foreach (IClass c in oldUnit.Classes)
                    {
                        RemoveClass(c);
                    }
                    foreach (IAttribute attr in oldUnit.Attributes)
                    {
                        assemblyAttributes.Remove(attr);
                    }
                }

                foreach (IClass c in parserOutput.Classes)
                {
                    AddClassToNamespaceListInternal(c);
                }
                assemblyAttributes.AddRange(parserOutput.Attributes);
            }
            DomCache.Clear();
        }
Esempio n. 3
0
 protected virtual void OnReferencedContentsChanged(EventArgs e)
 {
     systemTypes = null;             // re-create system types
     DomCache.Clear();
     if (ReferencedContentsChanged != null)
     {
         ReferencedContentsChanged(this, e);
     }
 }
Esempio n. 4
0
 public void RemoveCompilationUnit(ICompilationUnit unit)
 {
     lock (namespaces) {
         foreach (IClass c in unit.Classes)
         {
             RemoveClass(c);
         }
         foreach (IAttribute attr in unit.Attributes)
         {
             assemblyAttributes.Remove(attr);
         }
     }
     DomCache.Clear();
 }
Esempio n. 5
0
        public void UpdateCompilationUnit(ICompilationUnit oldUnit, ICompilationUnit parserOutput, string fileName)
        {
            parserOutput.Freeze();
            lock (namespaces) {
                if (oldUnit != null)
                {
                    foreach (IClass c in oldUnit.Classes)
                    {
                        RemoveClass(c);
                    }
                    foreach (IAttribute attr in oldUnit.Attributes)
                    {
                        assemblyAttributes.Remove(attr);
                    }
                }

                foreach (IClass c in parserOutput.Classes)
                {
                    AddClassToNamespaceListInternal(c);
                }
                assemblyAttributes.AddRange(parserOutput.Attributes);
            }
            DomCache.Clear();
        }
        /// <summary>
        /// Gets all types the specified type inherits from (all classes and interfaces).
        /// Unlike the class inheritance tree, this method takes care of type arguments and calculates the type
        /// arguments that are passed to base classes.
        /// </summary>
        public static IEnumerable <IReturnType> GetTypeInheritanceTree(IReturnType typeToListInheritanceTreeFor)
        {
            if (typeToListInheritanceTreeFor == null)
            {
                throw new ArgumentNullException("typeToListInheritanceTreeFor");
            }

            lock (getTypeInheritanceTreeCache) {
                IEnumerable <IReturnType> result;
                if (getTypeInheritanceTreeCache.TryGetValue(typeToListInheritanceTreeFor, out result))
                {
                    return(result);
                }
            }

            IClass classToListInheritanceTreeFor = typeToListInheritanceTreeFor.GetUnderlyingClass();

            if (classToListInheritanceTreeFor == null)
            {
                return new IReturnType[] { typeToListInheritanceTreeFor }
            }
            ;

            if (typeToListInheritanceTreeFor.IsArrayReturnType)
            {
                IReturnType elementType = typeToListInheritanceTreeFor.CastToArrayReturnType().ArrayElementType;

                List <IReturnType> resultList = new List <IReturnType>();
                resultList.Add(typeToListInheritanceTreeFor);
                resultList.AddRange(GetTypeInheritanceTree(
                                        new ConstructedReturnType(
                                            classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.Generic.IList", 1).DefaultReturnType,
                                            new IReturnType[] { elementType }
                                            )
                                        ));
                resultList.Add(classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.IList", 0).DefaultReturnType);
                resultList.Add(classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.ICollection", 0).DefaultReturnType);
                // non-generic IEnumerable is already added by generic IEnumerable
                return(resultList);
            }

            HashSet <IReturnType> visitedSet   = new HashSet <IReturnType>();
            List <IReturnType>    visitedList  = new List <IReturnType>();
            Queue <IReturnType>   typesToVisit = new Queue <IReturnType>();
            bool enqueuedLastBaseType          = false;

            IReturnType currentType  = typeToListInheritanceTreeFor;
            IClass      currentClass = classToListInheritanceTreeFor;
            IReturnType nextType;

            do
            {
                if (currentClass != null)
                {
                    if (visitedSet.Add(currentType))
                    {
                        visitedList.Add(currentType);
                        foreach (IReturnType type in currentClass.BaseTypes)
                        {
                            typesToVisit.Enqueue(TranslateIfRequired(currentType, type));
                        }
                    }
                }
                if (typesToVisit.Count > 0)
                {
                    nextType = typesToVisit.Dequeue();
                }
                else
                {
                    nextType             = enqueuedLastBaseType ? null : DefaultClass.GetBaseTypeByClassType(classToListInheritanceTreeFor);
                    enqueuedLastBaseType = true;
                }
                if (nextType != null)
                {
                    currentType  = nextType;
                    currentClass = nextType.GetUnderlyingClass();
                }
            } while (nextType != null);
            lock (getTypeInheritanceTreeCache) {
                if (getTypeInheritanceTreeCache.Count == 0)
                {
                    DomCache.RegisterForClear(ClearGetTypeInheritanceTreeCache);
                }
                getTypeInheritanceTreeCache[typeToListInheritanceTreeFor] = visitedList;
            }
            return(visitedList);
        }