예제 #1
0
        public Method(Operation method, Context context, Element element, Class cls)
        {
            _context   = context;
            Name       = _context.CTSKeyWord[method.Name];
            Notes      = method.Notes ?? "";
            Id         = method.Id;
            IsAbstract = method.Abstract == "1";
            IsLocking  = !(method.IsQuery);
            Class      = cls;
            if (Name.StartsWith("operator"))
            {
                char[]   c   = new char[] { ' ' };
                string[] str = Name.Split(c);
                if (str.Length == 2)
                {
                    CTSType t = context.GetCTSType(str[1], element);
                    Name       = str[0] + " " + t.Value;
                    ReturnType = t;
                }
            }
            else
            {
                ReturnType = context.GetCTSType(method.Type, element);
            }
            int i = 0;

            foreach (var parameter in method.Params)
            {
                Parameter p = new Parameter(parameter, element, context);
                Parameters.Add(parameter.Pos ?? i, p);
                ++i;
            }
        }
예제 #2
0
 public Parameter(OperationParam parameter, Element element, Context context)
 {
     Name          = context.CTSKeyWord[parameter.Name];
     Notes         = parameter.Notes;
     Default       = parameter.Default ?? "";
     ParameterType = context.GetCTSType(parameter.Type, element);
 }
예제 #3
0
파일: Context.cs 프로젝트: rfrerebe/Cephei
        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;
                            }
                        }
                    }
                }
            }
        }