public void ProcessStuff(ClassComponent cls)
        {
            foreach (MethodComponent method in cls.Methods)
            {
                int i = 0;

                SwitchStatementComponent current = null;
                foreach (LineModel line in method.Lines)
                {
                    if (line.HasSwitch)
                    {
                        string sw       = method.TextLines[i];
                        int    start    = sw.IndexOf("(") + 1;
                        int    end      = sw.LastIndexOf(")");
                        string typeCode = sw.Substring(start, end - start);
                        if (!m_htTypeCodes.ContainsKey(typeCode))
                        {
                            m_htTypeCodes[typeCode] = new SwitchStatementComponent(method, typeCode);
                        }
                        current = (SwitchStatementComponent)m_htTypeCodes[typeCode];
                        current.Count++;
                    }
                    if (line.HasCase && current != null && current.Count == 1)
                    {
                        current.CaseCount++;
                    }
                    i++;
                }
            }

            foreach (ClassComponent inner in cls.InnerClasses)
            {
                ProcessStuff(inner);
            }
        }
        private static IEnumerable <EventObserverMethod> FindExceptionHandlers(ClassComponent component)
        {
            foreach (var method in component.AnnotatedType.Methods)
            {
                var injectParams = method.Parameters
                                   .Where(p => p.Annotations.OfType <HandlesAttribute>().Any())
                                   .ToArray();
                if (!injectParams.Any())
                {
                    continue;
                }
                if (injectParams.Length > 1)
                {
                    throw new InvalidComponentException(Formatters.MultipleHandlesParameter(method.Method));
                }

                var param = injectParams.Single();
                if (GenericUtils.OpenIfGeneric(param.Parameter.ParameterType) != typeof(ICaughtException <>))
                {
                    throw new InvalidComponentException(Formatters.WrongHandlesParamType(param.Parameter));
                }

                yield return(new EventObserverMethod(component, param.Parameter, param.Annotations));
            }
        }
        public void ProcessStuff(ClassComponent cls)
        {
            Hashtable htUses = SearchUses(cls);
            Hashtable htDefs = SearchDefs(cls, htUses);

            GenerateForClass(htUses, htDefs, cls);

            foreach (ClassComponent inner in cls.InnerClasses)
            {
                ProcessStuff(inner);
            }
        }
Exemple #4
0
        protected override void Prepare()
        {
            IterationCount = 1000;
            var entityManager = new EntityManager();
            var entityType1   = new ComponentType[]
            {
                ComponentType.Create <StructComponent>(),
                ComponentType.Create <Struct2Component>(),
                ComponentType.Create <ClassComponent>(),
            };
            var entityType2 = new ComponentType[]
            {
                ComponentType.Create <Struct2Component>(),
                ComponentType.Create <ClassComponent>(),
            };
            var entityType3 = new ComponentType[]
            {
                ComponentType.Create <Struct2Component>(),
                ComponentType.Create <StructComponent>()
            };
            var classObjects = new ClassComponent[entityCount];

            for (int i = classObjects.Length - 1; i >= 0; i--)
            {
                classObjects[i] = new ClassComponent(i);
            }
            for (var i = 0; i < entityCount; i++)
            {
                if (i % 3 == 0)
                {
                    var e = entityManager.CreateEntity(entityType1);
                    entityManager.SetComponent(e, classObjects[i]);
                }
                else if (i % 3 == 1)
                {
                    var e = entityManager.CreateEntity(entityType2);
                    entityManager.SetComponent(e, classObjects[i]);
                }
                else
                {
                    entityManager.CreateEntity(entityType3);
                }
            }
            structGroup = entityManager.RegisterGroup(new StructGroup());

            world = new World();
            for (int i = 0; i < entityCount; i++)
            {
                world.Entities.Add(new Entity(i));
            }
            world.Behaviours.Add(new EntityBehaviour());
        }
 public void ProcessStuff(ClassComponent cls)
 {
     ClassCount++;
     foreach (MethodComponent meth in cls.Methods)
     {
         Lines += meth.Lines.Count;
     }
     foreach (ClassComponent inner in cls.InnerClasses)
     {
         ProcessStuff(inner);
         ClassCount++;
     }
 }
        protected void OnMouseClickClass(object sender, MouseEventArgs e)
        {
            MovieClip clip = (MovieClip)sender;

            if (clip.Object != null)
            {
                ClassComponent mc = (ClassComponent)clip.Object;
                if (mc.CodeClass != null)
                {
                    CodeClass cc = (CodeClass)mc.CodeClass;
                    SelectObjectClass(cc);
                }
            }
        }
        public Hashtable SearchUses(ClassComponent cls)
        {
            Hashtable htUses = new Hashtable();

            foreach (MethodComponent method in cls.Methods)
            {
                int i = 0;
                foreach (LineModel line in method.Lines)
                {
                    CollectTemporaryFieldUses(htUses, cls, method, line, method.TextLines[i]);
                    i++;
                }
            }
            return(htUses);
        }
Exemple #8
0
        public void Search(ClassComponent cls)
        {
            if (cls.CodeClass.Children.Count > 0)
            {
                ClassHierarchy ch = new ClassHierarchy();
                ch.Parent = cls.Name;
                foreach (EnvDTE.CodeClass child in cls.CodeClass.Children)
                {
                    ch.Children.Add(child.Name);
                }
                m_htClassHierchs[cls.CodeClass] = ch;
            }

            foreach (ClassComponent inner in cls.InnerClasses)
            {
                Search(inner);
            }
        }
 protected void CollectTemporaryFieldUses(Hashtable htUses, ClassComponent cls, MethodComponent m, LineModel line, string strLine)
 {
     if (line.HasConditional)
     {
         foreach (FieldComponent field in cls.Fields)
         {
             if (strLine.IndexOf(field.Name) > -1)
             {
                 if (htUses[field] == null)
                 {
                     htUses[field] = new ArrayList();
                 }
                 if (!((ArrayList)htUses[field]).Contains(m))
                 {
                     ((ArrayList)htUses[field]).Add(m);
                 }
             }
         }
     }
 }
Exemple #10
0
        public ArrayList Search(ClassComponent cls)
        {
            ArrayList list = new ArrayList();

            foreach (MethodComponent method in cls.Methods)
            {
                if (method.Lines.Count > this.MethodLength &&
                    method.NumConditionalStmts > this.ConditionalStmts &&
                    method.NumIterationStmts > this.IterationStmts)
                {
                    list.Add(method);
                }
            }

            foreach (ClassComponent inner in cls.InnerClasses)
            {
                list.AddRange(Search(inner));
            }

            return(list);
        }
        public void Search(ClassComponent cls)
        {
            foreach (MethodComponent method in cls.Methods)
            {
                int i = 0;
                foreach (LineModel line in method.Lines)
                {
                    if (line.HasCode)
                    {
                        string strLine = method.TextLines[i];
                        //MakeMessageChainComponent( strLine );
                        MakeChain(strLine);
                    }
                    i++;
                }
            }

            foreach (ClassComponent inner in cls.InnerClasses)
            {
                Search(inner);
            }
        }
        protected void GenerateForClass(Hashtable htDefs, Hashtable htUses, ClassComponent cls)
        {
            ArrayList uses = new ArrayList();
            ArrayList defs = new ArrayList();
            TemporaryFieldComponent temp = new TemporaryFieldComponent(cls, cls.Name, cls.FullName);

            foreach (FieldComponent field in htUses.Keys)
            {
                if ((ArrayList)htUses[field] != null)
                {
                    foreach (object obj in (ArrayList)htUses[field])
                    {
                        if (!uses.Contains(obj))
                        {
                            uses.Add(obj);
                        }
                    }
                }
                if ((ArrayList)htDefs[field] != null)
                {
                    foreach (object obj in (ArrayList)htDefs[field])
                    {
                        if (!defs.Contains(obj))
                        {
                            defs.Add(obj);
                        }
                    }
                }
            }
            temp.Uses = uses;
            temp.Defs = defs;
            if (temp.Uses.Count > 0 || temp.Defs.Count > 0)
            {
                m_list.Add(temp);
            }
        }
Exemple #13
0
        protected void WalkElements(CodeElement cein, AbstractComponent parent)
        {
            CodeElements ces;

            switch (cein.Kind)
            {
            // Handle namespaces
            case EnvDTE.vsCMElement.vsCMElementNamespace:
            {
                CodeNamespace cn = (CodeNamespace)cein;

                ces = cn.Members;
                foreach (CodeElement ce in ces)
                {
                    WalkElements(ce, parent);
                }
                break;
            }

            // Handle classes
            case EnvDTE.vsCMElement.vsCMElementClass:
            {
                CodeClass cc = (CodeClass)cein;

                ClassComponent cls = new ClassComponent(cc.FullName, cc.Name);
                cls.CodeClass = cc;
                parent.Visit(cls);

                ces = cc.Members;
                foreach (CodeElement ce in ces)
                {
                    WalkElements(ce, cls);
                }
                break;
            }

            // Handle interfaces
            case EnvDTE.vsCMElement.vsCMElementInterface:
            {
                CodeInterface ci = (CodeInterface)cein;

                // nothing for now.

                break;
            }

            // Handle methods (functions)
            case  EnvDTE.vsCMElement.vsCMElementFunction:
            {
                CodeFunction cf = (CodeFunction)cein;

                MethodComponent mc = new MethodComponent(cf.FullName, cf.Name);
                parent.Visit(mc);
                mc.CreateRepresentation(GetFunctionText(cf));
                mc.CodeFunction = cf;

                break;
            }

            // Handle properties
            case EnvDTE.vsCMElement.vsCMElementProperty:
            {
                CodeProperty cp = (CodeProperty)cein;

                PropertyComponent pc = new PropertyComponent(cp.FullName, cp.Name);
                parent.Visit(pc);

                break;
            }

            // Handle fields (variables)
            case EnvDTE.vsCMElement.vsCMElementVariable:
            {
                CodeVariable cv = (CodeVariable)cein;

                FieldComponent fc = new FieldComponent(cv.FullName, cv.Name);
                parent.Visit(fc);

                break;
            }
            }
        }
 public TemporaryFieldComponent(ClassComponent unit, string name, string fullName) : base(fullName, name)
 {
     this.ClassComponent = unit;
 }