protected ArchAngel.Providers.CodeProvider.DotNet.Function CreateFunction(string functionName, string functionParameterName, int index) { ArchAngel.Providers.CodeProvider.DotNet.Function createdFunction = new ArchAngel.Providers.CodeProvider.DotNet.Function(controller); createdFunction.Name = functionName; createdFunction.Index = index; createdFunction.Modifiers.Add(Modifier); createdFunction.ReturnType = new DataType(controller, ReturnType); createdFunction.BodyText = BodyText; Parameter param = new Parameter(controller); param.Name = functionParameterName; param.DataType = DataType; createdFunction.Parameters.Add(param); return(createdFunction); }
public RemoveModifiersFromFunctionAction(Function functionToChange) { FunctionToChange = functionToChange; }
public AddModifierToFunctionAction(Function functionToChange, string newModifier, bool insertAtStart) { FunctionToChange = functionToChange; NewModifier = newModifier; InsertAtStart = insertAtStart; }
public void Function() { Function item = new Function(controller, "Function1", new DataType(controller, "ReturnObjectOfSomeKind")); item.Parameters.Add(new Parameter(controller, "float", "f")); item.Parameters.Add(new Parameter(controller, "InputObject", "j")); Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Function1 (float, InputObject)")); Class cl = new Class(controller, "Class1"); cl.AddChild(item); Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Class1.Function1 (float, InputObject)")); }
public void Function() { Function inter = new Function(controller); inter.Name = "File"; inter.Modifiers.Add("public"); inter.ReturnType = new DataType(controller,"int"); Parameter param = new Parameter(controller); param.Name = "i"; param.DataType = "int"; inter.Parameters.Add(param); Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True); }
public ChangeNameOfFunctionAction(Function functionToChange, string newName) { FunctionToChange = functionToChange; NewName = newName; }
public AddMethodToClassAction(Function functionToAdd, AdditionPoint additionPoint, Class classToAddTo) { ConstructToAdd = MethodToAdd = functionToAdd; AdditionPoint = additionPoint; ClassToAddTo = classToAddTo; }
protected void SetupFunctions() { controller = new CSharpController(); func1 = CreateFunction("Function1", "i", 21); func2 = CreateFunction("Function2", "j", 22); func3 = CreateFunction("Function3", "k", 23); func4 = CreateFunction("Function4", "l", 24); Class cl = new Class(controller, "Class1"); cl.AddChild(func1); cl.AddChild(func2); cl.AddChild(func3); cl.AddChild(func4); controller.Root.AddChild(cl); }
private static void ApplyFunctionDeletion(Actions actions, Function existingFunction) { actions.AddAction(new RemoveMethodFromClassAction(existingFunction)); }
private static void ApplyFunctionChanges(Actions actions, Function existingFunction, Function exampleFunction) { ApplyHeaderChanges(existingFunction, exampleFunction, actions); ApplyBodyChanges(existingFunction, exampleFunction, actions); }
private static void ApplyBodyChanges(Function existingFunction, Function exampleFunction, Actions actions) { actions.AddAction(new ChangeMethodBodyAction(existingFunction, exampleFunction)); }
protected ArchAngel.Providers.CodeProvider.DotNet.Function CreateFunction(string functionName, string functionParameterName, int index) { ArchAngel.Providers.CodeProvider.DotNet.Function createdFunction = new ArchAngel.Providers.CodeProvider.DotNet.Function(controller); createdFunction.Name = functionName; createdFunction.Index = index; createdFunction.Modifiers.Add(Modifier); createdFunction.ReturnType = new DataType(controller, ReturnType); createdFunction.BodyText = BodyText; Parameter param = new Parameter(controller); param.Name = functionParameterName; param.DataType = DataType; createdFunction.Parameters.Add(param); return createdFunction; }
public string GetFormattedDefaultCode() { bool isMethod = false; MethodInfo method = null; bool hasApiExt = false; string defaultCode = ""; foreach (MethodInfo meth in ObjectType.GetMethods()) { if (meth.Name == PropertyName) { ParameterInfo[] realParams = meth.GetParameters(); if (realParams.Length == ParameterTypes.Count) { bool paramsMatch = true; for (int paramCounter = 0; paramCounter < realParams.Length; paramCounter++) { if (realParams[paramCounter].ParameterType.FullName != ParameterTypes[paramCounter].DataType.FullName) { paramsMatch = false; break; } } if (paramsMatch) { object[] allAttributes = meth.GetCustomAttributes(false); foreach (object att in allAttributes) { Type attType = att.GetType(); if (Utility.StringsAreEqual(attType.Name, "ApiExtensionAttribute", true)) { hasApiExt = true; method = meth; defaultCode = (string)attType.InvokeMember("DefaultCode", BindingFlags.GetProperty, null, att, null); } } break; } } } } Type returnType = null; if (method != null) { isMethod = true; returnType = method.ReturnType; } else { PropertyInfo property = ObjectType.GetProperty(PropertyName); object[] allAttributes = property.GetCustomAttributes(false); foreach (object att in allAttributes) { Type attType = att.GetType(); if (Utility.StringsAreEqual(attType.Name, "ApiExtensionAttribute", true)) { hasApiExt = true; defaultCode = (string)attType.InvokeMember("DefaultCode", BindingFlags.GetProperty, null, att, null); break; } } returnType = property.PropertyType; } if (!hasApiExt)// attributes != null && attributes.Length == 0) { throw new NotImplementedException(String.Format("DefaultCodeAttribute not implemented for {0}.{1} yet.", ObjectType.FullName, PropertyName)); } string code = defaultCode;// attributes[0].DefaultCode; CSharpParser csf = new CSharpParser(); if (isMethod) { Function f = (Function)csf.ParseSingleConstruct("public void Method1(){ " + code + " }", BaseConstructType.MethodDeclaration); code = f.BodyText; } else { Property p = (Property)csf.ParseSingleConstruct("public int Property1 { " + code + " }", BaseConstructType.PropertyDeclaration); if (p.GetAccessor != null) { code = p.GetAccessor.BodyText; } else { code = p.SetAccessor.BodyText; } } int secondLineBreak = code.IndexOf("\r\n", code.IndexOf("{")) + 2; int lastLineBreak = code.LastIndexOf("\r\n", code.LastIndexOf("}")); if (lastLineBreak > secondLineBreak) { code = code.Substring(secondLineBreak, lastLineBreak - secondLineBreak); } else { code = ""; } string[] lines = Utility.StandardizeLineBreaks(code, Utility.LineBreaks.Unix).Split('\n'); StringBuilder sb = new StringBuilder(lines.Length * 100); for (int i = 0; i < lines.Length; i++) { if (lines[i].Length > 1) { sb.AppendLine(lines[i].Substring(1)); } else { sb.AppendLine(lines[i]); } } return(sb.ToString()); }
public AddAttributeToMethodAction(Function methodToAddTo, Attribute attributeToAdd) { MethodToAddTo = methodToAddTo; AttributeToAdd = attributeToAdd; }
/// <summary> /// Changes the entire header, including modifiers, return-type, name and parameters. /// </summary> /// <param name="existingFunction"></param> /// <param name="exampleFunction"></param> /// <param name="actions"></param> private static void ApplyHeaderChanges(Function existingFunction, Function exampleFunction, Actions actions) { if (existingFunction.Name != exampleFunction.Name) { // Change datatype actions.AddAction(new ChangeMethodHeaderAction(existingFunction, exampleFunction)); } }
public ChangeMethodBodyAction(Function methodToChange, Function newMethodInfo) { MethodToChange = methodToChange; NewMethodInfo = newMethodInfo; }
private Function Construct(Class @class) { Function func = new Function(@class.Controller); func.Name = _name; func.Modifiers.AddRange(_Modifiers); func.ReturnType = new DataType(@class.Controller, _returnTypeName); func.BodyText = _body; foreach (var p in _ParameterTypes) func.Parameters.Add(new Parameter(@class.Controller, func, p.Name, p.DataType, BaseConstruct.CodeLanguage.CSharp)); return func; }
public VBFunctionPrinter(Function obj) { this.obj = obj; }
public ChangeReturnTypeOfFunctionAction(Function functionToChange, DataType newName) { FunctionToChange = functionToChange; NewType = newName; }