本文整理汇总了C#中InvocationExpressionSyntax.FirstAncestorOrSelf方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpressionSyntax.FirstAncestorOrSelf方法的具体用法?C# InvocationExpressionSyntax.FirstAncestorOrSelf怎么用?C# InvocationExpressionSyntax.FirstAncestorOrSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvocationExpressionSyntax
的用法示例。
在下文中一共展示了InvocationExpressionSyntax.FirstAncestorOrSelf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpressionSyntax node)
{
var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;
if (symbol != null)
{
IsAsyncLibraryConstruct(symbol.OriginalDefinition);
if (symbol.IsAPMBeginMethod())
{
Logs.TempLog.Info(SourceFile.FilePath + "\n" + node + "\n" + symbol + "\n"+ node.FirstAncestorOrSelf<MethodDeclarationSyntax>() + "******************\n");
Result.APM++;
}
else if (node.IsEAPMethod())
{
Result.EAP++;
}
else if (symbol.IsTAPMethod())
{
// printing TAP methods: Logs.TempLog.Info(SourceFile.FilePath + "\n" + node + "\n" + symbol + "******************\n");
Result.TAP++;
}
else if (symbol.IsThreadStart())
{
Result.ThreadInit++;
}
else if (symbol.IsThreadPoolQueueUserWorkItem())
{
Result.ThreadPoolQueue++;
}
else if (symbol.IsBackgroundWorkerMethod())
{
Result.BackgroundWorker++;
}
else if (symbol.IsAsyncDelegate())
{
Result.AsyncDelegate++;
}
else if (symbol.IsTaskCreationMethod())
{
Result.TaskInit++;
}
else if (symbol.IsParallelFor())
{
Result.ParallelFor++;
}
else if (symbol.IsParallelForEach())
{
Result.ParallelForEach++;
}
else if (symbol.IsParallelInvoke())
{
Result.ParallelInvoke++;
}
}
base.VisitInvocationExpression(node);
}
示例2: ShouldUseTap
internal bool ShouldUseTap(InvocationExpressionSyntax invocation)
{
var method = invocation.FirstAncestorOrSelf<MethodDeclarationSyntax>();
if (invocation.IsWrappedInAwaitExpression() || invocation.IsWrappedInLock() || method == null || IsFollowedByCallReturningVoid(invocation))
{
return false;
}
taskSymbol = new Lazy<ITypeSymbol>(() => semanticModel.Compilation.GetTypeByMetadataName(typeof(Task).FullName));
taskOfTSymbol = new Lazy<ITypeSymbol>(() => semanticModel.Compilation.GetTypeByMetadataName(typeof(Task).FullName + "`1"));
if (method.HasOutOrRefParameters())
{
return false;
}
var symbolToCheck = semanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol;
if (symbolToCheck == null)
return false;//Broken code case
return IsAwaitableMethod(symbolToCheck) && this.InvocationCallsIsWrappedInResultCall(invocation);
}
示例3: RewriteStatement
/// <summary>
/// Rewrites the expression with a create machine expression.
/// </summary>
/// <param name="node">InvocationExpressionSyntax</param>
/// <returns>SyntaxNode</returns>
private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
{
var arguments = new List<ArgumentSyntax>(node.ArgumentList.Arguments);
var machineIdentifier = arguments[0].ToString();
SyntaxNode models = null;
var parent = node.FirstAncestorOrSelf<ExpressionStatementSyntax>();
if (parent != null)
{
models = base.GetNextStatement(parent);
if (models != null &&
(models is LocalDeclarationStatementSyntax) &&
(models as LocalDeclarationStatementSyntax).Declaration.
Type.ToString().Equals("models"))
{
if (this.Project.CompilationContext.ActiveCompilationTarget != CompilationTarget.Testing)
{
machineIdentifier = (models as LocalDeclarationStatementSyntax).
Declaration.Variables[0].Identifier.ValueText;
}
}
else
{
models = null;
}
}
arguments[0] = SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(
SyntaxFactory.IdentifierName(machineIdentifier)));
var text = "";
if (base.IsMonitor(machineIdentifier))
{
if (this.Project.CompilationContext.ActiveCompilationTarget != CompilationTarget.Testing)
{
this.ToRemove.Add(node);
if (models != null)
{
this.ToRemove.Add(models);
}
return node;
}
text += "this.CreateMonitor";
}
else
{
text += "this.CreateMachine";
}
var rewritten = node.
WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
WithExpression(SyntaxFactory.IdentifierName(text)).
WithTriviaFrom(node);
if (models != null)
{
node = node.WithoutTrailingTrivia();
this.ToReplace.Add(models);
}
return rewritten;
}
示例4: ChangetoAwaitAsync
private async Task<Document> ChangetoAwaitAsync(Document document, InvocationExpressionSyntax invocation, string name, CancellationToken cancellationToken)
{
SyntaxNode oldExpression = invocation;
SyntaxNode newExpression = null;
if (name.Equals("Wait"))
{
oldExpression = invocation.FirstAncestorOrSelf<InvocationExpressionSyntax>();
var identifier = (invocation.Expression as MemberAccessExpressionSyntax).Expression as IdentifierNameSyntax;
newExpression = SyntaxFactory.PrefixUnaryExpression(
SyntaxKind.AwaitExpression,
identifier).WithAdditionalAnnotations(Formatter.Annotation);
}
if (name.Equals("Result"))
{
oldExpression = invocation.Parent.FirstAncestorOrSelf<MemberAccessExpressionSyntax>();
newExpression = SyntaxFactory.PrefixUnaryExpression(
SyntaxKind.AwaitExpression,
invocation).WithAdditionalAnnotations(Formatter.Annotation);
}
var oldroot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var newroot = oldroot.ReplaceNode(oldExpression, newExpression);
var newDocument = document.WithSyntaxRoot(newroot);
return newDocument;
}
示例5: DetectBlockingOperations
private void DetectBlockingOperations(InvocationExpressionSyntax methodCall, IMethodSymbol methodCallSymbol)
{
var methodDeclaration = methodCall.FirstAncestorOrSelf<MethodDeclarationSyntax>();
var replacement = ((IMethodSymbol)methodCallSymbol.OriginalDefinition).DetectSynchronousUsages(SemanticModel);
if (methodDeclaration != null)
{
if (replacement != "None")
{
Logs.TempLog6.Info(@"{0}{1}{2}{3}**********************************************",
Document.FilePath,
System.Environment.NewLine + System.Environment.NewLine + "BLOCKING METHODCALL: " + methodCallSymbol.ToString(),
System.Environment.NewLine + System.Environment.NewLine + "REPLACE IT WITH: " + replacement,
methodDeclaration.ToLog());
}
}
}
示例6: RefactorSimpleLambdaInstance
public static CompilationUnitSyntax RefactorSimpleLambdaInstance(CompilationUnitSyntax syntax, InvocationExpressionSyntax apmSyntax, IMethodSymbol apmSymbol, SimpleLambdaExpressionSyntax lambda)
{
if (lambda.Body.CSharpKind() != SyntaxKind.Block)
throw new NotImplementedException("Lambda body must be rewritten as BlockSyntax - it is now: " + lambda.Body.CSharpKind() + ": lambda: " + lambda);
var lambdaBlock = (BlockSyntax)lambda.Body;
var originatingMethodSyntax = apmSyntax.FirstAncestorOrSelf<MethodDeclarationSyntax>();
// TODO: This precondition'i Analyzer'a koy!!!
if (originatingMethodSyntax == null || !originatingMethodSyntax.ReturnsVoid())
{
throw new Exception("PRECONDITION: Initiating method does not return void");
}
// TODO: Look up the symbol to check that it actually exists.
var methodNameBase = GetAsyncMethodNameBase(apmSyntax);
var endStatement = TryFindEndAPMCallSyntaxNode(lambdaBlock, methodNameBase);
if (endStatement != null)
{
return RewriteNotNestedInstance(syntax, originatingMethodSyntax, apmSyntax, lambdaBlock, endStatement, methodNameBase, );
}
// Every method invocation might lead to the target EndXxx. Try to find it recursively.
// Once found, rewrite the methods in the invocation path, one by one.
// Finally, rewrite the originating method, and the method with the EndXxx statement.
var invocationPathToEndXxx = TryFindCallGraphPathToEndXxx(lambdaBlock, methodNameBase, model);
if (invocationPathToEndXxx.Count == 0)
{
throw new PreconditionException("Could not find End call in lambda body call graph");
}
// These two get special treatment.
var initialCall = invocationPathToEndXxx.RemoveLast();
var endXxxCall = invocationPathToEndXxx.RemoveFirst();
IMethodSymbol endXxxMethod;
try
{
endXxxMethod = model.LookupMethodSymbol(endXxxCall);
}
catch (SymbolMissingException e)
{
Logger.Error("No symbol found for APM End invocation: {0}", endXxxCall, e);
throw new RefactoringException("No symbol found for APM End invocation: " + endXxxCall, e);
}
var taskTypeParameter = endXxxMethod.ReturnType.Name;
var replacements = new List<SyntaxReplacementPair>(invocationPathToEndXxx.Count + 2);
// Replace all intermediate methods on the call graph path.
replacements.AddRange(
invocationPathToEndXxx.Select(
invocation => new SyntaxReplacementPair(
invocation.ContainingMethod(),
RewriteCallGraphPathComponent(invocation, taskTypeParameter)
)
)
);
// Replace method that contains BeginXxx call.
var taskName = FreeTaskName(originatingMethodSyntax);
replacements.Add(
new SyntaxReplacementPair(
originatingMethodSyntax,
RewriteOriginatingMethod(
apmSyntax,
RewriteOriginatingMethodLambdaBlock(lambda, initialCall, taskName),
methodNameBase,
taskName
)
)
);
// Replace method that contains the EndXxx call.
replacements.Add(
new SyntaxReplacementPair(
endXxxCall.ContainingMethod(),
RewriteEndXxxContainingMethod(
endXxxCall,
taskTypeParameter
)
)
);
return syntax
.ReplaceAll(replacements)
.WithUsingSystemThreadingTasks()
.Format(workspace);
}