本文整理汇总了C#中SyntaxNode.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.GetLocation方法的具体用法?C# SyntaxNode.GetLocation怎么用?C# SyntaxNode.GetLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.GetLocation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUpdatedDocumentAsync
internal async override Task<Document> GetUpdatedDocumentAsync(Document document, SemanticModel model, SyntaxNode root, SyntaxNode nodeToFix, Diagnostic diagnostic, CancellationToken cancellationToken)
{
var symbol = model.GetDeclaredSymbol(nodeToFix, cancellationToken);
var generator = SyntaxGenerator.GetGenerator(document);
// There was no constructor and so the diagnostic was on the type. Generate a serlialization ctor.
if (symbol.Kind == SymbolKind.NamedType)
{
var typeSymbol = symbol as INamedTypeSymbol;
var throwStatement = generator.ThrowStatement(generator.ObjectCreationExpression(generator.DottedName("System.NotImplementedException")));
var ctorDecl = generator.ConstructorDeclaration(
typeSymbol.Name,
new[]
{
generator.ParameterDeclaration("serializationInfo", generator.TypeExpression(WellKnownTypes.SerializationInfo(model.Compilation))),
generator.ParameterDeclaration("streamingContext", generator.TypeExpression(WellKnownTypes.StreamingContext(model.Compilation)))
},
typeSymbol.IsSealed ? Accessibility.Private : Accessibility.Protected,
statements: new[] { throwStatement });
var editor = SymbolEditor.Create(document.Project.Solution);
await editor.EditOneDeclarationAsync(typeSymbol, nodeToFix.GetLocation(), (e, d) => e.AddMember(d, ctorDecl), cancellationToken);
return editor.GetChangedDocuments().First();
}
else if (symbol.Kind == SymbolKind.Method)
{
// There is a serialization constructor but with incorrect accessibility. Set that right.
var methodSymbol = symbol as IMethodSymbol;
// This would be constructor and can have only one definition.
Debug.Assert(methodSymbol.IsConstructor() && methodSymbol.DeclaringSyntaxReferences.Count() == 1);
var declaration = await methodSymbol.DeclaringSyntaxReferences.First().GetSyntaxAsync(cancellationToken);
var newAccessibility = methodSymbol.ContainingType.IsSealed ? Accessibility.Private : Accessibility.Protected;
var newDecl = generator.WithAccessibility(declaration, newAccessibility);
return document.WithSyntaxRoot(root.ReplaceNode(declaration, newDecl));
}
return document;
}
示例2: GetConstantValue
internal override ConstantValue GetConstantValue(SyntaxNode node, LocalSymbol inProgress, DiagnosticBag diagnostics = null)
{
if (this.IsConst && inProgress == this)
{
if (diagnostics != null)
{
diagnostics.Add(ErrorCode.ERR_CircConstValue, node.GetLocation(), this);
}
return Microsoft.CodeAnalysis.ConstantValue.Bad;
}
MakeConstantTuple(inProgress, boundInitValue: null);
return _constantTuple == null ? null : _constantTuple.Value;
}
示例3: BaseMethodWrapperSymbol
internal BaseMethodWrapperSymbol(NamedTypeSymbol containingType, MethodSymbol methodBeingWrapped, SyntaxNode syntax, string name)
: base(containingType, methodBeingWrapped, syntax.SyntaxTree.GetReference(syntax), null, syntax.GetLocation(), name, DeclarationModifiers.Private)
{
Debug.Assert(containingType.ContainingModule is SourceModuleSymbol);
Debug.Assert(ReferenceEquals(methodBeingWrapped, methodBeingWrapped.ConstructedFrom));
Debug.Assert(!methodBeingWrapped.IsStatic);
TypeMap typeMap = null;
ImmutableArray<TypeParameterSymbol> typeParameters;
var substitutedType = methodBeingWrapped.ContainingType as SubstitutedNamedTypeSymbol;
typeMap = ((object)substitutedType == null ? TypeMap.Empty : substitutedType.TypeSubstitution);
if (!methodBeingWrapped.IsGenericMethod)
{
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else
{
typeMap = typeMap.WithAlphaRename(methodBeingWrapped, this, out typeParameters);
}
AssignTypeMapAndTypeParameters(typeMap, typeParameters);
}
示例4: GetTargetCaretPosition
protected override int GetTargetCaretPosition(SyntaxNode caretTarget)
{
// Inserted Event declarations are a single line, so move to the end of the line.
if (caretTarget is EventFieldDeclarationSyntax)
{
return caretTarget.GetLocation().SourceSpan.End;
}
else if (caretTarget is MethodDeclarationSyntax)
{
var methodDeclaration = (MethodDeclarationSyntax)caretTarget;
// abstract override blah(); : move to the end of the line
if (methodDeclaration.Body == null)
{
return methodDeclaration.GetLocation().SourceSpan.End;
}
else
{
// move to the end of the last statement in the method
var lastStatement = methodDeclaration.Body.Statements.Last();
return lastStatement.GetLocation().SourceSpan.End;
}
}
else if (caretTarget is BasePropertyDeclarationSyntax)
{
// property: no accessors; move to the end of the declaration
var propertyDeclaration = (BasePropertyDeclarationSyntax)caretTarget;
if (propertyDeclaration.AccessorList != null && propertyDeclaration.AccessorList.Accessors.Any())
{
// move to the end of the last statement of the first accessor
var firstAccessorStatement = propertyDeclaration.AccessorList.Accessors.First().Body.Statements.Last();
return firstAccessorStatement.GetLocation().SourceSpan.End;
}
else
{
return propertyDeclaration.GetLocation().SourceSpan.End;
}
}
else
{
throw ExceptionUtilities.Unreachable;
}
}
示例5: Report
private static void Report(OperationAnalysisContext context, SyntaxNode syntax, DiagnosticDescriptor descriptor)
{
context.ReportDiagnostic(Diagnostic.Create(descriptor, syntax.GetLocation()));
}
示例6: Report
/// <summary>Reports a diagnostic warning for a boxing operation.</summary>
/// <param name="context">The context.</param>
/// <param name="boxingExpression">The expression that produces the boxing.</param>
internal void Report(OperationAnalysisContext context, SyntaxNode boxingExpression)
{
context.ReportDiagnostic(Diagnostic.Create(BoxingDescriptor, boxingExpression.GetLocation()));
}
示例7: Report
/// <summary>Reports a diagnostic warning for an array creation that should be replaced.</summary>
/// <param name="context">The context.</param>
/// <param name="arrayCreationExpression">The array creation expression to be replaced.</param>
internal void Report(SyntaxNodeAnalysisContext context, SyntaxNode arrayCreationExpression)
{
context.ReportDiagnostic(Diagnostic.Create(UseArrayEmptyDescriptor, arrayCreationExpression.GetLocation()));
}
示例8: AddAnalysisPoint
private BoundStatement AddAnalysisPoint(SyntaxNode syntaxForSpan, SyntheticBoundNodeFactory statementFactory)
{
return AddAnalysisPoint(syntaxForSpan, syntaxForSpan.GetLocation().GetMappedLineSpan(), statementFactory);
}
示例9: GetSourceDocument
private Cci.DebugSourceDocument GetSourceDocument(SyntaxNode syntax)
{
return GetSourceDocument(syntax, syntax.GetLocation().GetMappedLineSpan());
}
示例10: TryCheckVariableTypeAsync
private async Task<Tuple<bool, OperationStatus>> TryCheckVariableTypeAsync(
SemanticDocument document, SyntaxNode contextNode, IEnumerable<VariableInfo> variables,
OperationStatus status, CancellationToken cancellationToken)
{
if (status.FailedWithNoBestEffortSuggestion())
{
return Tuple.Create(false, status);
}
var location = contextNode.GetLocation();
foreach (var variable in variables)
{
var originalType = variable.GetVariableType(document);
var result = await CheckTypeAsync(document.Document, contextNode, location, originalType, cancellationToken).ConfigureAwait(false);
if (result.FailedWithNoBestEffortSuggestion())
{
status = status.With(result);
return Tuple.Create(false, status);
}
}
return Tuple.Create(true, status);
}