本文整理汇总了C#中AstNode.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# AstNode.GetText方法的具体用法?C# AstNode.GetText怎么用?C# AstNode.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstNode
的用法示例。
在下文中一共展示了AstNode.GetText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPhrase
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;
}
示例2: GetName
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;
}
示例3: Resolve
/// <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;
}
}
}
示例4: CreateNewType
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);
}
示例5: GetKeywordTooltip
public TooltipInformation GetKeywordTooltip (AstNode node)
{
return GetKeywordTooltip (node.GetText (), node);
}
示例6: Resolve
/// <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;
}
}
}