internal static void SetModifiers(AstNode node, Modifiers newValue) { Modifiers oldValue = GetModifiers(node); AstNode insertionPos = node.GetChildrenByRole(AttributeRole).LastOrDefault(); foreach (Modifiers m in CSharpModifierToken.AllModifiers) { if ((m & newValue) != 0) { if ((m & oldValue) == 0) { // Modifier was added var newToken = new CSharpModifierToken(TextLocation.Empty, m); node.InsertChildAfter(insertionPos, newToken, ModifierRole); insertionPos = newToken; } else { // Modifier already exists insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m); } } else { if ((m & oldValue) != 0) { // Modifier was removed node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m).Remove(); } } } }
public override void WriteKeyword(Role role, string keyword) { TextLocation start = locationProvider.Location; CSharpTokenNode t = null; if (role is TokenRole) { t = new CSharpTokenNode(start, (TokenRole)role); } else if (role == EntityDeclaration.ModifierRole) { t = new CSharpModifierToken(start, CSharpModifierToken.GetModifierValue(keyword)); } else if (keyword == "this") { ThisReferenceExpression node = nodes.Peek().LastOrDefault() as ThisReferenceExpression; if (node != null) { node.Location = start; } } else if (keyword == "base") { BaseReferenceExpression node = nodes.Peek().LastOrDefault() as BaseReferenceExpression; if (node != null) { node.Location = start; } } if (t != null) { currentList.Add(t); } base.WriteKeyword(role, keyword); }
void PrintModifiers(Modifiers modifiers, TokenWriter writer) { foreach (var m in CSharpModifierToken.AllModifiers) { if ((modifiers & m) == m) { writer.WriteKeyword(EntityDeclaration.ModifierRole, CSharpModifierToken.GetModifierName(m)); writer.Space(); } } }
void PrintModifiers(Modifiers modifiers, StringWriter writer) { foreach (var m in CSharpModifierToken.AllModifiers) { if ((modifiers & m) == m) { writer.Write(CSharpModifierToken.GetModifierName(m)); writer.Write(' '); } } }
void PrintModifiers(Modifiers modifiers, IOutputFormatter formatter) { foreach (var m in CSharpModifierToken.AllModifiers) { if ((modifiers & m) == m) { formatter.WriteKeyword(CSharpModifierToken.GetModifierName(m)); formatter.Space(); } } }
public override void WriteKeyword(Role role, string keyword) { TextLocation start = locationProvider.Location; CSharpTokenNode t = null; if (role is TokenRole) t = new CSharpTokenNode(start, (TokenRole)role); else if (role == EntityDeclaration.ModifierRole) t = new CSharpModifierToken(start, CSharpModifierToken.GetModifierValue(keyword)); else if (keyword == "this") { ThisReferenceExpression node = nodes.Peek().LastOrDefault() as ThisReferenceExpression; if (node != null) node.Location = start; } else if (keyword == "base") { BaseReferenceExpression node = nodes.Peek().LastOrDefault() as BaseReferenceExpression; if (node != null) node.Location = start; } if (t != null) currentList.Add(t); base.WriteKeyword(role, keyword); }
internal static void SetModifiers(AstNode node, Modifiers newValue) { Modifiers oldValue = GetModifiers(node); AstNode insertionPos = node.GetChildrenByRole(AttributeRole).LastOrDefault(); foreach (Modifiers m in CSharpModifierToken.AllModifiers) { if ((m & newValue) != 0) { if ((m & oldValue) == 0) { // Modifier was added var newToken = new CSharpModifierToken(AstLocation.Empty, m); node.InsertChildAfter(insertionPos, newToken, ModifierRole); insertionPos = newToken; } else { // Modifier already exists insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m); } } else { if ((m & oldValue) != 0) { // Modifier was removed node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove(); } } } }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { CSharpModifierToken o = other as CSharpModifierToken; return(o != null && this.modifier == o.modifier); }