本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxNode.IsKind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.IsKind方法的具体用法?C# SyntaxNode.IsKind怎么用?C# SyntaxNode.IsKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.IsKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsCandidate
protected override bool IsCandidate(SyntaxNode node)
{
return node.IsKind(SyntaxKind.IdentifierName) ||
node.IsKind(SyntaxKind.MethodDeclaration) ||
node.IsKind(SyntaxKind.InvocationExpression) ||
node.IsKind(SyntaxKind.CastExpression) ||
node is LiteralExpressionSyntax ||
node is SimpleNameSyntax ||
node is ExpressionSyntax;
}
示例2: CreateBaseName
public static string CreateBaseName(SyntaxNode node, ITypeSymbol type)
{
string name = null;
if (node.IsKind(SyntaxKind.Argument))
node = ((ArgumentSyntax)node).Expression;
if (node.IsKind(SyntaxKind.NullLiteralExpression))
return "o";
if (node.IsKind(SyntaxKind.InvocationExpression))
return CreateBaseName(((InvocationExpressionSyntax)node).Expression, type);
if (node.IsKind(SyntaxKind.IdentifierName))
{
name = node.ToString();
}
else if (node is MemberAccessExpressionSyntax)
{
name = ((MemberAccessExpressionSyntax)node).Name.ToString();
}
else if (node is LiteralExpressionSyntax)
{
var pe = (LiteralExpressionSyntax)node;
if (pe.IsKind(SyntaxKind.StringLiteralExpression))
{
name = CreateBaseNameFromString(pe.Token.ToString());
}
else
{
return char.ToLower(type.Name[0]).ToString();
}
}
else if (node is ArrayCreationExpressionSyntax)
{
name = "arr";
}
else
{
if (type.TypeKind == TypeKind.Error)
return "par";
name = GuessNameFromType(type);
}
var sb = new StringBuilder();
sb.Append(char.ToLower(name[0]));
for (int i = 1; i < name.Length; i++)
{
var ch = name[i];
if (char.IsLetterOrDigit(ch) || ch == '_')
sb.Append(ch);
}
return sb.ToString();
}
示例3: IsFunctionLikeLastReturnStatement
private static bool IsFunctionLikeLastReturnStatement(SyntaxNode node)
{
if (!BranchKinds.Contains(node.Kind()))
{
return false;
}
if (!node.IsKind(SyntaxKind.ReturnStatement))
{
return false;
}
var blockType = node.Parent.GetType();
if (!BlockTypes.Any(bType => bType.IsAssignableFrom(blockType)))
{
return false;
}
if (!IsFunctionLike(node.Parent))
{
return false;
}
var nextToken = node.GetLastToken().GetNextToken();
var nextNode = nextToken.Parent;
return nextToken.IsKind(SyntaxKind.EndKeyword) &&
node.Parent == nextNode.Parent;
}
示例4: GetOutlineSpans
public List<TagSpan<IOutliningRegionTag>> GetOutlineSpans(SyntaxNode node, ITextSnapshot textSnapshot,
IdeServices ideServices)
{
var ret = new List<TagSpan<IOutliningRegionTag>>();
var isBlock = IsBlock(node);
if (!isBlock)
{
return ret;
}
// always has an extra empty line?
var text = node.GetText();
var isOnlineBlock = text.Lines.Count <= 2;
if (isOnlineBlock)
{
return ret;
}
if (node.IsKind(SyntaxKind.MultiLineIfBlock))
{
var additionalSpan = AddAdditionalOutlinerForIfStatement(node, textSnapshot, ideServices);
if (additionalSpan != null)
{
ret.Add(additionalSpan);
}
}
var hint = GetCodeHint(textSnapshot, ideServices, node.FullSpan.Start, node.FullSpan.Length);
var span = new TagSpan<IOutliningRegionTag>(
new SnapshotSpan(textSnapshot, GetSpanStartPosition(node, text), GetSpanLength(node, text)),
new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
collapsedForm: "...", collapsedHintForm: hint));
ret.Add(span);
return ret;
}
示例5: IsAssertTrueOrFalse
/// <summary>
///
/// </summary>
/// <param name="node"></param>
/// <returns>true=Assert.True; false=Assert.False; null=Neither </returns>
public static bool? IsAssertTrueOrFalse(SyntaxNode node)
{
if (node != null && node.IsKind(SyntaxKind.ExpressionStatement))
{
var invoke = (node as ExpressionStatementSyntax).Expression as InvocationExpressionSyntax;
if (invoke != null)
{
var expr = invoke.Expression as MemberAccessExpressionSyntax;
if (!(expr == null || expr.Name == null || expr.Expression == null))
{
var id = expr.Name.Identifier.ToString().Trim();
var caller = expr.Expression.ToString().Trim();
if (caller == "Assert")
{
if (id == "True")
return true;
if (id == "False")
return false;
}
}
}
}
return null;
}
示例6: IsEmpty
internal static bool IsEmpty(SyntaxNode node)
{
if (node == null || node.IsKind(SyntaxKind.EmptyStatement))
return true;
var block = node as BlockSyntax;
return block != null && block.Statements.All(IsEmpty);
}
示例7: IsGetProperty
private static bool IsGetProperty(SyntaxNode n)
{
if (!n.IsKind(SyntaxKind.PropertyDeclaration))
{
return false;
}
var propertyDeclarationSyntax = n as PropertyDeclarationSyntax;
return propertyDeclarationSyntax != null && propertyDeclarationSyntax.AccessorList.Accessors.Any(a => a.IsKind(SyntaxKind.GetAccessorDeclaration));
}
示例8: Visit
public override void Visit(SyntaxNode node)
{
var t = node.Kind();
if (node.IsKind(SyntaxKind.IdentifierName))
{
var name = node.ToString();
string syntax;
if (_DefinedOutside.TryGetValue(name, out syntax))
{
_DefinedOutside.Remove(name);
sb.Append(syntax);
}
}
/*
var symbol = _model.GetSymbolInfo(node).Symbol;
var ca = _model.GetSymbolInfo(node).CandidateSymbols;
var declaredSymbol = _model.GetDeclaredSymbol(node);
if (symbol?.Kind == SymbolKind.Field)
{
var x = 3;
}
if (symbol != null)
{
var test = symbol.CanBeReferencedByName;
var sources = symbol.DeclaringSyntaxReferences;
if (sources.Any())
{
foreach (var source in sources)
{
if (source.Span.Start > _end
|| source.Span.End < _start)
{
//DefinedOutside.Add(source.GetSyntax().ToFullString());
}
}
}
var locations = symbol?.Locations;
if (locations.HasValue)
{
/*
foreach (var location in locations.Value)
{
if (location.SourceSpan.Start > _end
|| location.SourceSpan.End < _start)
{
DefinedOutside.Add(symbol);
}
}
}
}*/
base.Visit(node);
}
示例9: ExtractName
private static string ExtractName(SyntaxNode node)
{
string result;
if (node.IsKind(SyntaxKind.ConstructorDeclaration))
{
result = "Constructor \"" + ((ConstructorDeclarationSyntax)node).Identifier + "\"";
}
else if (node.IsKind(SyntaxKind.MethodDeclaration))
{
result = "Method \"" + ((MethodDeclarationSyntax)node).Identifier + "\"";
}
else if (node.IsKind(SyntaxKind.DelegateDeclaration))
{
result = "Delegate";
}
else
{
result = "Lambda";
}
return result;
}
示例10: GetTargetNode
protected override SyntaxNode GetTargetNode(SyntaxNode node)
{
if (node.IsKind(SyntaxKind.MemberBindingExpression))
{
var nameNode = node.ChildNodes().FirstOrDefault(n => n.IsKind(SyntaxKind.IdentifierName));
if (nameNode != null)
{
return nameNode;
}
}
return base.GetTargetNode(node);
}
示例11: GetMethodParameters
private static IList<string> GetMethodParameters(SyntaxNode node)
{
while ((node != null) && !node.IsKind(SyntaxKind.MethodDeclaration))
{
node = node.Parent;
}
if (node == null)
{
return new List<string>();
}
var methodDeclaration = (MethodDeclarationSyntax)node;
return methodDeclaration.ParameterList.Parameters.Select(p => p.Identifier.ValueText).ToList();
}
示例12: GetMethodNameLocation
protected override Location GetMethodNameLocation(SyntaxNode invocationNode)
{
Debug.Assert(invocationNode.IsKind(SyntaxKind.InvocationExpression));
var invocation = invocationNode as InvocationExpressionSyntax;
if (invocation.Expression.IsKind(SyntaxKind.SimpleMemberAccessExpression))
{
return ((MemberAccessExpressionSyntax)invocation.Expression).Name.GetLocation();
}
else if (invocation.Expression.IsKind(SyntaxKind.ConditionalAccessExpression))
{
return ((ConditionalAccessExpressionSyntax)invocation.Expression).WhenNotNull.GetLocation();
}
return invocation.GetLocation();
}
示例13: IsNotAssignment
private static bool IsNotAssignment(SyntaxNode syntax, SyntaxNode value)
{
if (syntax.IsKind(SyntaxKind.SimpleAssignmentExpression))
{
var binaryExpression = (AssignmentExpressionSyntax)syntax;
return binaryExpression.Right == value;
}
var expression = syntax as EqualsValueClauseSyntax;
if (expression != null)
{
return expression.Value == value;
}
return true;
}
示例14: IsCandidate
protected override bool IsCandidate(SyntaxNode node)
{
var qualified = node as QualifiedNameSyntax;
if (qualified != null)
{
return true;
}
var simple = node as SimpleNameSyntax;
if (simple != null)
{
return !simple.IsParentKind(SyntaxKind.QualifiedName);
}
var memberAccess = node as MemberAccessExpressionSyntax;
if (memberAccess != null)
{
return true;
}
if (node.IsKind (SyntaxKind.ObjectCreationExpression))
return true;
return false;
}
示例15: GetValidTypes
//.........这里部分代码省略.........
// var rr = model.Resolve(field.ReturnType);
// if (!rr.IsError)
// return new [] { rr.Type };
// }
// var varStmt = initializer.GetParent<VariableDeclarationStatement>();
// if (varStmt != null) {
// var rr = model.Resolve(varStmt.Type);
// if (!rr.IsError)
// return new [] { rr.Type };
// }
// return new [] { model.Resolve(initializer).Type };
// }
//
// if (expr.Parent is CastExpressionSyntax) {
// var cast = (CastExpressionSyntax)expr.Parent;
// return new [] { model.Resolve(cast.Type).Type };
// }
//
// if (expr.Parent is AsExpressionSyntax) {
// var cast = (AsExpressionSyntax)expr.Parent;
// return new [] { model.Resolve(cast.Type).Type };
// }
if (expr.Parent is AssignmentExpressionSyntax || mref != null && mref.Parent is AssignmentExpressionSyntax)
{
var assign = expr.Parent as AssignmentExpressionSyntax ?? mref.Parent as AssignmentExpressionSyntax;
var other = assign.Left == expr || assign.Left == mref ? assign.Right : assign.Left;
return new[] { model.GetTypeInfo(other).Type };
}
// if (expr.Parent is BinaryOperatorExpressionSyntax) {
// var assign = (BinaryOperatorExpressionSyntax)expr.Parent;
// var other = assign.Left == expr ? assign.Right : assign.Left;
// return new [] { model.Resolve(other).Type };
// }
//
// if (expr.Parent is ReturnStatement) {
// var parent = expr.Ancestors.FirstOrDefault(n => n is EntityDeclaration || n is AnonymousMethodExpressionSyntax|| n is LambdaExpressionSyntax);
// if (parent != null) {
// var rr = model.Resolve(parent);
// if (!rr.IsError)
// return new [] { rr.Type };
// }
// var e = parent as EntityDeclaration;
// if (e != null) {
// var rt = model.Resolve(e.ReturnType);
// if (!rt.IsError)
// return new [] { rt.Type };
// }
// }
//
// if (expr.Parent is YieldReturnStatement) {
// var state = model.GetResolverStateBefore(expr);
// if (state != null && (state.CurrentMember.ReturnType is ParameterizedType)) {
// var pt = (ParameterizedType)state.CurrentMember.ReturnType;
// if (pt.FullName == "System.Collections.Generic.IEnumerable") {
// return new [] { pt.TypeArguments.First() };
// }
// }
// }
//
// if (expr.Parent is UnaryOperatorExpressionSyntax) {
// var uop = (UnaryOperatorExpressionSyntax)expr.Parent;
// switch (uop.Operator) {
// case UnaryOperatorType.Not:
// return new [] { model.Compilation.FindType(KnownTypeCode.Boolean) };
// case UnaryOperatorType.Minus:
// case UnaryOperatorType.Plus:
// case UnaryOperatorType.Increment:
// case UnaryOperatorType.Decrement:
// case UnaryOperatorType.PostIncrement:
// case UnaryOperatorType.PostDecrement:
// return new [] { model.Compilation.FindType(KnownTypeCode.Int32) };
// }
// }
//
// if (expr.Parent is ConstructorInitializer)
// return GuessFromConstructorInitializer(model, expr);
//
// if (expr.Parent is NamedExpressionSyntax) {
// var rr = model.Resolve(expr.Parent);
// if (!rr.IsError) {
// return new [] { rr.Type };
// }
// }
if (expr.IsKind(SyntaxKind.Argument))
{
var parent = expr.Parent.Parent;
var invocationParent = parent as InvocationExpressionSyntax;
if (invocationParent != null)
{
return GetAllValidTypesFromInvocation(model, invocationParent, expr);
}
}
var types = typeInferenceService.InferTypes(model, expr, cancellationToken).ToList();
return types;
}