//TODO: handle generics public static IMethod CodeDomToMDDomMethod(CodeMemberMethod method) { DomMethod meth = new DomMethod(); meth.Name = method.Name; meth.ReturnType = new DomReturnType(method.ReturnType.BaseType); meth.Modifiers = CodeDomModifiersToMDDom(method.Attributes); foreach (CodeParameterDeclarationExpression dec in method.Parameters) { DomParameter par = new DomParameter(meth, dec.Name, new DomReturnType(dec.Type.BaseType)); if (dec.Direction == FieldDirection.Ref) { par.ParameterModifiers &= ParameterModifiers.Ref; } else if (dec.Direction == FieldDirection.Out) { par.ParameterModifiers &= ParameterModifiers.Out; } else { par.ParameterModifiers &= ParameterModifiers.In; } meth.Add(par); } return(meth); }
IMethod ConstructMethodFromInvocation(RefactoringOptions options) { var resolver = options.GetResolver(); var data = options.GetTextEditorData(); DomMethod result = new DomMethod(methodName, modifiers, MethodModifier.None, DomLocation.Empty, DomRegion.Empty, returnType); result.DeclaringType = new DomType("GeneratedType") { ClassType = declaringType.ClassType }; int i = 1; foreach (var curArg in invocation.Arguments) { var argument = curArg; DomParameter arg = new DomParameter(); if (argument is DirectionExpression) { var de = (DirectionExpression)argument; arg.ParameterModifiers = de.FieldDirection == FieldDirection.Out ? ParameterModifiers.Out : ParameterModifiers.Ref; argument = de.Expression; } string argExpression = data.GetTextBetween(argument.StartLocation.Line, argument.StartLocation.Column, argument.EndLocation.Line, argument.EndLocation.Column); var resolveResult = resolver.Resolve(new ExpressionResult(argExpression), resolvePosition); if (argument is MemberReferenceExpression) { arg.Name = ((MemberReferenceExpression)argument).MemberName; } else if (argument is IdentifierExpression) { arg.Name = ((IdentifierExpression)argument).Identifier; int idx = arg.Name.LastIndexOf('.'); if (idx >= 0) { arg.Name = arg.Name.Substring(idx + 1); } } else { arg.Name = "par" + i++; } arg.Name = char.ToLower(arg.Name[0]) + arg.Name.Substring(1); if (resolveResult != null && resolveResult.ResolvedType != null && !string.IsNullOrEmpty(resolveResult.ResolvedType.FullName)) { arg.ReturnType = resolveResult.ResolvedType; } else { arg.ReturnType = DomReturnType.Object; } result.Add(arg); } return(result); }
static DomParameter ConvertParameter (IMember declaringMember, ICSharpCode.NRefactory.Ast.ParameterDeclarationExpression pde) { DomParameter result = new DomParameter (); result.Name = pde.ParameterName; result.Location = ConvertLocation (pde.StartLocation); result.DeclaringMember = declaringMember; result.ReturnType = ConvertReturnType (pde.TypeReference); result.ParameterModifiers = ConvertParameterModifiers (pde.ParamModifier); return result; }
/// <summary> /// Create an IMember from a LanguageItem, /// using the source document to locate declaration bounds. /// </summary> /// <param name="pi"> /// A <see cref="ProjectInformation"/> for the current project. /// </param> /// <param name="item"> /// A <see cref="LanguageItem"/>: The item to convert. /// </param> /// <param name="contentLines"> /// A <see cref="System.String[]"/>: The document in which item is defined. /// </param> static IMember LanguageItemToIMember(ProjectInformation pi, LanguageItem item, string[] contentLines) { if (item is Class || item is Structure) { DomType klass = new DomType(new CompilationUnit(item.File), ClassType.Class, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new List <IMember> ()); foreach (LanguageItem li in pi.AllItems()) { if (klass.Equals(li.Parent) && FilePath.Equals(li.File, item.File)) { klass.Add(LanguageItemToIMember(pi, li, contentLines)); } } return(klass); } if (item is Enumeration) { return(new DomType(new CompilationUnit(item.File), ClassType.Enum, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, (int)item.Line + 1), new List <IMember> ())); } if (item is Function) { DomMethod method = new DomMethod(item.Name, Modifiers.None, MethodModifier.None, new DomLocation((int)item.Line, 1), new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new DomReturnType()); Function function = (Function)item; Match match; bool abort = false; List <IParameter> parameters = new List <IParameter> (); foreach (string parameter in function.Parameters) { match = paramExpression.Match(parameter); if (null == match) { abort = true; break; } DomParameter p = (new DomParameter(method, match.Groups["name"].Value, new DomReturnType(string.Format("{0}{1}{2}", match.Groups["type"].Value, match.Groups["subtype"].Value, match.Groups["array"].Value)))); parameters.Add(p); } if (!abort) { method.Add(parameters); } return(method); } if (item is Member) { return(new DomField(item.Name, Modifiers.None, new DomLocation((int)item.Line, 1), new DomReturnType())); } return(null); }
public static DomParameter ReadParameter(BinaryReader reader, INameDecoder nameTable) { DomParameter result = new DomParameter(); result.Name = ReadString(reader, nameTable); result.ParameterModifiers = (ParameterModifiers)reader.ReadUInt32(); result.ReturnType = ReadReturnType(reader, nameTable); result.Location = ReadLocation(reader, nameTable); if (reader.ReadBoolean()) { result.DefaultValue = ReadExpression(reader, nameTable); } return(result); }
IEnumerable <IMethod> BuildFunctions(IEnumerable <PythonFunction> functions) { if (functions == null) { yield break; } foreach (PythonFunction pyFunc in functions) { var domFunc = new DomMethod() { Name = pyFunc.Name, Documentation = pyFunc.Documentation, BodyRegion = pyFunc.Region, Location = new DomLocation(pyFunc.Region.Start.Line - 1, 0), ReturnType = new DomReturnType() { Name = pyFunc.Name, // FIXME: Get inferred type Namespace = Module.FullName, }, }; m_AllWrapped.Add(domFunc); foreach (PythonArgument pyArg in pyFunc.Arguments) { var domArg = new DomParameter() { Name = pyArg.Name, ReturnType = new DomReturnType() { Name = pyArg.Name, // FIXME: Get inferred type Namespace = Module.FullName, }, }; m_AllWrapped.Add(domArg); domFunc.Add(domArg); } yield return(domFunc); } }
static DomMethod GenerateMethodStub(RefactoringOptions options, ExtractMethodParameters param) { DomMethod result = new DomMethod(); result.Name = param.Name; result.ReturnType = param.ExpressionType ?? DomReturnType.Void; result.Modifiers = param.Modifiers; if (!param.ReferencesMember) { result.Modifiers |= Modifiers.Static; } if (param.Parameters == null) { return(result); } foreach (var p in param.Parameters) { if (param.OneChangedVariable && p.UsedAfterCutRegion && !p.UsedInCutRegion) { continue; } var newParameter = new DomParameter(); newParameter.Name = p.Name; newParameter.ReturnType = p.ReturnType; if (!param.OneChangedVariable) { if (!p.IsDefinedInsideCutRegion && p.IsChangedInsideCutRegion) { newParameter.ParameterModifiers = p.UsedBeforeCutRegion ? ParameterModifiers.Ref : ParameterModifiers.Out; } } result.Add(newParameter); } return(result); }
public void AddParameter (MonoDevelop.Projects.Dom.AbstractMember member, AParametersCollection parameters) { for (int i = 0; i < parameters.Count; i++) { var p = (Parameter)parameters.FixedParameters[i]; DomParameter parameter = new DomParameter (); parameter.Name = ConvertQuoted (p.Name); parameter.Location = Convert (p.Location); parameter.ReturnType = ConvertReturnType (p.TypeExpression); var modifiers = MonoDevelop.Projects.Dom.ParameterModifiers.None; if ((p.ParameterModifier & Parameter.Modifier.OUT) == Parameter.Modifier.OUT) modifiers |= MonoDevelop.Projects.Dom.ParameterModifiers.Out; if ((p.ParameterModifier & Parameter.Modifier.REF) == Parameter.Modifier.REF) modifiers |= MonoDevelop.Projects.Dom.ParameterModifiers.Ref; if ((p.ParameterModifier & Parameter.Modifier.PARAMS) == Parameter.Modifier.PARAMS) modifiers |= MonoDevelop.Projects.Dom.ParameterModifiers.Params; if ((p.ParameterModifier & Parameter.Modifier.This) == Parameter.Modifier.This) modifiers |= MonoDevelop.Projects.Dom.ParameterModifiers.This; parameter.ParameterModifiers = modifiers; member.Add (parameter); } }
IMethod ConstructMethodFromInvocation (RefactoringOptions options) { var resolver = options.GetResolver (); var data = options.GetTextEditorData (); DomMethod result = new DomMethod (methodName, modifiers, MethodModifier.None, DomLocation.Empty, DomRegion.Empty, returnType); result.DeclaringType = new DomType ("GeneratedType") { ClassType = declaringType.ClassType }; int i = 1; foreach (var curArg in invocation.Arguments) { var argument = curArg; DomParameter arg = new DomParameter (); if (argument is DirectionExpression) { var de = (DirectionExpression)argument; arg.ParameterModifiers = de.FieldDirection == FieldDirection.Out ? ParameterModifiers.Out : ParameterModifiers.Ref; argument = de.Expression; } string argExpression = data.GetTextBetween (argument.StartLocation.Line, argument.StartLocation.Column, argument.EndLocation.Line, argument.EndLocation.Column); var resolveResult = resolver.Resolve (new ExpressionResult (argExpression), resolvePosition); if (argument is MemberReferenceExpression) { arg.Name = ((MemberReferenceExpression)argument).Identifier.Name; } else if (argument is IdentifierExpression) { arg.Name = ((IdentifierExpression)argument).Identifier; int idx = arg.Name.LastIndexOf ('.'); if (idx >= 0) arg.Name = arg.Name.Substring (idx + 1); } else { arg.Name = "par" + i++; } arg.Name = char.ToLower (arg.Name[0]) + arg.Name.Substring (1); if (resolveResult != null) { arg.ReturnType = resolveResult.ResolvedType; } else { arg.ReturnType = DomReturnType.Object; } result.Add (arg); } return result; }
static DomMethod GenerateMethodStub (RefactoringOptions options, ExtractMethodParameters param) { DomMethod result = new DomMethod (); result.Name = param.Name; result.ReturnType = param.ExpressionType ?? DomReturnType.Void; result.Modifiers = param.Modifiers; if (!param.ReferencesMember) result.Modifiers |= MonoDevelop.Projects.Dom.Modifiers.Static; if (param.Parameters == null) return result; foreach (var p in param.Parameters) { if (param.OneChangedVariable && p.UsedAfterCutRegion && !p.UsedInCutRegion) continue; var newParameter = new DomParameter (); newParameter.Name = p.Name; newParameter.ReturnType = p.ReturnType; if (!param.OneChangedVariable) { if (!p.IsDefinedInsideCutRegion && p.IsChangedInsideCutRegion) { newParameter.ParameterModifiers = p.UsedBeforeCutRegion ? ParameterModifiers.Ref : ParameterModifiers.Out; } } result.Add (newParameter); } return result; }
IEnumerable<IMethod> BuildFunctions(IEnumerable<PythonFunction> functions) { if (functions == null) yield break; foreach (PythonFunction pyFunc in functions) { var domFunc = new DomMethod () { Name = pyFunc.Name, Documentation = pyFunc.Documentation, BodyRegion = pyFunc.Region, Location = new DomLocation (pyFunc.Region.Start.Line - 1, 0), ReturnType = new DomReturnType () { Name = pyFunc.Name, // FIXME: Get inferred type Namespace = Module.FullName, }, }; m_AllWrapped.Add (domFunc); foreach (PythonArgument pyArg in pyFunc.Arguments) { var domArg = new DomParameter () { Name = pyArg.Name, ReturnType = new DomReturnType () { Name = pyArg.Name, // FIXME: Get inferred type Namespace = Module.FullName, }, }; m_AllWrapped.Add (domArg); domFunc.Add (domArg); } yield return domFunc; } }
public static DomParameter ReadParameter (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable) { DomParameter result = new DomParameter (); result.Name = ReadString (reader, nameTable); result.ParameterModifiers = (ParameterModifiers)reader.ReadUInt32 (); result.ReturnType = ReadReturnType (reader, nameTable, objectTable); result.Location = ReadLocation (reader, nameTable); if(reader.ReadBoolean()) result.DefaultValue = ReadExpression (reader, nameTable); return result; }
//TODO: handle generics public static IMethod CodeDomToMDDomMethod (CodeMemberMethod method) { DomMethod meth = new DomMethod (); meth.Name = method.Name; meth.ReturnType = new DomReturnType (method.ReturnType.BaseType); meth.Modifiers = CodeDomModifiersToMDDom (method.Attributes); foreach (CodeParameterDeclarationExpression dec in method.Parameters) { DomParameter par = new DomParameter (meth, dec.Name, new DomReturnType (dec.Type.BaseType)); if (dec.Direction == FieldDirection.Ref) par.ParameterModifiers &= ParameterModifiers.Ref; else if (dec.Direction == FieldDirection.Out) par.ParameterModifiers &= ParameterModifiers.Out; else par.ParameterModifiers &= ParameterModifiers.In; meth.Add (par); } return meth; }