本文整理汇总了C#中SonarLint.Common.AnalyzerLanguage类的典型用法代码示例。如果您正苦于以下问题:C# AnalyzerLanguage类的具体用法?C# AnalyzerLanguage怎么用?C# AnalyzerLanguage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnalyzerLanguage类属于SonarLint.Common命名空间,在下文中一共展示了AnalyzerLanguage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNumberOfCrossReferences
private static int GetNumberOfCrossReferences(AnalyzerLanguage language)
{
return RuleDetailBuilder.GetParameterlessRuleDetails(language)
.Select(rule => rule.Description)
.Select(description => Regex.Matches(description, RuleImplementationMeta.CrosslinkPattern).Count)
.Sum();
}
示例2: GetParameterlessAnalyzerTypes
public IEnumerable<Type> GetParameterlessAnalyzerTypes(AnalyzerLanguage language)
{
return diagnosticAnalyzers
.Where(analyzerType =>
!analyzerType.GetProperties()
.Any(p => p.GetCustomAttributes<RuleParameterAttribute>().Any()))
.Where(type => GetTargetLanguages(type).IsAlso(language));
}
示例3: GetSolutionWithEmptyFile
public static Solution GetSolutionWithEmptyFile(AnalyzerLanguage language)
{
using (var workspace = new AdhocWorkspace())
{
var lang = language == AnalyzerLanguage.CSharp ? LanguageNames.CSharp : LanguageNames.VisualBasic;
return workspace.CurrentSolution.AddProject("foo", "foo.dll", lang)
.AddMetadataReference(SystemMetadataReference)
.AddDocument($"foo.{language.GetFileExtension()}", string.Empty)
.Project
.Solution;
}
}
示例4: WriteQualityProfileFile
private static void WriteQualityProfileFile(string filePath, IEnumerable<RuleDetail> ruleDetails, AnalyzerLanguage language)
{
var root = new QualityProfileRoot(language);
root.Rules.AddRange(ruleDetails
.Where(descriptor => descriptor.IsActivatedByDefault)
.Select(descriptor => new QualityProfileRuleDescriptor(language)
{
Key = descriptor.Key
}));
SerializeObjectToFile(filePath, root);
}
示例5: CheckRuleDescriptorsNotEmpty
private static void CheckRuleDescriptorsNotEmpty(AnalyzerLanguage language)
{
var ruleDetails = RuleDetailBuilder.GetAllRuleDetails(language).ToList();
foreach (var ruleDetail in ruleDetails)
{
Assert.IsNotNull(ruleDetail);
Assert.IsNotNull(ruleDetail.Description);
Assert.IsNotNull(ruleDetail.Key);
Assert.IsNotNull(ruleDetail.Title);
}
Assert.AreEqual(ruleDetails.Count,
ruleDetails.Select(descriptor => descriptor.Key).Distinct().Count());
}
示例6: Convert
public static RuleImplementationMeta Convert(RuleDetail detail, string productVersion, AnalyzerLanguage language)
{
return new RuleImplementationMeta
{
Id = detail.Key,
Language = language.GetFriendlyName(),
Severity = detail.Severity,
Title = detail.Title,
Description = GetParameterDescription(detail.Parameters) +
AddLinksBetweenRulesToDescription(detail.Description, productVersion) +
GetCodeFixDescription(detail),
Tags = detail.Tags
};
}
示例7: IsAlso
public bool IsAlso(AnalyzerLanguage other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
if (other == None)
{
throw new NotSupportedException("IsAlso doesn't support AnalyzerLanguage.None.");
}
return this == other || this == Both;
}
示例8: GetSolutionFromFiles
public static Solution GetSolutionFromFiles(string filePath, AnalyzerLanguage language)
{
using (var workspace = new AdhocWorkspace())
{
var file = new FileInfo(filePath);
var lang = language == AnalyzerLanguage.CSharp ? LanguageNames.CSharp : LanguageNames.VisualBasic;
var project = workspace.CurrentSolution.AddProject("foo", "foo.dll", lang)
.AddMetadataReference(SystemMetadataReference);
var document = project.AddDocument(file.Name, File.ReadAllText(file.FullName, Encoding.UTF8));
project = document.Project;
return project.Solution;
}
}
示例9: AddLanguage
public AnalyzerLanguage AddLanguage(AnalyzerLanguage other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
if (this == None ||
this == other)
{
return other;
}
return Both;
}
示例10: Configuration
public Configuration(string path, AnalyzerLanguage language)
{
if (!ParameterLoader.ConfigurationFilePathMatchesExpected(path))
{
throw new ArgumentException(
$"Input configuration doesn't match expected file name: '{ParameterLoader.ParameterConfigurationFileName}'",
nameof(path));
}
Path = path;
analyzers = ImmutableArray.Create(GetAnalyzers(language).ToArray());
var xml = XDocument.Load(path);
var settings = ParseSettings(xml);
IgnoreHeaderComments = "true".Equals(settings[$"sonar.{language}.ignoreHeaderComments"], StringComparison.OrdinalIgnoreCase);
Files = xml.Descendants("File").Select(e => e.Value).ToImmutableList();
AnalyzerIds = xml.Descendants("Rule").Select(e => e.Elements("Key").Single().Value).ToImmutableHashSet();
}
示例11: GetRuleDetail
private static RuleDetail GetRuleDetail(Type analyzerType, AnalyzerLanguage language)
{
var rule = analyzerType.GetCustomAttributes<RuleAttribute>().Single();
var ruleDetail = new RuleDetail
{
Key = rule.Key,
Title = rule.Title,
Severity = rule.Severity.ToString(),
IsActivatedByDefault = rule.IsActivatedByDefault,
Description = GetResourceHtml(rule, language)
};
GetParameters(analyzerType, ruleDetail);
GetTags(analyzerType, ruleDetail);
GetSqale(analyzerType, ruleDetail);
GetCodeFixNames(analyzerType, ruleDetail);
return ruleDetail;
}
示例12: Convert
public static RuleDescription Convert(RuleDetail detail, string productVersion, AnalyzerLanguage language)
{
return new RuleDescription
{
Key = detail.Key,
Data = new Dictionary<string, RuleMetaData>
{
{
language.ToString(),
new RuleMetaData
{
Title = detail.Title,
Description =
GetParameterDescription(detail.Parameters) +
AddLinksBetweenRulesToDescription(detail.Description, productVersion) +
GetCodeFixDescription(detail),
Tags = detail.Tags,
Severity = detail.Severity,
IdeSeverity = detail.IdeSeverity
}
}
}
};
}
示例13: Configuration
public Configuration(XContainer xml, AnalyzerLanguage language)
{
this.language = language;
nonTemplateAnalyzers = ImmutableArray.Create(GetNonTemplateAnalyzers(language).ToArray());
var settings = ParseSettings(xml);
IgnoreHeaderComments = "true".Equals(settings["sonar.cs.ignoreHeaderComments"]);
Files = xml.Descendants("File").Select(e => e.Value).ToImmutableList();
AnalyzerIds = xml.Descendants("Rule").Select(e => e.Elements("Key").Single().Value).ToImmutableHashSet();
var builder = ImmutableList.CreateBuilder<RuleParameterValues>();
foreach (var rule in xml.Descendants("Rule").Where(e => e.Elements("Parameters").Any()))
{
var analyzerId = rule.Elements("Key").Single().Value;
var parameterValues = rule
.Elements("Parameters").Single()
.Elements("Parameter")
.Select(e => new RuleParameterValue
{
ParameterKey = e.Elements("Key").Single().Value,
ParameterValue = e.Elements("Value").Single().Value
});
var pvs = new RuleParameterValues
{
RuleId = analyzerId
};
pvs.ParameterValues.AddRange(parameterValues);
builder.Add(pvs);
}
parameters = builder.ToImmutable();
}
示例14: Lines
private static int Lines(AnalyzerLanguage language, string text) => MetricsFor(language, text).LineCount;
示例15: FunctionComplexityDistribution
private static Distribution FunctionComplexityDistribution(AnalyzerLanguage language, string text) =>
MetricsFor(language, text).FunctionComplexityDistribution;