本文整理汇总了C#中Microsoft.PythonTools.Parsing.Ast.NameExpression.AddPreceedingWhiteSpace方法的典型用法代码示例。如果您正苦于以下问题:C# NameExpression.AddPreceedingWhiteSpace方法的具体用法?C# NameExpression.AddPreceedingWhiteSpace怎么用?C# NameExpression.AddPreceedingWhiteSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.PythonTools.Parsing.Ast.NameExpression
的用法示例。
在下文中一共展示了NameExpression.AddPreceedingWhiteSpace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExtractionResult
public ExtractMethodResult GetExtractionResult(ExtractMethodRequest info) {
bool isStaticMethod = false, isClassMethod = false;
var parameters = new List<Parameter>();
string selfParam = null;
if (info.TargetScope is ClassDefinition) {
var fromScope = _scopes[_scopes.Length - 1] as FunctionDefinition;
Debug.Assert(fromScope != null); // we don't allow extracting from classes, so we have to be coming from a function
if (fromScope != null) {
if (fromScope.Decorators != null) {
foreach (var decorator in fromScope.Decorators.Decorators) {
NameExpression name = decorator as NameExpression;
if (name != null) {
if (name.Name == "staticmethod") {
isStaticMethod = true;
} else if (name.Name == "classmethod") {
isClassMethod = true;
}
}
}
}
if (!isStaticMethod) {
if (fromScope.Parameters.Count > 0) {
selfParam = fromScope.Parameters[0].Name;
parameters.Add(new Parameter(selfParam, ParameterKind.Normal));
}
}
}
}
foreach (var param in info.Parameters) {
var newParam = new Parameter(param, ParameterKind.Normal);
if (parameters.Count > 0) {
newParam.AddPreceedingWhiteSpace(_ast, " ");
}
parameters.Add(newParam);
}
// include any non-closed over parameters as well...
foreach (var input in _inputVars) {
var variableScope = input.Scope;
var parentScope = info.TargetScope;
// are these variables a child of the target scope so we can close over them?
while (parentScope != null && parentScope != variableScope) {
parentScope = parentScope.Parent;
}
if (parentScope == null && input.Name != selfParam) {
// we can either close over or pass these in as parameters, add them to the list
var newParam = new Parameter(input.Name, ParameterKind.Normal);
if (parameters.Count > 0) {
newParam.AddPreceedingWhiteSpace(_ast, " ");
}
parameters.Add(newParam);
}
}
var body = _target.GetBody(_ast);
var isCoroutine = IsCoroutine(body);
// reset leading indentation to single newline + indentation, this
// strips out any proceeding comments which we don't extract
var leading = _newline + body.GetIndentationLevel(_ast);
body.SetLeadingWhiteSpace(_ast, leading);
if (_outputVars.Count > 0) {
// need to add a return statement
Expression retValue;
Expression[] names = new Expression[_outputVars.Count];
int outputIndex = 0;
foreach (var name in _outputVars) {
var nameExpr = new NameExpression(name.Name);
nameExpr.AddPreceedingWhiteSpace(_ast, " ");
names[outputIndex++] = nameExpr;
}
var tuple = new TupleExpression(false, names);
tuple.RoundTripHasNoParenthesis(_ast);
retValue = tuple;
var retStmt = new ReturnStatement(retValue);
retStmt.SetLeadingWhiteSpace(_ast, leading);
body = new SuiteStatement(
new Statement[] {
body,
retStmt
}
);
} else {
// we need a SuiteStatement to give us our colon
body = new SuiteStatement(new Statement[] { body });
}
DecoratorStatement decorators = null;
if (isStaticMethod) {
decorators = new DecoratorStatement(new[] { new NameExpression("staticmethod") });
} else if (isClassMethod) {
decorators = new DecoratorStatement(new[] { new NameExpression("classmethod") });
}
//.........这里部分代码省略.........