private AssemblyCacheEntry CreateAssemblyCacheEntry([NotNull] string path) { ExternalAnnotationsMap assemblyAnnotationsMap = AssemblyExternalAnnotationsLoader.ParseFile(path); FileSystemWatcher fileWatcher = CreateAssemblyAnnotationsFileWatcher(path); return(new AssemblyCacheEntry(assemblyAnnotationsMap, fileWatcher)); }
private static ExternalAnnotationsCache ScanForMemberExternalAnnotations() { var result = new ExternalAnnotationsMap(); var parser = new ExternalAnnotationDocumentParser(); var recorder = new HighestLastWriteTimeUtcRecorder(); foreach (string path in EnumerateAnnotationFiles()) { recorder.VisitFile(path); using (StreamReader reader = File.OpenText(path)) { parser.ProcessDocument(reader, result); } } Compact(result); if (!result.Any()) { throw GetErrorForMissingExternalAnnotations(); } return(new ExternalAnnotationsCache(recorder.HighestLastWriteTimeUtc, result)); }
public AssemblyCacheEntry([NotNull] ExternalAnnotationsMap map, [NotNull] FileSystemWatcher watcher) { Guard.NotNull(map, "map"); Guard.NotNull(watcher, "watcher"); this.map = map; this.watcher = watcher; }
public AssemblyCacheEntry([NotNull] ExternalAnnotationsMap map, [NotNull] FileSystemWatcher watcher) { Guard.NotNull(map, nameof(map)); Guard.NotNull(watcher, nameof(watcher)); Map = map; Watcher = watcher; }
public ExactSourceCode([NotNull] string text, [NotNull] string sourceExpected, [NotNull] string filename, [NotNull] ExternalAnnotationsMap externalAnnotationsMap, [NotNull][ItemNotNull] ImmutableHashSet <MetadataReference> references, [NotNull] string codeNamespaceImport) : base(text, filename, externalAnnotationsMap, references, new string[0], codeNamespaceImport, false) { Guard.NotNull(sourceExpected, nameof(sourceExpected)); this.sourceExpected = sourceExpected; }
private static void Compact([NotNull] ExternalAnnotationsMap externalAnnotations) { foreach (string key in externalAnnotations.Keys.ToList()) { MemberNullabilityInfo annotation = externalAnnotations[key]; if (!HasNullabilityDefined(annotation)) { externalAnnotations.Remove(key); } } }
public static ExternalAnnotationsMap ParseFile([NotNull] string externalAnnotationsPath) { Guard.NotNull(externalAnnotationsPath, nameof(externalAnnotationsPath)); using (TextReader reader = File.OpenText(externalAnnotationsPath)) { var map = new ExternalAnnotationsMap(); var parser = new ExternalAnnotationDocumentParser(); parser.ProcessDocument(reader, map); return(map); } }
public static ExternalAnnotationsMap ParseFile([NotNull] string externalAnnotationsPath) { Guard.NotNull(externalAnnotationsPath, "externalAnnotationsPath"); using (TextReader reader = File.OpenText(externalAnnotationsPath)) { var map = new ExternalAnnotationsMap(); var parser = new ExternalAnnotationDocumentParser(); parser.ProcessDocument(reader, map); return map; } }
public static ExternalAnnotationsMap Create() { try { ExternalAnnotationsMap map = GetCached(); if (map.Count > 0) { return(map); } } catch (Exception ex) { throw new Exception($"Failed to load Resharper external annotations: {ex.Message}", ex); } throw new Exception("Failed to load Resharper external annotations."); }
public ParsedSourceCode([NotNull] string text, [NotNull] string filename, [NotNull] ExternalAnnotationsMap externalAnnotationsMap, [NotNull][ItemNotNull] ImmutableHashSet <MetadataReference> references, [ItemNotNull][NotNull] IList <string> nestedTypes, [NotNull] string codeNamespaceImport, bool reIndent) { Guard.NotNull(text, nameof(text)); Guard.NotNull(filename, nameof(filename)); Guard.NotNull(externalAnnotationsMap, nameof(externalAnnotationsMap)); Guard.NotNull(references, nameof(references)); Guard.NotNull(nestedTypes, nameof(nestedTypes)); Guard.NotNull(codeNamespaceImport, nameof(codeNamespaceImport)); this.text = Parse(text); Filename = filename; ExternalAnnotationsMap = externalAnnotationsMap; References = references; attributePrefix = ExtractAttributePrefix(nestedTypes); CodeNamespaceImport = codeNamespaceImport; ReIndentExpected = reIndent; }
private static ExternalAnnotationsCache ScanForMemberExternalAnnotations() { var result = new ExternalAnnotationsMap(); var parser = new ExternalAnnotationDocumentParser(); var recorder = new HighestLastWriteTimeUtcRecorder(); foreach (string path in EnumerateAnnotationFiles()) { recorder.VisitFile(path); using (StreamReader reader = File.OpenText(path)) { parser.ProcessDocument(reader, result); } } Compact(result); return new ExternalAnnotationsCache(recorder.HighestLastWriteTimeUtc, result); }
public SimpleExternalAnnotationsResolver([NotNull] ExternalAnnotationsMap source) { Guard.NotNull(source, nameof(source)); this.source = source; }
public ExternalAnnotationsCache() { ExternalAnnotations = new ExternalAnnotationsMap(); }
public void EnsureScanned() { ExternalAnnotationsMap dummy = GlobalCache.Value; }
public void EnsureScanned() { // ReSharper disable once UnusedVariable ExternalAnnotationsMap dummy = GlobalCache.Value; }
public void ProcessDocument([NotNull] TextReader reader, [NotNull] ExternalAnnotationsMap result) { Guard.NotNull(reader, nameof(reader)); Guard.NotNull(result, nameof(result)); XElement assemblyElement = XDocument.Load(reader).Element("assembly"); if (assemblyElement != null) { // Known limitation: we are not entirely correct here, by ignoring assembly info. // You'll run into this, for example, with the next block of code: // // public class MyEnumerator : IEnumerator // { // public bool MoveNext() { throw new System.NotImplementedException(); } // // public void Reset() { } // // [CanBeNull] // public object Current { get; } // } // // When you set project properties to target .NET Framework v4.5, Resharper is fine with // the [CanBeNull]. But if you switch to target .NET Framework v2, then Resharper grays // out the [CanBeNull], with hover message "Base declaration has the same annotation". // This is because the external annotation file "2.0.0.0.Interfaces.Nullness.Gen.xml" // contains the following snapshot: // // <?xml version="1.0" encoding="utf-8"?> // <assembly name="mscorlib, Version=2.0.0.0"> // <member name="P:System.Collections.IEnumerator.Current"> // <attribute ctor="M:JetBrains.Annotations.CanBeNullAttribute.#ctor" /> // </member> // </assembly> // // But when targeting the .NET Framework v4.5, mscorlib v4.0.0.0 is used, so this snapshot // does not apply. To support this, we need to add assembly info to our data structure // for each symbol. That makes the dataset grow a lot, taking longer to load/save. foreach (XElement memberElement in assemblyElement.Elements("member")) { string memberType = "?"; string memberName = memberElement.Attribute("name").Value; if (memberName.Length > 2 && memberName[1] == ':') { memberType = memberName[0].ToString(); memberName = memberName.Substring(2); } MemberNullabilityInfo memberInfo = result.ContainsKey(memberName) ? result[memberName] : new MemberNullabilityInfo(memberType); foreach (XElement childElement in memberElement.Elements()) { if (childElement.Name == "parameter") { string parameterName = childElement.Attribute("name").Value; foreach (XElement attributeElement in childElement.Elements("attribute")) { if (ElementHasNullabilityDefinition(attributeElement)) { memberInfo.ParametersNullability[parameterName] = true; } } } if (childElement.Name == "attribute") { if (ElementHasNullabilityDefinition(childElement)) { memberInfo.HasNullabilityDefined = true; } } } result[memberName] = memberInfo; } } }