Esempio n. 1
0
        /// <summary>
        /// Performs final merging of old and new class, then triggers template engine to generate the code.
        /// </summary>
        /// <returns>Result to check for errors.</returns>
        public CodeGeneratorResult GenerateCode()
        {
            if (!config.IgnoreExistingCode)
            {
                if (existingClass != null && !existingClass.IsEmpty())
                {
                    string msg = string.Format("Animator state or parameter is no longer valid{0}. Refactor your code to not contain any references.", (config.KeepObsoleteMembers ? "" : " and will be removed in the next code generation"));
                    existingClass.AddAttributeToAllMembers(new ObsoleteAttributeCodeElement(msg, false));
                    List <MemberCodeElement> allMembers = newClass.GetAllMembers();
                    newClass.MergeMethods(existingClass, (element) => !allMembers.Contains(element));
                    newClass.MergeProperties(existingClass, (element) => !allMembers.Contains(element));
                    newClass.MergeFields(existingClass, (element) => !allMembers.Contains(element));
                }
            }
            FileCodeElement fileElement = new FileCodeElement(newClass);

            fileElement.Usings.Add(new UsingCodeElement("UnityEngine"));
            CodeGeneratorResult result = templateEngine.GenerateCode(fileElement);

            if (result.Success)
            {
                code = templateEngine.Code;
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Checks all preconditions and builds both class code elements.
        /// </summary>
        /// <returns>Result to check if there were errors or user input is required.</returns>
        /// <param name="suppressLoggingOfChanges">If set to <c>true</c> changes will not be printed to console.</param>
        public CodeGeneratorResult PrepareCodeGeneration(bool suppressLoggingOfChanges)
        {
            CodeGeneratorResult result = BuildClasses();

            if (result.Error)
            {
                return(result);
            }
            if (!existingClass.IsEmpty() && !config.IgnoreExistingCode)
            {
                int remaining = CodeElementUtils.CleanupExistingClass(existingClass, newClass, config.KeepObsoleteMembers);
                if (remaining > 0 && !suppressLoggingOfChanges)
                {
                    string consoleMessage = "";
                    List <MemberCodeElement> previousMembers = existingClass.GetAllMembers();
                    int previousMembersCount = previousMembers.Count;
                    for (int i = 0; i < previousMembersCount; i++)
                    {
                        consoleMessage += previousMembers [i].GetSignature() + "\n";
                    }
                    Logger.Info("Members found in previous version that will be marked as obsolete: " + consoleMessage);
                }
            }
            return(result);
        }