public string ConvertVariable(IVariable v) { TypeSystemAstBuilder astBuilder = CreateAstBuilder(); AstNode astNode = astBuilder.ConvertVariable(v); return(astNode.GetText().TrimEnd(';', '\r', '\n')); }
private static Phrase FindPhrase(AstNode node) { var text = node.GetText(); if (node.Role == Roles.Comment) return Phrase.Comment; if (node.Role == Roles.Type) { var type = (node as PrimitiveType); if (type != null) return (type.Keyword != null) ? Phrase.Keyword : Phrase.Type; // some keywords can be type like "var" which our parser does not recognise return text.IsKeyword() ? Phrase.Keyword : Phrase.Type; } if (node is PrimitiveExpression) { if (text.IsString()) return Phrase.String; } if (node is CSharpTokenNode) { if (text.IsKeyword()) return Phrase.Keyword; } return Phrase.Unknwon; }
public static string PrettyPrint(this AstNode code) { if (code == null) { return(string.Empty); } return(code.GetText(FormattingOptionsFactory.CreateSharpDevelop())); }
XmlElement MakeTreeNode(AstNode node, XmlDocument dom) { //string node_role = node.Role.ToString().Replace("?", "__quote__"); XmlElement element = dom.CreateElement(node.GetType().Name); element.SetAttribute("Role", node.Role.ToString()); element.SetAttribute("Text", node.GetText()); //t.Tag = node; foreach (AstNode child in node.Children) { element.AppendChild(MakeTreeNode(child, dom)); //t.AppendChild(MakeTreeNode(child, dom)); } return(element); }
string GetName(AstNode node) { if (tag is SyntaxTree) { var type = node as TypeDeclaration; if (type != null) { var sb = new StringBuilder(); sb.Append(type.Name); while (type.Parent is TypeDeclaration) { type = type.Parent as TypeDeclaration; sb.Insert(0, type.Name + "."); } return(sb.ToString()); } } if (node is Accessor) { if (node.Role == PropertyDeclaration.GetterRole) { return("get"); } if (node.Role == PropertyDeclaration.SetterRole) { return("set"); } if (node.Role == CustomEventDeclaration.AddAccessorRole) { return("add"); } if (node.Role == CustomEventDeclaration.RemoveAccessorRole) { return("remove"); } return(node.GetText()); } if (node is EntityDeclaration) { return(((EntityDeclaration)node).Name); } return(((VariableInitializer)node).Name); }
private static Phrase FindPhrase(AstNode node) { var text = node.GetText(); if (node.Role == Roles.Comment) { return(Phrase.Comment); } if (node.Role == Roles.Type) { var type = (node as PrimitiveType); if (type != null) { return((type.Keyword != null) ? Phrase.Keyword : Phrase.Type); } // some keywords can be type like "var" which our parser does not recognise return(text.IsKeyword() ? Phrase.Keyword : Phrase.Type); } if (node is PrimitiveExpression) { if (text.IsString()) { return(Phrase.String); } } if (node is CSharpTokenNode) { if (text.IsKeyword()) { return(Phrase.Keyword); } } return(Phrase.Unknwon); }
public override void CreateNewType(AstNode newType, NewTypeContext ntctx) { if (newType == null) { throw new System.ArgumentNullException("newType"); } var correctFileName = MoveTypeToFile.GetCorrectFileName(context, (EntityDeclaration)newType); var content = context.Document.Editor.Text; var types = new List <EntityDeclaration> (context.Unit.GetTypes()); types.Sort((x, y) => y.StartLocation.CompareTo(x.StartLocation)); foreach (var removeType in types) { var start = context.GetOffset(removeType.StartLocation); var end = context.GetOffset(removeType.EndLocation); content = content.Remove(start, end - start); } var insertLocation = types.Count > 0 ? context.GetOffset(types.Last().StartLocation) : -1; var formattingPolicy = this.document.GetFormattingPolicy(); if (insertLocation < 0 || insertLocation > content.Length) { insertLocation = content.Length; } content = content.Substring(0, insertLocation) + newType.GetText(formattingPolicy.CreateOptions()) + content.Substring(insertLocation); var formatter = new CSharpFormatter(); content = formatter.FormatText(formattingPolicy, null, CSharpFormatter.MimeType, content, 0, content.Length); File.WriteAllText(correctFileName, content); document.Project.AddFile(correctFileName); MonoDevelop.Ide.IdeApp.ProjectOperations.Save(document.Project); MonoDevelop.Ide.IdeApp.Workbench.OpenDocument(correctFileName); }
XmlElement MakeTreeNode(AstNode node, XmlDocument dom) { //string node_role = node.Role.ToString().Replace("?", "__quote__"); XmlElement element = dom.CreateElement(node.GetType().Name); var fd = node as FieldDeclaration; if (fd != null) { var anon = fd.Annotation <FieldDefinition>(); if (anon != null) { element.SetAttribute("Anon", anon.Name); } } element.SetAttribute("Role", node.Role.ToString()); element.SetAttribute("Text", node.GetText()); //t.Tag = node; foreach (AstNode child in node.Children) { element.AppendChild(MakeTreeNode(child, dom)); //t.AppendChild(MakeTreeNode(child, dom)); } return(element); }
string GetName (AstNode node) { if (tag is SyntaxTree) { var type = node as TypeDeclaration; if (type != null) { var sb = new StringBuilder (); sb.Append (type.Name); while (type.Parent is TypeDeclaration) { type = type.Parent as TypeDeclaration; sb.Insert (0, type.Name + "."); } return sb.ToString (); } } if (node is Accessor) { if (node.Role == PropertyDeclaration.GetterRole) return "get"; if (node.Role == PropertyDeclaration.SetterRole) return "set"; if (node.Role == CustomEventDeclaration.AddAccessorRole) return "add"; if (node.Role == CustomEventDeclaration.RemoveAccessorRole) return "remove"; return node.GetText (); } if (node is EntityDeclaration) return ((EntityDeclaration)node).Name; return ((VariableInitializer)node).Name; }
/// <summary> /// Resolves the specified node. /// </summary> public ResolveResult Resolve(AstNode node, CancellationToken cancellationToken = default(CancellationToken)) { if (node == null || node.IsNull || IsUnresolvableNode(node)) return ErrorResolveResult.UnknownError; lock (resolveVisitor) { InitResolver(); resolveVisitor.cancellationToken = cancellationToken; try { ResolveResult rr = resolveVisitor.GetResolveResult(node); if (rr == null) Debug.Fail (node.GetType () + " resolved to null.", node.StartLocation + ":'" + node.GetText () + "'"); return rr; } finally { resolveVisitor.cancellationToken = CancellationToken.None; } } }
public override void CreateNewType (AstNode newType, NewTypeContext ntctx) { if (newType == null) throw new System.ArgumentNullException ("newType"); var correctFileName = MoveTypeToFile.GetCorrectFileName (context, (EntityDeclaration)newType); var content = context.Document.Editor.Text; var types = new List<TypeDeclaration> (context.Unit.GetTypes ()); types.Sort ((x, y) => y.StartLocation.CompareTo (x.StartLocation)); foreach (var removeType in types) { var start = context.GetOffset (removeType.StartLocation); var end = context.GetOffset (removeType.EndLocation); content = content.Remove (start, end - start); } var insertLocation = types.Count > 0 ? context.GetOffset (types.Last ().StartLocation) : -1; var formattingPolicy = this.document.GetFormattingPolicy (); if (insertLocation < 0 || insertLocation > content.Length) insertLocation = content.Length; content = content.Substring (0, insertLocation) + newType.GetText (formattingPolicy.CreateOptions ()) + content.Substring (insertLocation); var formatter = new CSharpFormatter (); content = formatter.FormatText (formattingPolicy, null, CSharpFormatter.MimeType, content, 0, content.Length); File.WriteAllText (correctFileName, content); document.Project.AddFile (correctFileName); MonoDevelop.Ide.IdeApp.ProjectOperations.Save (document.Project); MonoDevelop.Ide.IdeApp.Workbench.OpenDocument (correctFileName); }
/// <summary> /// Resolves the specified node. /// </summary> public ResolveResult Resolve(AstNode node, CancellationToken cancellationToken = default(CancellationToken)) { if (node == null || node.IsNull || IsUnresolvableNode(node)) { return(ErrorResolveResult.UnknownError); } lock (resolveVisitor) { InitResolver(); resolveVisitor.cancellationToken = cancellationToken; try { ResolveResult rr = resolveVisitor.GetResolveResult(node); if (rr == null) { Debug.Fail(node.GetType() + " resolved to null.", node.StartLocation + ":'" + node.GetText() + "'"); } return(rr); } finally { resolveVisitor.cancellationToken = CancellationToken.None; } } }
static string ToCSharp(AstNode node) { return(node.GetText()); }
public void PrintInvocation(AstNode invocation) { Console.WriteLine("new_Line:" + invocation.GetRegion().Begin.Line + " Invocation: " + invocation.GetText().ToString()); }
public TooltipInformation GetKeywordTooltip (AstNode node) { return GetKeywordTooltip (node.GetText (), node); }
/// <summary> /// Resolves the specified node. /// </summary> public ResolveResult Resolve(AstNode node, CancellationToken cancellationToken = default(CancellationToken)) { if(node == null) return ErrorResolveResult.UnknownError; lock(resolve_visitor){ InitResolver(); resolve_visitor.cancellation_token = cancellationToken; try{ ResolveResult rr = resolve_visitor.GetResolveResult(node); if(rr == null){ Debug.Fail(string.Format("{0} resolved to null.{1}:'{2}'", node.GetType(), node.StartLocation, node.GetText())); } return rr; }finally{ resolve_visitor.cancellation_token = CancellationToken.None; } } }