public ClassCodeElement Build () {
			classCodeElement = new ClassCodeElement (targetClassName);
			classCodeElement.Summary.Add ("Convenience class to access Animator states and parameters.");
			classCodeElement.Summary.Add ("Edits will be lost when this class is regenerated. ");
			classCodeElement.Summary.Add ("Hint: Editing might be useful after renaming animator items in complex projects:");
			classCodeElement.Summary.Add (" - Right click on an obsolete member and select Refactor/Rename. ");
			classCodeElement.Summary.Add (" - Change it to the new name. ");
			classCodeElement.Summary.Add (" - Delete this member to avoid comile error CS0102 ... already contains a definition ...''. ");
			string versionString = "" + DateTime.Now;
			classCodeElement.AddAttribute (new GeneratedClassAttributeCodeElement (versionString));
			if (!string.IsNullOrEmpty (config.DefaultNamespace)) {
				classCodeElement.NameSpace = new NameSpaceCodeElement (config.DefaultNamespace);
			}
			ProcessInternalFields ();
			if (config.GenerateMonoBehaviourComponent) {
				classCodeElement.SetBaseClass (config.MonoBehaviourComponentBaseClass);
				AwakeMethod = PrepareAwakeMethod ();
			} else {
				AwakeMethod = PrepareConstructors ();
			}
			EventManagerInitialiser = PrepareEventManagerInitialiserMethod ();
			ProcessAnimatorStates ();
			ProcessAnimatorParameters ();
			ProcessStateEventHandling ();
			return classCodeElement;
		}
Ejemplo n.º 2
0
        public ClassCodeElement Build()
        {
            ClassCodeElement classCodeElement = new ClassCodeElement(className);

            if (!HasType())
            {
                return(classCodeElement);
            }
            Type type = obj.GetType();

            classCodeElement.NameSpace.Name = type.Namespace;
            CodeElementUtils.AddAttributes(classCodeElement.Attributes, type.GetCustomAttributes(false));
            PropertyInfo[]      propertyInfoArray = type.GetProperties(propertiesBinding);
            List <PropertyInfo> propertyInfos     = GetFilteredList(propertyInfoArray, propertyInfoFilter);

            CodeElementUtils.AddPropertyInfos(classCodeElement.Properties, propertyInfos);
            MethodInfo[]      methodInfoArray = type.GetMethods(methodBinding);
            List <MethodInfo> methodInfos     = GetFilteredList(methodInfoArray, methodInfoFilter);

            CodeElementUtils.AddMethodInfos(classCodeElement.Methods, methodInfos);
            FieldInfo[]      fieldInfoArray = type.GetFields(fieldBinding);
            List <FieldInfo> fieldInfos     = GetFilteredList(fieldInfoArray, fieldInfoFilter);

            CodeElementUtils.AddFieldInfos(classCodeElement.Fields, fieldInfos);
            return(classCodeElement);
        }
Ejemplo n.º 3
0
        public static int CleanupExistingClass(ClassCodeElement existingClass, ClassCodeElement newClass, bool keepObsolete)
        {
            int remaining = RemoveDuplicateElements(existingClass.Properties, newClass.Properties, keepObsolete);

            remaining += RemoveDuplicateElements(existingClass.Fields, newClass.Fields, keepObsolete);
            remaining += RemoveDuplicateElements(existingClass.Methods, newClass.Methods, keepObsolete);
            return(remaining);
        }
Ejemplo n.º 4
0
        public static List <ClassMemberCompareElement> CompareClasses(ClassCodeElement existingClass, ClassCodeElement newClass,
                                                                      bool removeOldMembers, bool keepObsolete)
        {
            List <ClassMemberCompareElement> l = CompareElements(existingClass.Fields, newClass.Fields, removeOldMembers, keepObsolete);

            l.AddRange(CompareElements(existingClass.Properties, newClass.Properties, removeOldMembers, keepObsolete));
            l.AddRange(CompareElements(existingClass.Methods, newClass.Methods, removeOldMembers, keepObsolete));
            List <MemberCodeElement> allNew = new List <MemberCodeElement> ();

            newClass.Fields.ForEach((GenericFieldCodeElement element) => allNew.Add(element));
            newClass.Properties.ForEach((GenericPropertyCodeElement element) => allNew.Add(element));
            newClass.Methods.ForEach((GenericMethodCodeElement element) => allNew.Add(element));
            l.ForEach((ClassMemberCompareElement element) => {
                if (element.result == ClassMemberCompareElement.Result.Obsolete && element is CodeElementBasedCompareElement)
                {
                    MemberCodeElement underlyingElement = ((CodeElementBasedCompareElement)element).UnderlyingElement;
                    underlyingElement.Obsolete          = true;
                    allNew.Add(underlyingElement);
                }
            });
            int nextToLast = allNew.Count - 2;

            for (int i = 0; i <= nextToLast; i++)
            {
                MemberCodeElement element = allNew [i];
                int duplicateIndex        = allNew.FindIndex(i + 1, (MemberCodeElement m) => m.Equals(element));
                if (duplicateIndex >= 0)
                {
                    MemberCodeElement duplicate = allNew [duplicateIndex];
                    Func <MemberCodeElement, string> formatter = (MemberCodeElement m) => {
                        return((m.Obsolete ? "obsolete " : "") + m.MemberType + " " + m.ElementType + " " + m.GetSignature());
                    };
                    string message = string.Format("Possible naming conflict between [{0}] and [{1}].", formatter(element), formatter(duplicate));
                    if (duplicate.Obsolete)
                    {
                        message += " Previous element " + formatter(duplicate) + " will be removed.";
                    }
                    else
                    {
                        message += " Avoid using the same name for an Animator state and a parameter.";
                    }
                    l.Add(new CodeElementBasedCompareElement(element, message));
                    Logger.Debug(message);
                }
            }
            return(l);
        }
Ejemplo n.º 5
0
		public FileCodeElement (ClassCodeElement c) {
			Classes.Add (c);
		}
Ejemplo n.º 6
0
 /// <summary>
 /// Merges all those fields of other class into this one, that meet the filter condition.
 /// </summary>
 /// <param name="other">Other class whose fields will be merged into this class.</param>
 /// <param name="filter">Filter (optional), defines a subset of other's fields.</param>
 public void MergeFields(ClassCodeElement other, Predicate <GenericFieldCodeElement> filter = null)
 {
     CodeElementUtils.MergeElements <GenericFieldCodeElement> (Fields, other.Fields, filter);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Merges all those properties of other class into this one, that meet the filter condition.
 /// </summary>
 /// <param name="other">Other class whose properties will be merged into this class.</param>
 /// <param name="filter">Filter (optional), defines a subset of other's properties.</param>
 public void MergeProperties(ClassCodeElement other, Predicate <GenericPropertyCodeElement> filter = null)
 {
     CodeElementUtils.MergeElements <GenericPropertyCodeElement> (Properties, other.Properties, filter);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Merges all those methods of other class into this one, that meet the filter condition.
 /// </summary>
 /// <param name="other">Other class whose methods will be merged into this class.</param>
 /// <param name="filter">Filter (optional), defines a subset of other's methods.</param>
 public void MergeMethods(ClassCodeElement other, Predicate <GenericMethodCodeElement> filter = null)
 {
     CodeElementUtils.MergeElements <GenericMethodCodeElement> (Methods, other.Methods, filter);
 }
Ejemplo n.º 9
0
 public FileCodeElement(ClassCodeElement c)
 {
     Classes.Add(c);
 }
		/// <summary>
		/// Initialises templateEngine and builds newClass and existingClass.
		/// </summary>
		/// <returns>The classes.</returns>
		CodeGeneratorResult BuildClasses () {
			TemplateLookup templateLookup = new TemplateLookup (config);
			CodeGeneratorResult result = templateLookup.GetPathToTemplate (className);
			if (result.Success) {
				result = templateEngine.Prepare (templateLookup.TemplateConfig);
				if (result.NoSuccess) {
					return result;
				}
				newClass = builder.Build ();
				if (newClass.IsEmpty ()) {
					return result.SetError ("No Input", "The input seems to be invalid. Check that there are any states or parameter to process.");
				}
				Logger.Debug ("New: " + newClass);
				if (!existingClassBuilder.HasType ()) {
					Logger.Info ("Generating source for " + className + " the very first time");
				}
				try {
					existingClassBuilder.MethodBinding = BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | 
						BindingFlags.InvokeMethod | BindingFlags.NonPublic;
					existingClassBuilder.MethodInfoFilter = (MethodInfo mi) => mi.Name.StartsWith ("Is") || 
						mi.Name.StartsWith ("Set") || mi.Name.StartsWith ("Get") || mi.Name == "IdToName" 
							|| mi.Name == "Update" || mi.Name == "FixedUpdate";
					existingClass = existingClassBuilder.Build ();
					// little bit dirty hack: we don't want special methods like Update to participate in the regular
					// workflow i.e. mark as obsolete to be regenerated once with code throwing NotImplementedException.
					// So if settings have changed, mark them as obsolete to force their removal
					List<GenericMethodCodeElement> updateMethods = existingClass.Methods.FindAll (
						(GenericMethodCodeElement m) => m.Name == "Update" || m.Name == "FixedUpdate");
					updateMethods.ForEach ((GenericMethodCodeElement m) => m.Obsolete = true);
				} catch (System.Exception ex) {
					Logger.Warning (ex.Message + "\n" + ex.StackTrace);
					result.SetError ("Error", "Oops. An unexpected error occurred. Details" + ex.Message + "\n" + ex.StackTrace);
				}
			}
			return result;
		}
Ejemplo n.º 11
0
		/// <summary>
		/// Merges all those fields of other class into this one, that meet the filter condition.
		/// </summary>
		/// <param name="other">Other class whose fields will be merged into this class.</param>
		/// <param name="filter">Filter (optional), defines a subset of other's fields.</param>
		public void MergeFields (ClassCodeElement other, Predicate<GenericFieldCodeElement> filter = null) {
			CodeElementUtils.MergeElements <GenericFieldCodeElement> (Fields, other.Fields, filter);
		}
Ejemplo n.º 12
0
		/// <summary>
		/// Merges all those properties of other class into this one, that meet the filter condition.
		/// </summary>
		/// <param name="other">Other class whose properties will be merged into this class.</param>
		/// <param name="filter">Filter (optional), defines a subset of other's properties.</param>
		public void MergeProperties (ClassCodeElement other, Predicate<GenericPropertyCodeElement> filter = null) {
			CodeElementUtils.MergeElements <GenericPropertyCodeElement> (Properties, other.Properties, filter);
		}
Ejemplo n.º 13
0
		/// <summary>
		/// Merges all those methods of other class into this one, that meet the filter condition.
		/// </summary>
		/// <param name="other">Other class whose methods will be merged into this class.</param>
		/// <param name="filter">Filter (optional), defines a subset of other's methods.</param>
		public void MergeMethods (ClassCodeElement other, Predicate<GenericMethodCodeElement> filter = null) {
			CodeElementUtils.MergeElements <GenericMethodCodeElement> (Methods, other.Methods, filter);
		}