本文整理汇总了C#中AstNode.GetPrevNode方法的典型用法代码示例。如果您正苦于以下问题:C# AstNode.GetPrevNode方法的具体用法?C# AstNode.GetPrevNode怎么用?C# AstNode.GetPrevNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstNode
的用法示例。
在下文中一共展示了AstNode.GetPrevNode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEndOfPrev
TextLocation GetEndOfPrev(AstNode node)
{
do {
node = node.GetPrevNode();
} while (node.NodeType == NodeType.Whitespace);
return node.EndLocation;
}
示例2: PlaceOnNewLine
void PlaceOnNewLine(NewLinePlacement newLine, AstNode keywordNode)
{
if (keywordNode == null || newLine == NewLinePlacement.DoNotCare) {
return;
}
var prev = keywordNode.GetPrevNode (NoWhitespacePredicate);
if (prev is Comment || prev is PreProcessorDirective)
return;
int offset = document.GetOffset(keywordNode.StartLocation);
int whitespaceStart = SearchWhitespaceStart(offset);
string indentString = newLine == NewLinePlacement.NewLine ? options.EolMarker + curIndent.IndentString : " ";
AddChange(whitespaceStart, offset - whitespaceStart, indentString);
}
示例3: FixOpenBrace
void FixOpenBrace(BraceStyle braceStyle, AstNode lbrace)
{
if (lbrace.IsNull)
return;
switch (braceStyle) {
case BraceStyle.DoNotChange:
return;
case BraceStyle.BannerStyle:
case BraceStyle.EndOfLine:
var prev = lbrace.GetPrevNode (NoWhitespacePredicate);
if (prev is PreProcessorDirective)
return;
int prevOffset = document.GetOffset(prev.EndLocation);
if (prev is Comment || prev is PreProcessorDirective) {
int next = document.GetOffset(lbrace.GetNextNode ().StartLocation);
AddChange(prevOffset, next - prevOffset, "");
while (prev is Comment || prev is PreProcessorDirective)
prev = prev.GetPrevNode();
prevOffset = document.GetOffset(prev.EndLocation);
AddChange(prevOffset, 0, " {");
} else {
int braceOffset2 = document.GetOffset(lbrace.StartLocation);
AddChange(prevOffset, braceOffset2 - prevOffset, " ");
}
break;
case BraceStyle.EndOfLineWithoutSpace:
prev = lbrace.GetPrevNode (NoWhitespacePredicate);
if (prev is PreProcessorDirective)
return;
prevOffset = document.GetOffset(prev.EndLocation);
int braceOffset = document.GetOffset(lbrace.StartLocation);
AddChange(prevOffset, braceOffset - prevOffset, "");
break;
case BraceStyle.NextLine:
prev = lbrace.GetPrevNode (NoWhitespacePredicate);
if (prev is PreProcessorDirective)
return;
prevOffset = document.GetOffset(prev.EndLocation);
braceOffset = document.GetOffset(lbrace.StartLocation);
AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString);
break;
case BraceStyle.NextLineShifted:
prev = lbrace.GetPrevNode (NoWhitespacePredicate);
if (prev is PreProcessorDirective)
return;
prevOffset = document.GetOffset(prev.EndLocation);
braceOffset = document.GetOffset(lbrace.StartLocation);
curIndent.Push(IndentType.Block);
AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString);
curIndent.Pop();
break;
case BraceStyle.NextLineShifted2:
prev = lbrace.GetPrevNode (NoWhitespacePredicate);
if (prev is PreProcessorDirective)
return;
prevOffset = document.GetOffset(prev.EndLocation);
braceOffset = document.GetOffset(lbrace.StartLocation);
curIndent.Push(IndentType.Block);
AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString);
curIndent.Pop();
break;
}
}
示例4: FixIndentationForceNewLine
void FixIndentationForceNewLine(AstNode node)
{
if (node.GetPrevNode () is NewLineNode) {
FixIndentation(node);
} else {
int offset = document.GetOffset(node.StartLocation);
AddChange(offset, 0, curIndent.IndentString);
}
}
示例5: CorrectClosingBrace
void CorrectClosingBrace(AstNode rbrace)
{
int braceOffset = document.GetOffset(rbrace.StartLocation);
var prevNode = rbrace.GetPrevNode();
int prevNodeOffset = prevNode != null ? document.GetOffset(prevNode.EndLocation) : 0;
if (prevNode is NewLineNode) {
AddChange(prevNodeOffset, braceOffset - prevNodeOffset, curIndent.IndentString);
} else {
AddChange(prevNodeOffset, braceOffset - prevNodeOffset, options.EolMarker + curIndent.IndentString);
}
}
示例6: EnforceBraceStyle
void EnforceBraceStyle(BraceStyle braceStyle, AstNode lbrace, AstNode rbrace)
{
if (lbrace.IsNull || rbrace.IsNull) {
return;
}
// LineSegment lbraceLineSegment = data.Document.GetLine (lbrace.StartLocation.Line);
int lbraceOffset = document.GetOffset(lbrace.StartLocation);
// LineSegment rbraceLineSegment = data.Document.GetLine (rbrace.StartLocation.Line);
int rbraceOffset = document.GetOffset(rbrace.StartLocation);
int whitespaceStart = SearchWhitespaceStart(lbraceOffset);
int whitespaceEnd = SearchWhitespaceLineStart(rbraceOffset);
string startIndent = "";
string endIndent = "";
switch (braceStyle) {
case BraceStyle.DoNotChange:
startIndent = endIndent = null;
break;
case BraceStyle.EndOfLineWithoutSpace:
startIndent = "";
endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString;
break;
case BraceStyle.BannerStyle:
var prevNode = lbrace.GetPrevNode();
if (prevNode is Comment) {
// delete old bracket
AddChange(whitespaceStart, lbraceOffset - whitespaceStart + 1, "");
while (prevNode is Comment) {
prevNode = prevNode.GetPrevNode();
}
whitespaceStart = document.GetOffset(prevNode.EndLocation);
lbraceOffset = whitespaceStart;
startIndent = " {";
} else {
startIndent = " ";
}
curIndent.Push(IndentType.Block);
endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString;
curIndent.Pop();
break;
case BraceStyle.EndOfLine:
prevNode = lbrace.GetPrevNode();
if (prevNode is Comment) {
// delete old bracket
AddChange(whitespaceStart, lbraceOffset - whitespaceStart + 1, "");
while (prevNode is Comment) {
prevNode = prevNode.GetPrevNode();
}
whitespaceStart = document.GetOffset(prevNode.EndLocation);
lbraceOffset = whitespaceStart;
startIndent = " {";
} else {
startIndent = " ";
}
endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString;
break;
case BraceStyle.NextLine:
startIndent = this.options.EolMarker + curIndent.IndentString;
endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString;
break;
case BraceStyle.NextLineShifted2:
case BraceStyle.NextLineShifted:
curIndent.Push(IndentType.Block);
startIndent = this.options.EolMarker + curIndent.IndentString;
endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString;
curIndent.Pop ();
break;
}
if (lbraceOffset > 0 && startIndent != null) {
AddChange(whitespaceStart, lbraceOffset - whitespaceStart, startIndent);
}
if (rbraceOffset > 0 && endIndent != null) {
AddChange(whitespaceEnd, rbraceOffset - whitespaceEnd, endIndent);
}
}
示例7: FixIndentationForceNewLine
void FixIndentationForceNewLine(AstNode node)
{
var directive = node as PreProcessorDirective;
if (node.GetPrevNode () is NewLineNode) {
if (directive != null && !policy.IndentPreprocessorDirectives) {
var startNode = node.GetPrevNode ();
var startOffset = document.GetOffset(startNode.EndLocation);
int endOffset = document.GetOffset(node.StartLocation);
AddChange(startOffset, endOffset - startOffset, "");
return;
} else {
FixIndentation(node);
}
} else {
// if no new line preceeds an #endif directive it's excluded
if (directive != null) {
if (directive.Type == PreProcessorDirectiveType.Endif)
return;
}
var startNode = node.GetPrevSibling(n => !(n is WhitespaceNode)) ?? node;
var startOffset = document.GetOffset(startNode.EndLocation);
int endOffset = document.GetOffset(node.StartLocation);
if (startOffset >= endOffset)
return;
if (directive != null && !policy.IndentPreprocessorDirectives) {
AddChange(startOffset, endOffset - startOffset, "");
return;
}
AddChange(startOffset, endOffset - startOffset, curIndent.IndentString);
}
}
示例8: FixIndentationForceNewLine
void FixIndentationForceNewLine(AstNode node)
{
if (node.GetPrevNode () is NewLineNode) {
FixIndentation(node);
} else {
// if no new line preceeds an #endif directive it's excluded
var directive = node as PreProcessorDirective;
if (directive != null) {
if (directive.Type == PreProcessorDirectiveType.Endif)
return;
}
int offset = document.GetOffset(node.StartLocation);
AddChange(offset, 0, curIndent.IndentString);
}
}