本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Location类的典型用法代码示例。如果您正苦于以下问题:C# Location类的具体用法?C# Location怎么用?C# Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Location类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyDiagnosticLocation
private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Location actual, DiagnosticResultLocation expected)
{
var actualSpan = actual.GetLineSpan();
Assert.True(actualSpan.Path == expected.Path || (actualSpan.Path != null && actualSpan.Path.Contains("Test0.") && expected.Path.Contains("Test.")),
string.Format("Expected diagnostic to be in file \"{0}\" was actually in file \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
expected.Path, actualSpan.Path, FormatDiagnostics(analyzer, diagnostic)));
var actualLinePosition = actualSpan.StartLinePosition;
// Only check line position if there is an actual line in the real diagnostic
if (actualLinePosition.Line > 0)
{
if (actualLinePosition.Line + 1 != expected.Line)
{
Assert.True(false,
string.Format("Expected diagnostic to be on line \"{0}\" was actually on line \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
expected.Line, actualLinePosition.Line + 1, FormatDiagnostics(analyzer, diagnostic)));
}
}
// Only check column position if there is an actual column position in the real diagnostic
if (actualLinePosition.Character > 0)
{
if (actualLinePosition.Character + 1 != expected.Column)
{
Assert.True(false,
string.Format("Expected diagnostic to start at column \"{0}\" was actually at column \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
expected.Column, actualLinePosition.Character + 1, FormatDiagnostics(analyzer, diagnostic)));
}
}
}
示例2: Add
internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, ImmutableArray<Symbol> symbols, params object[] args)
{
var info = new CSDiagnosticInfo(code, args, symbols, ImmutableArray<Location>.Empty);
var diag = new CSDiagnostic(info, location);
diagnostics.Add(diag);
return info;
}
示例3: GetDiagnosticReport
// Take a warning and return the final deposition of the given warning,
// based on both command line options and pragmas.
// If you update this method, also update DiagnosticItemSource.GetEffectiveSeverity.
internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity, bool isEnabledByDefault, string id, int diagnosticWarningLevel, Location location, string category, int warningLevelOption, ReportDiagnostic generalDiagnosticOption, IDictionary<string, ReportDiagnostic> specificDiagnosticOptions)
{
// Read options (e.g., /nowarn or /warnaserror)
ReportDiagnostic report = ReportDiagnostic.Default;
var isSpecified = specificDiagnosticOptions.TryGetValue(id, out report);
if (!isSpecified)
{
report = isEnabledByDefault ? ReportDiagnostic.Default : ReportDiagnostic.Suppress;
}
// Compute if the reporting should be suppressed.
if (diagnosticWarningLevel > warningLevelOption // honor the warning level
|| report == ReportDiagnostic.Suppress) // check options (/nowarn)
{
return ReportDiagnostic.Suppress;
}
// If location is available, check out pragmas
if (location != null &&
location.SourceTree != null &&
((SyntaxTree)location.SourceTree).GetPragmaDirectiveWarningState(id, location.SourceSpan.Start) == ReportDiagnostic.Suppress)
{
return ReportDiagnostic.Suppress;
}
// Unless specific warning options are defined (/warnaserror[+|-]:<n> or /nowarn:<n>,
// follow the global option (/warnaserror[+|-] or /nowarn).
if (report == ReportDiagnostic.Default)
{
switch (generalDiagnosticOption)
{
case ReportDiagnostic.Error:
// If we've been asked to do warn-as-error then don't raise severity for anything below warning (info or hidden).
if (severity == DiagnosticSeverity.Warning)
{
// In the case where /warnaserror+ is followed by /warnaserror-:<n> on the command line,
// do not promote the warning specified in <n> to an error.
if (!isSpecified && (report == ReportDiagnostic.Default))
{
return ReportDiagnostic.Error;
}
}
break;
case ReportDiagnostic.Suppress:
// When doing suppress-all-warnings, don't lower severity for anything other than warning and info.
// We shouldn't suppress hidden diagnostics here because then features that use hidden diagnostics to
// display a lightbulb would stop working if someone has suppress-all-warnings (/nowarn) specified in their project.
if (severity == DiagnosticSeverity.Warning || severity == DiagnosticSeverity.Info)
{
return ReportDiagnostic.Suppress;
}
break;
default:
break;
}
}
return report;
}
示例4: ReportUnsafeIfNotAllowed
/// <returns>True if a diagnostic was reported, or would have been reported if not for
/// the suppress flag.</returns>
private bool ReportUnsafeIfNotAllowed(Location location, TypeSymbol sizeOfTypeOpt, DiagnosticBag diagnostics)
{
var diagnosticInfo = GetUnsafeDiagnosticInfo(sizeOfTypeOpt);
if (diagnosticInfo == null || this.Flags.Includes(BinderFlags.SuppressUnsafeDiagnostics))
{
return false;
}
diagnostics.Add(new CSDiagnostic(diagnosticInfo, location));
return true;
}
示例5: EnsureSingleDefinition
internal override bool EnsureSingleDefinition(Symbol symbol, string name, Location location, DiagnosticBag diagnostics)
{
ParameterSymbol existingDeclaration;
var map = this.definitionMap;
if (map != null && map.TryGetValue(name, out existingDeclaration))
{
return InMethodBinder.ReportConflictWithParameter(existingDeclaration, symbol, name, location, diagnostics);
}
return false;
}
示例6: WithLocation
internal override Diagnostic WithLocation(Location location)
{
if (location == null)
{
throw new ArgumentNullException(nameof(location));
}
if (location != this.Location)
{
return new CSDiagnostic(this.Info, location);
}
return this;
}
示例7: GetUnsafeDiagnostic
private Diagnostic GetUnsafeDiagnostic(Location location, TypeSymbol sizeOfTypeOpt)
{
if (this.IsIndirectlyInIterator)
{
// Spec 8.2: "An iterator block always defines a safe context, even when its declaration
// is nested in an unsafe context."
return new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_IllegalInnerUnsafe), location);
}
else if (!this.InUnsafeRegion)
{
return ReferenceEquals(sizeOfTypeOpt, null)
? new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_UnsafeNeeded), location)
: new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_SizeofUnsafe, sizeOfTypeOpt), location);
}
else
{
return null;
}
}
示例8: AppendUseSiteDiagnostics
internal static bool AppendUseSiteDiagnostics(
Location location,
HashSet<DiagnosticInfo> useSiteDiagnostics,
DiagnosticBag diagnostics)
{
if (useSiteDiagnostics.IsNullOrEmpty())
{
return false;
}
bool haveErrors = false;
foreach (var info in useSiteDiagnostics)
{
if (info.Severity == DiagnosticSeverity.Error)
{
haveErrors = true;
}
Error(diagnostics, info, location);
}
return haveErrors;
}
示例9: EnterIncludeElement
private bool EnterIncludeElement(Location location)
{
if (this.inProgressIncludeElementNodes == null)
{
this.inProgressIncludeElementNodes = new HashSet<Location>();
}
return this.inProgressIncludeElementNodes.Add(location);
}
示例10: LeaveIncludeElement
private bool LeaveIncludeElement(Location location)
{
Debug.Assert(this.inProgressIncludeElementNodes != null);
bool result = this.inProgressIncludeElementNodes.Remove(location);
Debug.Assert(result);
return result;
}
示例11: MakeCommentMessage
private string MakeCommentMessage(Location location, MessageID messageId)
{
if (location.IsInSource)
{
// TODO: use culture from compilation instead of invariant culture?
return ErrorFacts.GetMessage(messageId, CultureInfo.InvariantCulture);
}
else
{
return null;
}
}
示例12: CompareSourceLocations
internal override int CompareSourceLocations(Location loc1, Location loc2)
{
Debug.Assert(loc1.IsInSource);
Debug.Assert(loc2.IsInSource);
var comparison = CompareSyntaxTreeOrdering(loc1.SourceTree, loc2.SourceTree);
if (comparison != 0)
{
return comparison;
}
return loc1.SourceSpan.Start - loc2.SourceSpan.Start;
}
示例13: ReportUseSiteDiagnosticForSynthesizedAttribute
/// <summary>
/// Report diagnostics that should be reported when using a synthesized attribute.
/// </summary>
internal static void ReportUseSiteDiagnosticForSynthesizedAttribute(
CSharpCompilation compilation,
WellKnownMember attributeMember,
DiagnosticBag diagnostics,
Location location = null,
CSharpSyntaxNode syntax = null)
{
Debug.Assert((location != null) ^ (syntax != null));
// Dev11 reports use-site diagnostics when an optional attribute is found but is bad for some other reason
// (comes from an unified assembly). When the symbol is not found no error is reported. See test VersionUnification_UseSiteDiagnostics_OptionalAttributes.
bool isOptional = WellKnownMembers.IsSynthesizedAttributeOptional(attributeMember);
GetWellKnownTypeMember(compilation, attributeMember, diagnostics, location, syntax, isOptional);
}
示例14: Error
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, Location location)
{
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code), location));
}
示例15: MethodGroupConversionDoesNotExistOrHasErrors
/// <summary>
/// This method is a wrapper around MethodGroupConversionHasErrors. As a preliminary step,
/// it checks whether a conversion exists.
/// </summary>
private bool MethodGroupConversionDoesNotExistOrHasErrors(
BoundMethodGroup boundMethodGroup,
NamedTypeSymbol delegateType,
Location delegateMismatchLocation,
DiagnosticBag diagnostics,
out Conversion conversion)
{
if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, delegateType, delegateMismatchLocation))
{
conversion = Conversion.NoConversion;
return true;
}
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
conversion = Conversions.GetMethodGroupConversion(boundMethodGroup, delegateType, ref useSiteDiagnostics);
diagnostics.Add(delegateMismatchLocation, useSiteDiagnostics);
if (!conversion.Exists)
{
// No overload for '{0}' matches delegate '{1}'
diagnostics.Add(ErrorCode.ERR_MethDelegateMismatch, delegateMismatchLocation, boundMethodGroup.Name, delegateType);
return true;
}
else
{
Debug.Assert(conversion.IsValid); // i.e. if it exists, then it is valid.
// Only cares about nullness and type of receiver, so no need to worry about BoundTypeOrValueExpression.
return this.MethodGroupConversionHasErrors(boundMethodGroup.Syntax, conversion, boundMethodGroup.ReceiverOpt, conversion.IsExtensionMethod, delegateType, diagnostics);
}
}