Exemplo n.º 1
0
        public void LinkCTSTypes(Class currentClass, CTSType ctsType)
        {
            if (ctsType == null ||
                ctsType.Feature != CTSType.FeatureType.Object ||
                ctsType.Value == null || ctsType.Value == "" ||
                ctsType.Value == "void" ||
                ctsType.Value.Contains("<")
                )
            {
                return;
            }
            List <Class> cSet = RootTree.FindClassByName(ctsType.Value);

            if (cSet.Count == 0 || cSet[0].FilledFromRepository == false)
            {
                //                if (ctsType.Value.Contains(">")) Debugger.Break();
                Console.WriteLine("\t\tCould not find " + ctsType.Value + " in memory");
                List <Element> collection;
                if (ctsType.Value.Contains("::"))
                {
                    collection = GetElementsByQuery("FindByName", ctsType.Value.Substring(ctsType.Value.LastIndexOf("::") + 2));
                }
                else
                {
                    collection = GetElementsByQuery("FindByName", ctsType.Value);
                }
                if (collection != null)
                {
                    foreach (var element in collection)
                    {
                        if (!element.IsSpec &&                  // explicitly excluded
                            element.ParentID == 0 &&            // no nested classes
                            element.IsTempleClass(_repo) &&     // no parameterised interfaces
                            element.Stereotype != "typedef" &&  // in this context all typedefs are templates.. so exlcude
                            !element.Name.Contains("<") &&
                            element.Name != "engine" &&
                            element.Name != "arguments" &&
                            element.Name != "results" &&
                            element.Name != "Point"
                            )
                        {
                            Class cclass = RootTree.FindClassByElement(element);
                            if (cclass == null)
                            {
                                cclass = new Class(element, RootTree, this);
                                Package rt = RootTree.GetById(element.PackageId.Value);
                                rt.Classes.Add(cclass.Name, cclass);
                            }
                            cSet.Add(cclass);
                        }
                    }
                }
                foreach (Class cclass in cSet)
                {
                    cclass.FilledFromRepository = true;
                }
            }
            // OK there must be at least one.. lets pick the nearest
            if (cSet.Count > 0)
            {
                Class matchedByFile    = null;
                Class matchedByPackage = null;
                Class matchedByName    = null;
                Class matchedByParent  = null;

                Class matched;                     // best from above

                foreach (Class cclass in cSet)
                {
                    if (matchedByFile == null && cclass.FileName == currentClass.FileName)
                    {
                        matchedByFile = cclass;
                    }
                    if (matchedByParent == null && cclass.ParentID == currentClass.Id)
                    {
                        matchedByParent = cclass;
                    }
                    if (matchedByPackage == null && cclass.Package == currentClass.Package)
                    {
                        matchedByPackage = cclass;
                    }
                    if (matchedByName == null && cclass.Name == ctsType.Value)
                    {
                        matchedByName = cclass;
                    }
                }

                matched = (matchedByFile != null ? matchedByFile : (matchedByParent != null ? matchedByParent : (matchedByPackage != null ? matchedByPackage : matchedByName)));

                // fill in the matching class reference, and do the same for any similar references in this class.
                if (matched != null)
                {
                    ctsType.Class = matched;
                    matched.References.Add(ctsType);
                    foreach (Method method in currentClass.Methods)
                    {
                        if (method.ReturnType != null && method.ReturnType.Value != null && method.ReturnType.Value == ctsType.Value)
                        {
                            method.ReturnType.Class = matched;
                        }
                        foreach (KeyValuePair <int, Parameter> pair in method.Parameters)
                        {
                            if (pair.Value.ParameterType.Value != null && pair.Value.ParameterType.Value == ctsType.Value)
                            {
                                pair.Value.ParameterType.Class = matched;
                            }
                        }
                    }
                }
            }
        }