Exemplo n.º 1
0
        public static DefaultClass GetDummyClassForTypeParameter(ITypeParameter p)
        {
            DefaultClass c = new DefaultClass(p.Class.CompilationUnit, p.Name);

            if (p.Method != null)
            {
                c.Region = new DomRegion(p.Method.Region.BeginLine, p.Method.Region.BeginColumn);
            }
            else
            {
                c.Region = new DomRegion(p.Class.Region.BeginLine, p.Class.Region.BeginColumn);
            }
            c.Modifiers = ModifierEnum.Public;
            if (p.HasValueTypeConstraint)
            {
                c.ClassType = ClassType.Struct;
            }
            else if (p.HasConstructableConstraint)
            {
                c.ClassType = ClassType.Class;
            }
            else
            {
                c.ClassType = ClassType.Interface;
            }
            return(c);
        }
Exemplo n.º 2
0
            bool ReadClasses()
            {
                int classCount        = reader.ReadInt32();
                int externalTypeCount = reader.ReadInt32();

                types = new IReturnType[classCount + externalTypeCount];
                DefaultClass[] classes = new DefaultClass[classCount];
                for (int i = 0; i < classes.Length; i++)
                {
                    DefaultClass c = new DefaultClass(pc.AssemblyCompilationUnit, reader.ReadString());
                    classes[i] = c;
                    types[i]   = c.DefaultReturnType;
                }
                for (int i = classCount; i < types.Length; i++)
                {
                    string name = reader.ReadString();
                    types[i] = new GetClassReturnType(pc, name, reader.ReadByte());
                }
                stringArray = new string[reader.ReadInt32()];
                for (int i = 0; i < stringArray.Length; i++)
                {
                    stringArray[i] = reader.ReadString();
                }
                ReadAttributes(pc.AssemblyCompilationUnit);
                for (int i = 0; i < classes.Length; i++)
                {
                    ReadClass(classes[i]);
                    pc.AddClassToNamespaceList(classes[i]);
                    if (reader.ReadByte() != 64)
                    {
                        return(false);
                    }
                }
                return(true);
            }
Exemplo n.º 3
0
 public IClass GetInnermostClass(int caretLine, int caretColumn)
 {
     foreach (IClass c in Classes)
     {
         if (c != null && DefaultClass.IsInside(c, caretLine, caretColumn))
         {
             return(c.GetInnermostClass(caretLine, caretColumn));
         }
     }
     return(null);
 }
Exemplo n.º 4
0
        public override IClass GetUnderlyingClass()
        {
            if (cachedClass != null)
            {
                return(cachedClass);
            }
            DefaultClass c = new DefaultClass(cu, ClassType.Delegate, ModifierEnum.None, DomRegion.Empty, null);

            c.BaseTypes.Add(cu.ProjectContent.SystemTypes.Delegate);
            AddDefaultDelegateMethod(c, returnType ?? cu.ProjectContent.SystemTypes.Object, parameters ?? new IParameter[0]);
            cachedClass = c;
            return(c);
        }
Exemplo n.º 5
0
 static void AddTypeParametersForCtrlSpace(List <ICompletionEntry> result, IEnumerable <ITypeParameter> typeParameters)
 {
     foreach (ITypeParameter p in typeParameters)
     {
         DefaultClass c = DefaultTypeParameter.GetDummyClassForTypeParameter(p);
         if (p.Method != null)
         {
             c.Documentation = "Type parameter of " + p.Method.Name;
         }
         else
         {
             c.Documentation = "Type parameter of " + p.Class.Name;
         }
         result.Add(c);
     }
 }
Exemplo n.º 6
0
        internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList <IParameter> parameters)
        {
            ModifierEnum  modifiers    = ModifierEnum.Public | ModifierEnum.Synthetic;
            DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c);

            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c);
            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
            invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c);
            invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
        }
Exemplo n.º 7
0
            void ReadClass(DefaultClass c)
            {
                this.currentClass = c;
                int count;

                count = reader.ReadByte();
                for (int i = 0; i < count; i++)
                {
                    c.TypeParameters.Add(new DefaultTypeParameter(c, ReadString(), i));
                }
                if (count > 0)
                {
                    foreach (ITypeParameter typeParameter in c.TypeParameters)
                    {
                        count = reader.ReadInt32();
                        for (int i = 0; i < count; i++)
                        {
                            typeParameter.Constraints.Add(ReadType());
                        }
                    }
                }
                else
                {
                    c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.BaseTypes.Add(ReadType());
                }
                c.Modifiers       = (ModifierEnum)reader.ReadInt32();
                c.CalculatedFlags = reader.ReadByte();
                c.ClassType       = (ClassType)reader.ReadByte();
                ReadAttributes(c);
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    DefaultClass innerClass = new DefaultClass(c.CompilationUnit, c);
                    innerClass.FullyQualifiedName = reader.ReadString();
                    c.InnerClasses.Add(innerClass);
                    ReadClass(innerClass);
                }
                this.currentClass = c;
                count             = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Methods.Add(ReadMethod());
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Properties.Add(ReadProperty());
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Events.Add(ReadEvent());
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Fields.Add(ReadField());
                }
                this.currentClass = null;
            }
Exemplo n.º 8
0
        /// <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);
        }