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); }
public void ThisTokenPosition() { IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember <IndexerDeclaration>("public int this[int a] { get { } protected set { } }"); CSharpTokenNode thisKeyword = id.GetChildByRole(IndexerDeclaration.ThisKeywordRole); Assert.AreEqual(12, thisKeyword.StartLocation.Column); }
public override object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) { CSharpTokenNode lParen = (CSharpTokenNode)destructorDeclaration.GetChildByRole(DestructorDeclaration.Roles.LPar); int offset = this.data.Document.LocationToOffset(lParen.StartLocation.Line, lParen.StartLocation.Column); ForceSpaceBefore(offset, policy.BeforeConstructorDeclarationParentheses); return(base.VisitDestructorDeclaration(destructorDeclaration, data)); }
public override void WriteToken(Role role, string token) { CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role); EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement; if (node == null) currentList.Add(t); else { node.Location = locationProvider.Location; } base.WriteToken(role, token); }
public override void VisitCSharpTokenNode(CSharpTokenNode token) { if (_currentNamespaces.Count != 0 && token == _currentNamespaces.Peek().Item2) { _currentNamespaces.Pop(); } else if (_currentMembers.Count != 0 && token == _currentMembers.Peek().Item3) { _currentMembers.Pop(); } base.VisitCSharpTokenNode(token); }
public override void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { CSharpModifierToken mod = cSharpTokenNode as CSharpModifierToken; if (mod != null) { StartNode(mod); WriteKeyword(CPlusPlusCLIModifierToken.GetModifierName(mod.Modifier)); EndNode(mod); } else { throw new NotSupportedException("Should never visit individual tokens"); } }
public override void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { CSharpModifierToken mod = cSharpTokenNode as CSharpModifierToken; if (mod != null) { // In context of FieldDefinition, the modifier is outputted using "<type> :" (type followed by colon). StartNode(mod); WriteKeyword(CPlusPlusCLIFieldModifierToken.GetModifierName(mod.Modifier)); EndNode(mod); } else { throw new NotSupportedException("Should never visit individual tokens"); } }
public override void WriteToken(Role role, string token) { CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role); t.Role = role; EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement; if (node == null) { currentList.Add(t); } else { node.Location = locationProvider.Location; } base.WriteToken(role, token); }
public void FixSemicolon(CSharpTokenNode semicolon) { if (semicolon.IsNull) { return; } int endOffset = data.Document.LocationToOffset(semicolon.StartLocation.Line, semicolon.StartLocation.Column); int offset = endOffset; while (offset - 1 > 0 && char.IsWhiteSpace(data.Document.GetCharAt(offset - 1))) { offset--; } if (offset < endOffset) { AddChange(offset, endOffset - offset, null); } }
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); }
public override void WriteToken(Role role, string token) { switch (nodes.Peek().LastOrDefault()) { case EmptyStatement emptyStatement: emptyStatement.Location = locationProvider.Location; break; case ErrorExpression errorExpression: errorExpression.Location = locationProvider.Location; break; default: CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role); t.Role = role; currentList.Add(t); break; } base.WriteToken(role, token); }
public override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) { foreach (INode node in fieldDeclaration.Children) { if (node is VariableInitializer && node.NextSibling != null && node.NextSibling.Role == FieldDeclaration.Roles.Comma) { VariableInitializer initializer = node as VariableInitializer; CSharpTokenNode commaToken = (CSharpTokenNode)node.NextSibling; int offset = this.data.Document.LocationToOffset(initializer.NameIdentifier.StartLocation.Line, initializer.NameIdentifier.StartLocation.Column); int commaOffset = this.data.Document.LocationToOffset(commaToken.StartLocation.Line, commaToken.StartLocation.Column); ForceSpace(offset, commaOffset, policy.SpacesAfterComma); //Console.WriteLine (initializer.Name +"/" + initializer.NameIdentifier + "/" + commaToken); if (node.NextSibling.NextSibling is VariableInitializer) { DomLocation location = ((VariableInitializer)node.NextSibling.NextSibling).NameIdentifier.StartLocation; int nextOffset = this.data.Document.LocationToOffset(location.Line, location.Column); ForceSpace(commaOffset, nextOffset, policy.SpacesAfterComma); } } } return(base.VisitFieldDeclaration(fieldDeclaration, data)); }
public override void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { throw NotSupportedToConsistency(); }
private void AddIssue (CSharpTokenNode operatorToken) { AddIssue (operatorToken, ctx.TranslateString ("Bitwise Operations on enum not marked with Flags attribute")); }
public void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { tokennodeCounter++; if (tokennodeCounter == 26) { } CSharpModifierToken mod = cSharpTokenNode as CSharpModifierToken; if (mod != null) { JsonElement element = new JsonElement(); element.SetValue(CSharpModifierToken.GetModifierName(mod.Modifier)); Push(element); } else { throw new NotSupportedException("Should never visit individual tokens"); } }
public void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { CSharpModifierToken mod = cSharpTokenNode as CSharpModifierToken; if (mod != null) { StartNode(mod); WriteKeyword(CSharpModifierToken.GetModifierName(mod.Modifier)); EndNode(mod); } else { throw new NotSupportedException ("Should never visit individual tokens"); } }
static bool ShouldBreakLine(NewLinePlacement placement, CSharpTokenNode token) { if (placement == NewLinePlacement.NewLine) return true; if (placement == NewLinePlacement.SameLine) return false; var prevMeaningfulNode = token.GetPrevNode (n =>n.Role !=Roles.NewLine && n.Role != Roles.Whitespace && n.Role !=Roles.Comment); return prevMeaningfulNode.EndLocation.Line != token.StartLocation.Line; }
public void VisitCSharpTokenNode(CSharpTokenNode node) { }
public override void VisitCSharpTokenNode(CSharpTokenNode token) { // Nothing }
public virtual Node VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { throw new System.NotImplementedException(); }
/// <inheritdoc/> public virtual void VisitCSharpTokenNode(CSharpTokenNode syntax) { VisitNode(syntax); }
public UnifiedElement VisitCSharpTokenNode( CSharpTokenNode tokenNode, object data) { throw new NotImplementedException("CSharpTokenNode"); }
public RedILNode VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, State data) { throw new System.NotImplementedException(); }
public abstract StringBuilder VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, int data);
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { CSharpTokenNode o = other as CSharpTokenNode; return(o != null && !o.IsNull && !(o is CSharpModifierToken)); }
void FixEmbeddedStatment(BraceStyle braceStyle, CSharpTokenNode token, bool allowInLine, AstNode node, bool statementAlreadyIndented = false) { if (node == null) return; bool isBlock = node is BlockStatement; FormattingChanges.TextReplaceAction beginBraceAction = null; FormattingChanges.TextReplaceAction endBraceAction = null; BlockStatement closeBlockToBeFixed = null; if (isBlock) { BlockStatement block = node as BlockStatement; if (allowInLine && block.StartLocation.Line == block.EndLocation.Line && block.Statements.Count() <= 1) { if (block.Statements.Count() == 1) nextStatementIndent = " "; } else { if (!statementAlreadyIndented) FixOpenBrace(braceStyle, block.LBraceToken); closeBlockToBeFixed = block; } if (braceStyle == BraceStyle.NextLineShifted2) curIndent.Push(IndentType.Block); } else { if (allowInLine && token.StartLocation.Line == node.EndLocation.Line) { nextStatementIndent = " "; } } bool pushed = false; if (policy.IndentBlocks && !(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement)) { curIndent.Push(IndentType.Block); pushed = true; } if (isBlock) { VisitBlockWithoutFixingBraces((BlockStatement)node, false); } else { if (!statementAlreadyIndented) FixStatementIndentation(node.StartLocation); node.AcceptVisitor(this); } if (pushed) curIndent.Pop(); if (beginBraceAction != null && endBraceAction != null) { beginBraceAction.DependsOn = endBraceAction; endBraceAction.DependsOn = beginBraceAction; } if (isBlock && braceStyle == BraceStyle.NextLineShifted2) curIndent.Pop(); if (closeBlockToBeFixed != null) { FixClosingBrace(braceStyle, closeBlockToBeFixed.RBraceToken); } }
public Node VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { return(CreateDummy(cSharpTokenNode, $"token: {cSharpTokenNode}")); }
public virtual void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { //throw this.CreateException(cSharpTokenNode); }
public override void VisitCSharpTokenNode(CSharpTokenNode syntax) { _underlyingVisitor.VisitCSharpTokenNode(syntax); }
public override StringBuilder VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, int data) { throw new NotImplementedException(); }
void FixEmbeddedStatment(BraceStyle braceStyle, BraceForcement braceForcement, CSharpTokenNode token, bool allowInLine, AstNode node, bool statementAlreadyIndented = false) { if (node == null) { return; } bool isBlock = node is BlockStatement; TextReplaceAction beginBraceAction = null; TextReplaceAction endBraceAction = null; switch (braceForcement) { case BraceForcement.DoNotChange: //nothing break; case BraceForcement.AddBraces: if (!isBlock) { AstNode n = node.Parent.GetCSharpNodeBefore(node); int start = document.GetOffset(n.EndLocation); string startBrace = ""; switch (braceStyle) { case BraceStyle.EndOfLineWithoutSpace: startBrace = "{"; break; case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: startBrace = " {"; break; case BraceStyle.NextLine: startBrace = this.options.EolMarker + curIndent.IndentString + "{"; break; case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: curIndent.Push(IndentType.Block); startBrace = this.options.EolMarker + curIndent.IndentString + "{"; curIndent.Pop(); break; } beginBraceAction = AddChange(start, 0, startBrace); } break; case BraceForcement.RemoveBraces: if (isBlock) { BlockStatement block = node as BlockStatement; if (block.Statements.Count() == 1) { int offset1 = document.GetOffset(node.StartLocation); int start = SearchWhitespaceStart(offset1); int offset2 = document.GetOffset(node.EndLocation); int end = SearchWhitespaceStart(offset2 - 1); beginBraceAction = AddChange(start, offset1 - start + 1, null); endBraceAction = AddChange(end + 1, offset2 - end, null); node = block.FirstChild; isBlock = false; } } break; } if (isBlock) { BlockStatement block = node as BlockStatement; if (allowInLine && block.StartLocation.Line == block.EndLocation.Line && block.Statements.Count() <= 1) { if (block.Statements.Count() == 1) { nextStatementIndent = " "; } } else { if (!statementAlreadyIndented) { EnforceBraceStyle(braceStyle, block.LBraceToken, block.RBraceToken); } } if (braceStyle == BraceStyle.NextLineShifted2) { curIndent.Push(IndentType.Block); } } else { if (allowInLine && token.StartLocation.Line == node.EndLocation.Line) { nextStatementIndent = " "; } } if (policy.IndentBlocks && !(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement)) { curIndent.Push(IndentType.Block); } if (isBlock) { VisitBlockWithoutFixingBraces((BlockStatement)node, false); } else { if (!statementAlreadyIndented) { FixStatementIndentation(node.StartLocation); } node.AcceptVisitor(this); } if (policy.IndentBlocks && !(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement)) { curIndent.Pop(); } switch (braceForcement) { case BraceForcement.DoNotChange: break; case BraceForcement.AddBraces: if (!isBlock) { int offset = document.GetOffset(node.EndLocation); if (!char.IsWhiteSpace(document.GetCharAt(offset))) { offset++; } string startBrace = ""; switch (braceStyle) { case BraceStyle.DoNotChange: startBrace = null; break; case BraceStyle.EndOfLineWithoutSpace: startBrace = this.options.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.EndOfLine: startBrace = this.options.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.NextLine: startBrace = this.options.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.BannerStyle: case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: curIndent.Push(IndentType.Block); startBrace = this.options.EolMarker + curIndent.IndentString + "}"; curIndent.Pop (); break; } if (startBrace != null) { endBraceAction = AddChange(offset, 0, startBrace); } } break; } if (beginBraceAction != null && endBraceAction != null) { beginBraceAction.DependsOn = endBraceAction; endBraceAction.DependsOn = beginBraceAction; } }
// public override void Visit (UsingsBag.Namespace nspace) // { // // // VisitNamespaceUsings (nspace); // VisitNamespaceBody (nspace); // // } // void ConvertNamespaceName(MemberName memberName, NamespaceDeclaration namespaceDecl) { AstNode insertPos = null; while (memberName != null) { Identifier newIdent = Identifier.Create (memberName.Name, Convert (memberName.Location)); // HACK for a parser 'bug' - sometimes it generates "<invalid>" identifiers in namespace names (on certain bugs in the input file) if (newIdent.Name != "<invalid>") { namespaceDecl.InsertChildBefore (insertPos, newIdent, Roles.Identifier); insertPos = newIdent; if (!memberName.DotLocation.IsNull) { var dotToken = new CSharpTokenNode (Convert (memberName.DotLocation), Roles.Dot); namespaceDecl.InsertChildBefore (insertPos, dotToken, Roles.Dot); insertPos = dotToken; } } memberName = memberName.Left; } }
object FixEmbeddedStatment(MonoDevelop.CSharp.Formatting.BraceStyle braceStyle, MonoDevelop.CSharp.Formatting.BraceForcement braceForcement, CSharpTokenNode token, bool allowInLine, ICSharpNode node) { if (node == null) { return(null); } bool isBlock = node is BlockStatement; switch (braceForcement) { case BraceForcement.DoNotChange: //nothing break; case BraceForcement.AddBraces: if (!isBlock) { int offset = data.Document.LocationToOffset(node.StartLocation.Line, node.StartLocation.Column); int start = SearchWhitespaceStart(offset); string startBrace = ""; switch (braceStyle) { case BraceStyle.EndOfLineWithoutSpace: startBrace = "{"; break; case BraceStyle.EndOfLine: startBrace = " {"; break; case BraceStyle.NextLine: startBrace = data.EolMarker + curIndent.IndentString + "{"; break; case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: startBrace = data.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "{"; break; } AddChange(start, offset - start, startBrace); } break; case BraceForcement.RemoveBraces: if (isBlock) { BlockStatement block = node as BlockStatement; if (block.Statements.Count() == 1) { int offset1 = data.Document.LocationToOffset(node.StartLocation.Line, node.StartLocation.Column); int start = SearchWhitespaceStart(offset1); int offset2 = data.Document.LocationToOffset(node.EndLocation.Line, node.EndLocation.Column); int end = SearchWhitespaceStart(offset2 - 1); AddChange(start, offset1 - start + 1, null); AddChange(end + 1, offset2 - end, null); node = (ICSharpNode)block.FirstChild; isBlock = false; } } break; } int originalLevel = curIndent.Level; if (isBlock) { BlockStatement block = node as BlockStatement; if (allowInLine && block.StartLocation.Line == block.EndLocation.Line && block.Statements.Count() <= 1) { if (block.Statements.Count() == 1) { nextStatementIndent = " "; } } else { EnforceBraceStyle(braceStyle, block.LBrace, block.RBrace); } if (braceStyle == BraceStyle.NextLineShifted2) { curIndent.Level++; } } else { if (allowInLine && token.StartLocation.Line == node.EndLocation.Line) { nextStatementIndent = " "; } } if (!(node is IfElseStatement && node.Parent is IfElseStatement || node is UsingStatement && node.Parent is UsingStatement)) { curIndent.Level++; } object result = isBlock ? base.VisitBlockStatement((BlockStatement)node, null) : node.AcceptVisitor(this, null); curIndent.Level = originalLevel; switch (braceForcement) { case BraceForcement.DoNotChange: break; case BraceForcement.AddBraces: if (!isBlock) { int offset = data.Document.LocationToOffset(node.EndLocation.Line, node.EndLocation.Column); string startBrace = ""; switch (braceStyle) { case BraceStyle.DoNotChange: startBrace = null; break; case BraceStyle.EndOfLineWithoutSpace: startBrace = data.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.EndOfLine: startBrace = data.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.NextLine: startBrace = data.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: startBrace = data.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "}"; break; } if (startBrace != null) { AddChange(offset, 0, startBrace); } } break; } return(result); }
public void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { CSharpModifierToken mod = cSharpTokenNode as CSharpModifierToken; if (mod != null) { // ITokenWriter assumes that each node processed between a // StartNode(parentNode)-EndNode(parentNode)-pair is a child of parentNode. WriteKeyword(CSharpModifierToken.GetModifierName(mod.Modifier), cSharpTokenNode.Role); } else { throw new NotSupportedException ("Should never visit individual tokens"); } }
public void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { throw new NotImplementedException(); }
void ConvertNamespaceName (MemberName memberName, NamespaceDeclaration namespaceDecl) { AstNode insertPos = null; while (memberName != null) { Identifier newIdent = Identifier.Create (memberName.Name, Convert (memberName.Location)); namespaceDecl.InsertChildBefore (insertPos, newIdent, NamespaceDeclaration.Roles.Identifier); insertPos = newIdent; if (!memberName.DotLocation.IsNull) { var dotToken = new CSharpTokenNode (Convert (memberName.DotLocation), 1); namespaceDecl.InsertChildBefore (insertPos, dotToken, NamespaceDeclaration.Roles.Dot); insertPos = dotToken; } memberName = memberName.Left; } }
public void FixSemicolon(CSharpTokenNode semicolon) { if (semicolon.IsNull) { return; } int endOffset = document.GetOffset(semicolon.StartLocation); int offset = endOffset; while (offset - 1 > 0 && char.IsWhiteSpace (document.GetCharAt (offset - 1))) { offset--; } if (offset < endOffset) { AddChange(offset, endOffset - offset, null); } }
public StringBuilder VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode) { throw new NotImplementedException(); }
public virtual void VisitCSharpTokenNode (CSharpTokenNode token) { VisitChildren (token); }
public JNode VisitCSharpTokenNode(CSharpTokenNode node) { throw new NotImplementedException(); }
private void AddIssue(CSharpTokenNode operatorToken) { AddIssue(operatorToken, ctx.TranslateString("Bitwise Operations on enum not marked with Flags attribute")); }