本文整理汇总了C#中AstNode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# AstNode.ToString方法的具体用法?C# AstNode.ToString怎么用?C# AstNode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstNode
的用法示例。
在下文中一共展示了AstNode.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginVisit
public void BeginVisit(AstNode node)
{
for (int i = 0; i < indentation; i++)
{
Console.Write ("\t");
}
Console.WriteLine (node.ToString ());
indentation++;
}
示例2: DisplayTree
public static void DisplayTree(AstNode node, int level)
{
for (int i = 0; i < level; i++)
Console.Write(" ");
Console.WriteLine(node.ToString());
foreach (AstNode child in node.ChildNodes)
DisplayTree(child, level + 1);
}
示例3: Replace
public static void Replace (this TextEditorData editor, AstNode n, AstNode replaceWith)
{
var change = editor.GetRemoveNodeChange (n);
editor.Replace (change.Offset, change.RemovedChars, replaceWith.ToString ());
}
示例4: GetPossibleNamespaces
static IEnumerable<PossibleNamespace> GetPossibleNamespaces (Document doc, AstNode node, ResolveResult resolveResult, DocumentLocation location)
{
var unit = doc.ParsedDocument.GetAst<SyntaxTree> ();
if (unit == null)
yield break;
var project = doc.Project;
if (project == null)
yield break;
int tc = GetTypeParameterCount (node);
var attribute = unit.GetNodeAt<ICSharpCode.NRefactory.CSharp.Attribute> (location);
bool isInsideAttributeType = attribute != null && attribute.Type.Contains (location);
var compilations = new List<Tuple<ICompilation, MonoDevelop.Projects.ProjectReference>> ();
compilations.Add (Tuple.Create (doc.Compilation, (MonoDevelop.Projects.ProjectReference)null));
var referencedItems = IdeApp.Workspace != null ? project.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionItem>) new SolutionItem[0];
var solution = project != null ? project.ParentSolution : null;
if (solution != null) {
foreach (var curProject in solution.GetAllProjects ()) {
if (curProject == project || referencedItems.Contains (curProject))
continue;
var otherRefes = IdeApp.Workspace != null ? curProject.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionItem>) new SolutionItem[0];
if (otherRefes.Contains (project))
continue;
var comp = TypeSystemService.GetCompilation (curProject);
if (comp == null)
continue;
compilations.Add (Tuple.Create (comp, new MonoDevelop.Projects.ProjectReference (curProject)));
}
}
var netProject = project as DotNetProject;
if (netProject == null)
yield break;
FrameworkLookup frameworkLookup;
if (!TypeSystemService.TryGetFrameworkLookup (netProject, out frameworkLookup))
frameworkLookup = null;
if (frameworkLookup != null && resolveResult is UnknownMemberResolveResult) {
var umResult = (UnknownMemberResolveResult)resolveResult;
try {
foreach (var r in frameworkLookup.GetExtensionMethodLookups (umResult)) {
var systemAssembly = netProject.AssemblyContext.GetAssemblyFromFullName (r.FullName, r.Package, netProject.TargetFramework);
if (systemAssembly == null)
continue;
if (CanBeReferenced (doc.Project, systemAssembly))
compilations.Add (Tuple.Create (TypeSystemService.GetCompilation (systemAssembly, doc.Compilation), new MonoDevelop.Projects.ProjectReference (systemAssembly)));
}
} catch (Exception e) {
if (!TypeSystemService.RecreateFrameworkLookup (netProject))
LoggingService.LogError (string.Format ("Error while looking up extension method {0}", umResult.MemberName), e);
}
}
bool foundIdentifier = false;
var lookup = new MemberLookup (null, doc.Compilation.MainAssembly);
foreach (var comp in compilations) {
var compilation = comp.Item1;
var requiredReference = comp.Item2;
if (resolveResult is AmbiguousTypeResolveResult) {
if (compilation != doc.Compilation)
continue;
var aResult = resolveResult as AmbiguousTypeResolveResult;
var file = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile;
var scope = file.GetUsingScope (location).Resolve (compilation);
while (scope != null) {
foreach (var u in scope.Usings) {
foreach (var typeDefinition in u.Types) {
if (typeDefinition.Name == aResult.Type.Name &&
typeDefinition.TypeParameterCount == tc &&
lookup.IsAccessible (typeDefinition, false)) {
yield return new PossibleNamespace (typeDefinition.Namespace, true, requiredReference);
}
}
}
scope = scope.Parent;
}
}
var allTypes = compilation == doc.Compilation ? compilation.GetAllTypeDefinitions () : compilation.MainAssembly.GetAllTypeDefinitions ();
if (resolveResult is UnknownIdentifierResolveResult) {
var uiResult = resolveResult as UnknownIdentifierResolveResult;
string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : uiResult.Identifier;
foreach (var typeDefinition in allTypes) {
if ((typeDefinition.Name == possibleAttributeName || typeDefinition.Name == uiResult.Identifier) && typeDefinition.TypeParameterCount == tc &&
lookup.IsAccessible (typeDefinition, false)) {
if (typeDefinition.DeclaringTypeDefinition != null) {
var builder = new TypeSystemAstBuilder (new CSharpResolver (doc.Compilation));
foundIdentifier = true;
yield return new PossibleNamespace (builder.ConvertType (typeDefinition.DeclaringTypeDefinition).ToString (), false, requiredReference);
} else {
foundIdentifier = true;
yield return new PossibleNamespace (typeDefinition.Namespace, true, requiredReference);
}
}
}
}
if (resolveResult is UnknownMemberResolveResult) {
var umResult = (UnknownMemberResolveResult)resolveResult;
string possibleAttributeName = isInsideAttributeType ? umResult.MemberName + "Attribute" : umResult.MemberName;
foreach (var typeDefinition in allTypes.Where (t => t.HasExtensionMethods)) {
//.........这里部分代码省略.........
示例5: 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.TextEditor.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;
if (insertLocation < 0 || insertLocation > content.Length)
insertLocation = content.Length;
content = content.Substring (0, insertLocation) + newType.ToString (FormattingOptions) + content.Substring (insertLocation);
var formatter = new MonoDevelop.CSharp.Formatting.CSharpFormatter ();
var policy = context.Project.Policies.Get<CSharpFormattingPolicy> ();
var textPolicy = context.Project.Policies.Get<TextStylePolicy> ();
content = formatter.FormatText (policy, textPolicy, MonoDevelop.CSharp.Formatting.CSharpFormatter.MimeType, content, 0, content.Length);
File.WriteAllText (correctFileName, content);
context.Project.AddFile (correctFileName);
IdeApp.ProjectOperations.Save (context.Project);
IdeApp.Workbench.OpenDocument (correctFileName);
}
示例6: 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.ToString ();
}
if (node is OperatorDeclaration)
return "operator";
if (node is EntityDeclaration)
return ((EntityDeclaration)node).Name;
if (node is FixedVariableInitializer) {
return ((FixedVariableInitializer)node).Name;
}
return ((VariableInitializer)node).Name;
}
示例7: GetKeywordTooltip
public TooltipInformation GetKeywordTooltip (AstNode node)
{
return GetKeywordTooltip (node.ToString (), node);
}
示例8: ResolveNode
public ResolveResult ResolveNode(AstNode node, ILog log)
{
var syntaxTree = node.GetParent<SyntaxTree>();
this.InitResolver(syntaxTree);
var result = this.resolver.Resolve(node);
if (result is MethodGroupResolveResult && node.Parent != null)
{
var methodGroupResolveResult = (MethodGroupResolveResult)result;
var parentResolveResult = this.ResolveNode(node.Parent, log);
var parentInvocation = parentResolveResult as InvocationResolveResult;
IParameterizedMember method = methodGroupResolveResult.Methods.LastOrDefault();
bool isInvocation = node.Parent is InvocationExpression && (((InvocationExpression)(node.Parent)).Target == node);
if (node is Expression)
{
var conversion = this.Resolver.GetConversion((Expression)node);
if (conversion != null && conversion.IsMethodGroupConversion)
{
return new MemberResolveResult(new TypeResolveResult(conversion.Method.DeclaringType), conversion.Method);
}
}
if (isInvocation && parentInvocation != null)
{
var or = methodGroupResolveResult.PerformOverloadResolution(this.compilation, parentInvocation.GetArgumentsForCall().ToArray());
if (or.FoundApplicableCandidate)
{
method = or.BestCandidate;
return new MemberResolveResult(new TypeResolveResult(method.DeclaringType), method);
}
}
if (parentInvocation != null && method == null)
{
var typeDef = methodGroupResolveResult.TargetType as DefaultResolvedTypeDefinition;
if (typeDef != null)
{
var methods = typeDef.Methods.Where(m => m.Name == methodGroupResolveResult.MethodName);
method = methods.FirstOrDefault();
}
}
if (method == null)
{
var extMethods = methodGroupResolveResult.GetEligibleExtensionMethods(false);
if (!extMethods.Any())
{
extMethods = methodGroupResolveResult.GetExtensionMethods();
}
if (!extMethods.Any() || !extMethods.First().Any())
{
throw new EmitterException(node, "Cannot find method defintion");
}
method = extMethods.First().First();
}
if (parentInvocation == null || method.FullName != parentInvocation.Member.FullName)
{
MemberResolveResult memberResolveResult = new MemberResolveResult(new TypeResolveResult(method.DeclaringType), method);
return memberResolveResult;
}
return parentResolveResult;
}
if ((result == null || result.IsError) && log != null)
{
if (result is CSharpInvocationResolveResult && ((CSharpInvocationResolveResult)result).OverloadResolutionErrors != OverloadResolutionErrors.None)
{
return result;
}
log.LogWarning(string.Format("Node resolving has failed {0}: {1}", node.StartLocation, node.ToString()));
}
return result;
}
示例9: renderPropertyDeclaration
PropertyRenderInformation renderPropertyDeclaration(AstNode node)
{
var propDecl = node as PropertyDeclaration;
if (propDecl == null) {
return new PropertyRenderInformation() {
anythingElse = new NameAndTypeRenderInformation() { name = chompedString(node.ToString()) },
};
}
var nameAndType = new NameAndTypeRenderInformation() {
name = chompedString(propDecl.Name),
type = chompedString(propDecl.ReturnType.ToString()),
};
var commands = new[] {
"ReactiveCommand",
"ReactiveAsyncCommand",
};
if (propDecl.Attributes.Any(x => x.ToString().StartsWith("[Once]") || commands.Contains(propDecl.ReturnType.ToString()))) {
return new PropertyRenderInformation() { onceProp = nameAndType, };
}
if (!propDecl.Setter.IsNull) {
return new PropertyRenderInformation() { readWriteProp = nameAndType, };
} else {
return new PropertyRenderInformation() { outputProp = nameAndType, };
}
}
示例10: 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.ToString () + "'");
return rr;
} finally {
resolveVisitor.cancellationToken = CancellationToken.None;
}
}
}
示例11: GetLookups
/// <summary>
/// Tries to get a type out of an unknow member resolve result. (In case of fully qualified names)
/// </summary>
/// <returns>The assemblies the type may be defined (if any).</returns>
/// <param name="resolveResult">The resolve result.</param>
/// <param name="typeParameterCount">Type parameter count.</param>
/// <param name="isInsideAttributeType">If set to <c>true</c> this resolve result may be inside an attribute.</param>
public IEnumerable<AssemblyLookup> GetLookups (UnknownMemberResolveResult resolveResult, AstNode node, int typeParameterCount, bool isInsideAttributeType)
{
string name = isInsideAttributeType ? resolveResult.MemberName + "Attribute" : resolveResult.MemberName;
var identifier = GetIdentifier (name, typeParameterCount);
foreach (var lookup in GetLookup (identifier, typeLookupTable, headerSize + assemblyListTable.Length * 4)) {
if (node.ToString ().StartsWith (lookup.Namespace, StringComparison.Ordinal))
yield return lookup;
}
}
示例12: GetNode
/// <summary>
/// Converts an AstNode to its AstNode extended equivalent.
/// </summary>
/// <param name="node">The node to convert.</param>
/// <returns>A node of the correct type.</returns>
public static object GetNode(AstNode node)
{
switch (node.ToString())
{
case "DefineImage":
return (DefineImageNode)node;
case "SetSharedProperties":
return (SetSharedPropsNode)node;
case "SetControlProperties":
return (SetControlPropsNode)node;
case "DefineString":
return (DefineStringNode)node;
case "AddText":
return (AddTextNode)node;
case "AddButton":
return (AddButtonNode)node;
case "AddTextEdit":
return (AddTextEditNode)node;
case "AddSlider":
return (AddSliderNode)node;
case "AddProgressBar":
return (AddProgressBarNode)node;
case "AddFormatedText":
return (AddFormatedTextNode)node;
default:
return node;
}
}
示例13: Resolve
MonoDevelop.Projects.Dom.ResolveResult Resolve (AstNode node)
{
MonoDevelop.Projects.Dom.ResolveResult result;
if (!resolveCache.TryGetValue (node, out result))
resolveCache [node] = result = Resolver.Resolve (node.ToString (), new MonoDevelop.Projects.Dom.DomLocation (Location.Line, Location.Column));
return result;
}
示例14: WalkTree
/// <summary>
/// Walks a generated AST (Abstract Syntax Tree) and creates the elements of this UIScreen.
/// </summary>
/// <param name="State">A ParserState instance.</param>
/// <param name="node">The root node of the AST.</param>
private void WalkTree(UIParser.ParserState State, AstNode node)
{
NodeType NType = (NodeType)Enum.Parse(typeof(NodeType), node.ToString(), true);
switch (NType)
{
case NodeType.DefineImage: //Defines an image and loads a texture for it.
DefineImageNode ImgNode = (DefineImageNode)UINode.GetNode(node);
UIImage Img = new UIImage(ImgNode, m_Screen);
Elements.Add(ImgNode.Name, Img);
break;
case NodeType.DefineString: //Defines a string with a name.
DefineStringNode StrNode = (DefineStringNode)UINode.GetNode(node);
Strings.Add(StrNode.Name, StringManager.StrTable(State.CurrentStringTable)[StrNode.StrIndex]);
break;
case NodeType.AddButton: //Defines a button.
AddButtonNode ButtonNode = (AddButtonNode)UINode.GetNode(node);
UIButton Btn = new UIButton(ButtonNode, State, m_Screen);
Elements.Add(ButtonNode.Name, Btn);
break;
case NodeType.AddText:
AddTextNode TextNode = (AddTextNode)UINode.GetNode(node);
UILabel Lbl = new UILabel(TextNode, State, m_Screen);
Elements.Add(TextNode.Name, Lbl);
break;
case NodeType.AddTextEdit:
AddTextEditNode TextEditNode = (AddTextEditNode)UINode.GetNode(node);
UITextEdit Txt = new UITextEdit(TextEditNode, State, m_Screen);
Elements.Add(TextEditNode.Name, Txt);
break;
case NodeType.AddSlider:
AddSliderNode SliderNode = (AddSliderNode)UINode.GetNode(node);
UISlider Slider = new UISlider(SliderNode, State, m_Screen);
Elements.Add(SliderNode.Name, Slider);
break;
case NodeType.SetSharedProperties: //Assigns a bunch of shared properties to declarations following the statement.
State.InSharedPropertiesGroup = true;
SetSharedPropsNode SharedPropsNode = (SetSharedPropsNode)UINode.GetNode(node);
if (SharedPropsNode.StringTable != null)
State.CurrentStringTable = (int)SharedPropsNode.StringTable;
if (SharedPropsNode.ControlPosition != null)
{
State.Position[0] = SharedPropsNode.ControlPosition.Numbers[0];
State.Position[1] = SharedPropsNode.ControlPosition.Numbers[1];
break;
}
if (SharedPropsNode.Color != null)
{
State.Color = new Color();
State.Color.R = (byte)SharedPropsNode.Color.Numbers[0];
State.Color.G = (byte)SharedPropsNode.Color.Numbers[1];
State.Color.B = (byte)SharedPropsNode.Color.Numbers[2];
}
if (SharedPropsNode.TextColor != null)
{
State.TextColor = new Color();
State.TextColor.R = (byte)SharedPropsNode.TextColor.Numbers[0];
State.TextColor.G = (byte)SharedPropsNode.TextColor.Numbers[1];
State.TextColor.B = (byte)SharedPropsNode.TextColor.Numbers[2];
}
if (SharedPropsNode.TextColorSelected != null)
{
State.TextColorSelected = new Color();
State.TextColorSelected.R = (byte)SharedPropsNode.TextColorSelected.Numbers[0];
State.TextColorSelected.G = (byte)SharedPropsNode.TextColorSelected.Numbers[1];
State.TextColorSelected.B = (byte)SharedPropsNode.TextColorSelected.Numbers[2];
}
if (SharedPropsNode.TextColorHighlighted != null)
{
State.TextColorHighlighted = new Color();
State.TextColorHighlighted.R = (byte)SharedPropsNode.TextColorHighlighted.Numbers[0];
State.TextColorHighlighted.G = (byte)SharedPropsNode.TextColorHighlighted.Numbers[1];
State.TextColorHighlighted.B = (byte)SharedPropsNode.TextColorHighlighted.Numbers[2];
}
if (SharedPropsNode.TextColorDisabled != null)
{
State.TextColorDisabled = new Color();
State.TextColorDisabled.R = (byte)SharedPropsNode.TextColorDisabled.Numbers[0];
State.TextColorDisabled.G = (byte)SharedPropsNode.TextColorDisabled.Numbers[1];
State.TextColorDisabled.B = (byte)SharedPropsNode.TextColorDisabled.Numbers[2];
}
if (SharedPropsNode.BackColor != null)
{
State.BackColor = new Color();
State.BackColor.R = (byte)SharedPropsNode.BackColor.Numbers[0];
State.BackColor.G = (byte)SharedPropsNode.BackColor.Numbers[1];
//.........这里部分代码省略.........
示例15: AddExpressionToUniqueList
private void AddExpressionToUniqueList(AstNode astNode)
{
if (!this.UniqueNodes.ContainsKey(astNode.ToString()))
this.UniqueNodes.Add(astNode.ToString(), new AstNodeCount(astNode));
else
{
this.UniqueNodes[astNode.ToString()].Count += 1;
this.UniqueNodes[astNode.ToString()].AstNodes.Add(astNode);
}
}