Ejemplo n.º 1
0
        /// <summary>
        /// Traverses the specified FCM.
        /// </summary>
        /// <param name="fcm">The FCM.</param>
        public void Traverse(FileCodeModel fcm)
        {
            if (fcm == null)
            {
                return;
            }

            try
            {
                _visitor.BeginTraverse(fcm);

                foreach (CodeElement cel in fcm.CodeElements)
                {
                    if (cel.Kind == vsCMElement.vsCMElementNamespace)
                    {
                        CandleCodeNamespace cns =
                            (CandleCodeNamespace)CandleCodeElement.CreateFromCodeElement(null, cel);
                        TraverseInternal(cns);
                    }
                }
                _visitor.EndTraverse(fcm);
            }
            catch (ExitException)
            {
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Traverses the internal.
        /// </summary>
        /// <param name="cce">The cce.</param>
        private void TraverseInternal(CandleCodeElement cce)
        {
            if (_filter == null || _filter.ShouldVisit(cce))
            {
                cce.Accept(_visitor);
            }

            foreach (CandleCodeElement child in cce.Members)
            {
                TraverseInternal(child);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates from code element.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="elem">The elem.</param>
        /// <returns></returns>
        public static CandleCodeElement CreateFromCodeElement(CandleCodeElement parent, CodeElement elem)
        {
            if (elem == null)
            {
                return(null);
            }

            switch (elem.Kind)
            {
            case vsCMElement.vsCMElementNamespace:
                return(new CandleCodeNamespace((CodeNamespace)elem));

            case vsCMElement.vsCMElementProperty:
                return(new CandleCodeProperty(parent, (CodeProperty)elem));

            case vsCMElement.vsCMElementClass:
                return(new CandleCodeClass(parent, (CodeClass)elem));

            case vsCMElement.vsCMElementFunction:
                return(new CandleCodeFunction(parent, (CodeFunction)elem));

            case vsCMElement.vsCMElementParameter:
                return(new CandleCodeParameter(parent, (CodeParameter)elem));

            case vsCMElement.vsCMElementStruct:
                return(new CandleCodeStruct(parent, (CodeStruct)elem));

            case vsCMElement.vsCMElementEnum:
                return(new CandleCodeEnum(parent, (CodeEnum)elem));

            case vsCMElement.vsCMElementInterface:
                return(new CandleCodeInterface(parent, (CodeInterface)elem));

            case vsCMElement.vsCMElementVariable:
                return(new CandleCodeVariable(parent, (CodeVariable)elem));
            }
            return(null);
        }
Ejemplo n.º 4
0
        // BEGIN-COMMENT : Inutile car les attributs des méthodes virtuelles sont bien répercutés sur les méthodes d'override

        ///// <summary>
        ///// Recherche si il y a des attributs multiples décrits dans un attribut GeneratedCode.
        ///// </summary>
        ///// <param name="strategyId"></param>
        ///// <returns></returns>
        //private List<int> FindGeneratedHashValue(string strategyId)
        //{
        //    CodeElements elements = GetAttributesInternal();

        //    // Recherche de l'attribut GeneratedCodeValue
        //    foreach (CodeElement element in elements)
        //    {
        //        if (element.Name == GeneratedAttributeName)
        //        {
        //            try
        //            {
        //                CodeAttribute2 attr = (CodeAttribute2)element;
        //                Dictionary<string, List<int>> data = CandleCodeElement.DeserializeGeneratedAttributeValue(attr.Value);
        //                if (data == null)
        //                    return null;
        //                List<int> list;
        //                if (data.TryGetValue(strategyId, out list))
        //                {
        //                    data.Remove(strategyId);
        //                    if (data.Count == 0)
        //                        attr.Delete();
        //                    else
        //                        attr.Value = SerializeGeneratedAttributeValue(data);
        //                    return list;
        //                }
        //            }
        //            catch { }
        //            break;
        //        }
        //    }

        //    return null;
        //}

        ///// <summary>
        ///// Calcul de la valeur de hashage d'un atrribut (Nom + valeur)
        ///// </summary>
        ///// <param name="attribute"></param>
        ///// <returns></returns>
        //private int CalculateAttributHashCode(CodeAttribute2 attribute)
        //{
        //    return attribute.Name.GetHashCode() + attribute.Value.GetHashCode();
        //}

        ///// <summary>
        ///// Supprime les attributs multiples générés précédemment par une stratégie
        ///// </summary>
        ///// <param name="strategyId"></param>
        //public void RemoveGeneratedAttributes(string strategyId)
        //{
        //    List<int> hashValues = FindGeneratedHashValue(strategyId);
        //    if (hashValues == null)
        //        return;

        //    foreach (int hv in hashValues)
        //    {
        //        CodeElements elements = GetAttributesInternal();
        //        foreach (CodeElement element in elements)
        //        {
        //            CodeAttribute2 attr = (CodeAttribute2)element;
        //            if (CalculateAttributHashCode(attr) == hv)
        //                attr.Delete();
        //        }
        //    }
        //}

        ///// <summary>
        ///// Pour chaque attribut généré, on va garder la trace de sa génération pour pouvoir le supprimer lors de la prochaine génération.
        ///// Ceci n'est valable que dans le cas d'une génération dans un fichier de code utilisateur.
        ///// </summary>
        ///// <param name="strategyId"></param>
        ///// <param name="attribute"></param>
        //private void AddGeneratedAttribute(string strategyId, CodeAttribute2 attribute)
        //{
        //    if (strategyId != null)
        //    {
        //        CodeAttribute generatedCodeAttribute = null;
        //        foreach (CodeElement element in GetAttributesInternal())
        //        {
        //            if (element.Name == GeneratedAttributeName)
        //            {
        //                generatedCodeAttribute = element as CodeAttribute2;
        //                break;
        //            }
        //        }

        //        Dictionary<string, List<int>> data = new Dictionary<string, List<int>>();
        //        if (generatedCodeAttribute == null)
        //        {
        //            generatedCodeAttribute = AddAttributeInternal(GeneratedAttributeName);
        //        }
        //        else
        //        {
        //            data = DeserializeGeneratedAttributeValue(generatedCodeAttribute.Value);
        //        }

        //        List<int> list;
        //        if (!data.TryGetValue(strategyId, out list))
        //        {
        //            list = new List<int>();
        //            data.Add(strategyId, list);
        //        }

        //        list.Add(CalculateAttributHashCode(attribute));
        //        generatedCodeAttribute.Value = SerializeGeneratedAttributeValue(data);
        //    }
        //}

        ///// <summary>
        ///// Serialisation des valeurs de hashage de chaque attributs multiples
        ///// </summary>
        ///// <param name="value"></param>
        ///// <returns></returns>
        //internal static string SerializeGeneratedAttributeValue(Dictionary<string, List<int>> value)
        //{
        //    // Forme = strategyid:n,n,n|strategyid:n,n,n
        //    StringBuilder sb = new StringBuilder("\"");
        //    foreach (string strategyId in value.Keys)
        //    {
        //        sb.Append(strategyId);
        //        sb.Append(':');
        //        foreach (int hv in value[strategyId])
        //        {
        //            sb.Append(hv);
        //            sb.Append(',');
        //        }
        //        sb.Append('|');
        //    }
        //    sb.Append("\", \"\"");
        //    return sb.ToString();
        //}

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="value"></param>
        ///// <returns></returns>
        //internal static Dictionary<string, List<int>> DeserializeGeneratedAttributeValue(string value)
        //{
        //    Dictionary<string, List<int>> values = new Dictionary<string, List<int>>();

        //    // Préparation des données à déserialiser
        //    value = value.Substring(0, value.LastIndexOf(','));
        //    value = value.Trim('"');

        //    string[] parts = value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
        //    foreach (string part in parts)
        //    {
        //        int pos = part.IndexOf(':');
        //        string strategyId = part.Substring(0, pos);
        //        List<int> hashValues = new List<int>();
        //        foreach (string v in part.Substring(pos + 1).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
        //        {
        //            hashValues.Add(Int32.Parse(v));
        //        }
        //        values.Add(strategyId, hashValues);
        //    }

        //    return values;
        //}
        // END-COMMENT

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="CandleCodeElement"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        public CandleCodeElement(CandleCodeElement parent)
        {
            _parent = parent;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeVariable"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The code variable.</param>
 internal CandleCodeVariable(CandleCodeElement parent, CodeVariable cel) : base(parent)
 {
     _codeElement = cel;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeParameter"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The cel.</param>
 internal CandleCodeParameter(CandleCodeElement parent, CodeParameter cel) : base(parent)
 {
     _codeElement = cel;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeFunction"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The cel.</param>
 internal CandleCodeFunction(CandleCodeElement parent, CodeFunction cel) : base(parent)
 {
     _codeElement = cel;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeStruct"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The cel.</param>
 internal CandleCodeStruct(CandleCodeElement parent, CodeStruct cel) : base(parent)
 {
     _codeElement = cel;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeClass"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The cel.</param>
 internal CandleCodeClass(CandleCodeElement parent, CodeClass cel) : base(parent)
 {
     _codeElement = cel;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeInterface"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The cel.</param>
 internal CandleCodeInterface(CandleCodeElement parent, CodeInterface cel) : base(parent)
 {
     _codeElement = cel;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeEnum"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The cel.</param>
 internal CandleCodeEnum(CandleCodeElement parent, CodeEnum cel) : base(parent)
 {
     _codeElement = cel;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CandleCodeProperty"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cel">The cel.</param>
 internal CandleCodeProperty(CandleCodeElement parent, CodeProperty cel) : base(parent)
 {
     _codeElement = cel;
 }