public void InsertComment (DomNode node, MonoDevelop.CSharp.Dom.Comment comment) { if (node.EndLocation < comment.StartLocation) { node.AddChild (comment); return; } foreach (var child in node.Children) { if (child.StartLocation < comment.StartLocation && comment.StartLocation < child.EndLocation) { InsertComment (child, comment); return; } if (comment.StartLocation < child.StartLocation) { node.InsertChildBefore (child, comment, DomNode.Roles.Comment); return; } } node.AddChild (comment); }
void AddModifiers (DomNode parent, LocationsBag.MemberLocations location) { if (location == null || location.Modifiers == null) return; foreach (var modifier in location.Modifiers) { parent.AddChild (new CSharpModifierToken (Convert (modifier.Item2), modifierTable[modifier.Item1]), DomNode.Roles.Modifier); } }
void AddArguments (DomNode parent, object location, Mono.CSharp.Arguments args) { if (args == null) return; var commaLocations = LocationsBag.GetLocations (args); for (int i = 0; i < args.Count; i++) { Argument arg = args[i]; if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) { DirectionExpression direction = new DirectionExpression (); direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref; var argLocation = LocationsBag.GetLocations (arg); if (location != null) direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword); direction.AddChild ((DomNode)arg.Expr.Accept (this), InvocationExpression.Roles.Expression); parent.AddChild (direction, InvocationExpression.Roles.Parameter); } else { parent.AddChild ((DomNode)arg.Expr.Accept (this), InvocationExpression.Roles.Parameter); } if (commaLocations != null && i > 0) { int idx = commaLocations.Count - i; if (idx >= 0) parent.AddChild (new CSharpTokenNode (Convert (commaLocations[idx]), 1), InvocationExpression.Roles.Comma); } } if (commaLocations != null && commaLocations.Count > args.Count) parent.AddChild (new CSharpTokenNode (Convert (commaLocations[0]), 1), InvocationExpression.Roles.Comma); }
void AddConstraints (DomNode parent, DeclSpace d) { if (d == null || d.Constraints == null) return; for (int i = 0; i < d.Constraints.Count; i++) { Constraints c = d.Constraints[i]; var location = LocationsBag.GetLocations (c); // var constraint = new Constraint (); parent.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword); parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier); parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), InvocationExpression.Roles.Colon); foreach (var expr in c.ConstraintExpressions) parent.AddChild ((DomNode)expr.Accept (this), InvocationExpression.Roles.TypeParameter); } }
void AddTypeArguments (DomNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments) { if (typeArguments == null || typeArguments.IsEmpty) return; for (int i = 0; i < typeArguments.Count; i++) { if (location != null && i > 0 && i - 1 < location.Count) parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma); var arg = typeArguments.Args[i]; if (arg == null) continue; parent.AddChild ((DomNode)arg.Accept (this), InvocationExpression.Roles.TypeParameter); } }
void AddParameter (DomNode parent, Mono.CSharp.AParametersCollection parameters) { if (parameters == null) return; var paramLocation = LocationsBag.GetLocations (parameters); for (int i = 0; i < parameters.Count; i++) { if (paramLocation != null && i > 0 && i - 1 < paramLocation.Count) parent.AddChild (new CSharpTokenNode (Convert (paramLocation[i - 1]), 1), ParameterDeclaration.Roles.Comma); var p = (Parameter)parameters.FixedParameters[i]; var location = LocationsBag.GetLocations (p); ParameterDeclaration parameterDeclarationExpression = new ParameterDeclaration (); switch (p.ModFlags) { case Parameter.Modifier.OUT: parameterDeclarationExpression.ParameterModifier = ParameterModifier.Out; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "out".Length), ParameterDeclaration.Roles.Keyword); break; case Parameter.Modifier.REF: parameterDeclarationExpression.ParameterModifier = ParameterModifier.Ref; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "ref".Length), ParameterDeclaration.Roles.Keyword); break; case Parameter.Modifier.PARAMS: parameterDeclarationExpression.ParameterModifier = ParameterModifier.Params; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "params".Length), ParameterDeclaration.Roles.Keyword); break; case Parameter.Modifier.This: parameterDeclarationExpression.ParameterModifier = ParameterModifier.This; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "this".Length), ParameterDeclaration.Roles.Keyword); break; } if (p.TypeExpression != null) // lambdas may have no types (a, b) => ... parameterDeclarationExpression.AddChild ((DomNode)p.TypeExpression.Accept (this), ParameterDeclaration.Roles.ReturnType); parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclaration.Roles.Identifier); if (p.HasDefaultValue) { if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ParameterDeclaration.Roles.Assign); parameterDeclarationExpression.AddChild ((DomNode)p.DefaultValue.Accept (this), ParameterDeclaration.Roles.Expression); } parent.AddChild (parameterDeclarationExpression, InvocationExpression.Roles.Parameter); } }
void AddTypeArguments (DomNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments) { if (typeArguments == null) return; for (int i = 0; i < typeArguments.Count; i++) { if (location != null && i > 0 && i - 1 < location.Count) parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma); parent.AddChild ((DomNode)typeArguments.Args[i].Accept (this), InvocationExpression.Roles.TypeParameter); } }