Skip to content
This repository was archived by the owner on Oct 2, 2022. It is now read-only.

Commit e588aa9

Browse files
committed
Revert langversion to default (which is now framework-dependent). Setting to latest may result in hard-to-trace bugs when framework support is missing, according to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version
1 parent 59a1b9e commit e588aa9

29 files changed

Lines changed: 194 additions & 170 deletions

src/CodeContractNullability/CodeContractNullability.Test/Specs/ScanningForExternalAnnotationsSpecs.cs

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,24 @@ public void When_external_annotations_cache_is_corrupt_it_must_succeed()
184184
public void When_side_by_side_external_annotations_file_does_not_exist_it_must_succeed()
185185
{
186186
// Arrange
187-
using var assemblyScope = new TempAssemblyScope();
188-
189-
string systemAnnotationsPath = Environment.ExpandEnvironmentVariables(
190-
@"%LOCALAPPDATA%\JetBrains\Installations\ReSharperPlatformVs14_57882815\ExternalAnnotations\.NETFramework\mscorlib\Annotations.xml");
191-
192-
IFileSystem fileSystem = new FakeFileSystemBuilder()
193-
.IncludingTextFile(systemAnnotationsPath, new ExternalAnnotationsBuilder()
194-
.IncludingMember(new ExternalAnnotationFragmentBuilder()
195-
.Named("M:System.String.IsNullOrEmpty(System.String)")
196-
.WithParameter(new ExternalAnnotationParameterBuilder()
197-
.Named("value")
198-
.CanBeNull()))
199-
.GetXml())
200-
.Build();
201-
202-
ParsedSourceCode source = new TypeSourceCodeBuilder()
203-
.WithNullabilityAttributes(new NullabilityAttributesBuilder())
204-
.WithReferenceToExternalAssemblyOnDiskFor(assemblyScope.AssemblyPath, @"
187+
using (var assemblyScope = new TempAssemblyScope())
188+
{
189+
string systemAnnotationsPath = Environment.ExpandEnvironmentVariables(
190+
@"%LOCALAPPDATA%\JetBrains\Installations\ReSharperPlatformVs14_57882815\ExternalAnnotations\.NETFramework\mscorlib\Annotations.xml");
191+
192+
IFileSystem fileSystem = new FakeFileSystemBuilder()
193+
.IncludingTextFile(systemAnnotationsPath, new ExternalAnnotationsBuilder()
194+
.IncludingMember(new ExternalAnnotationFragmentBuilder()
195+
.Named("M:System.String.IsNullOrEmpty(System.String)")
196+
.WithParameter(new ExternalAnnotationParameterBuilder()
197+
.Named("value")
198+
.CanBeNull()))
199+
.GetXml())
200+
.Build();
201+
202+
ParsedSourceCode source = new TypeSourceCodeBuilder()
203+
.WithNullabilityAttributes(new NullabilityAttributesBuilder())
204+
.WithReferenceToExternalAssemblyOnDiskFor(assemblyScope.AssemblyPath, @"
205205
using System;
206206
207207
namespace ExternalAssembly
@@ -212,7 +212,7 @@ public interface I
212212
}
213213
}
214214
")
215-
.InGlobalScope(@"
215+
.InGlobalScope(@"
216216
public class C : ExternalAssembly.I
217217
{
218218
public string [|M|]()
@@ -221,43 +221,44 @@ public class C : ExternalAssembly.I
221221
}
222222
}
223223
")
224-
.Build();
224+
.Build();
225225

226-
var analyzerTest = new ReusableAnalyzerOnFileSystemTest(fileSystem);
226+
var analyzerTest = new ReusableAnalyzerOnFileSystemTest(fileSystem);
227227

228-
analyzerTest.VerifyNullabilityDiagnostics(source,
229-
analyzerTest.CreateMessageFor(SymbolType.Method, "M"));
228+
analyzerTest.VerifyNullabilityDiagnostics(source,
229+
analyzerTest.CreateMessageFor(SymbolType.Method, "M"));
230+
}
230231
}
231232

232233
[Fact]
233234
public void When_side_by_side_external_annotations_file_changes_it_must_update_analyzer_cache()
234235
{
235236
// Arrange
236-
using var assemblyScope = new TempAssemblyScope();
237-
238-
string systemAnnotationsPath = Environment.ExpandEnvironmentVariables(
239-
@"%LOCALAPPDATA%\JetBrains\Installations\ReSharperPlatformVs14_57882815\ExternalAnnotations\.NETFramework\mscorlib\Annotations.xml");
240-
241-
string sideBySideAnnotationsPath = assemblyScope.TempPath + ".ExternalAnnotations.xml";
242-
243-
IFileSystem fileSystem = new FakeFileSystemBuilder()
244-
.IncludingTextFile(systemAnnotationsPath, new ExternalAnnotationsBuilder()
245-
.IncludingMember(new ExternalAnnotationFragmentBuilder()
246-
.Named("M:System.String.IsNullOrEmpty(System.String)")
247-
.WithParameter(new ExternalAnnotationParameterBuilder()
248-
.Named("value")
249-
.CanBeNull()))
250-
.GetXml())
251-
.IncludingTextFile(sideBySideAnnotationsPath, new ExternalAnnotationsBuilder()
252-
.IncludingMember(new ExternalAnnotationFragmentBuilder()
253-
.Named("M:ExternalAssembly.I.M")
254-
.NotNull())
255-
.GetXml())
256-
.Build();
257-
258-
TypeSourceCodeBuilder sourceBuilder = new TypeSourceCodeBuilder()
259-
.WithNullabilityAttributes(new NullabilityAttributesBuilder())
260-
.WithReferenceToExternalAssemblyOnDiskFor(assemblyScope.AssemblyPath, @"
237+
using (var assemblyScope = new TempAssemblyScope())
238+
{
239+
string systemAnnotationsPath = Environment.ExpandEnvironmentVariables(
240+
@"%LOCALAPPDATA%\JetBrains\Installations\ReSharperPlatformVs14_57882815\ExternalAnnotations\.NETFramework\mscorlib\Annotations.xml");
241+
242+
string sideBySideAnnotationsPath = assemblyScope.TempPath + ".ExternalAnnotations.xml";
243+
244+
IFileSystem fileSystem = new FakeFileSystemBuilder()
245+
.IncludingTextFile(systemAnnotationsPath, new ExternalAnnotationsBuilder()
246+
.IncludingMember(new ExternalAnnotationFragmentBuilder()
247+
.Named("M:System.String.IsNullOrEmpty(System.String)")
248+
.WithParameter(new ExternalAnnotationParameterBuilder()
249+
.Named("value")
250+
.CanBeNull()))
251+
.GetXml())
252+
.IncludingTextFile(sideBySideAnnotationsPath, new ExternalAnnotationsBuilder()
253+
.IncludingMember(new ExternalAnnotationFragmentBuilder()
254+
.Named("M:ExternalAssembly.I.M")
255+
.NotNull())
256+
.GetXml())
257+
.Build();
258+
259+
TypeSourceCodeBuilder sourceBuilder = new TypeSourceCodeBuilder()
260+
.WithNullabilityAttributes(new NullabilityAttributesBuilder())
261+
.WithReferenceToExternalAssemblyOnDiskFor(assemblyScope.AssemblyPath, @"
261262
using System;
262263
263264
namespace ExternalAssembly
@@ -269,8 +270,8 @@ public interface I
269270
}
270271
");
271272

272-
ParsedSourceCode initialSource = sourceBuilder
273-
.InGlobalScope(@"
273+
ParsedSourceCode initialSource = sourceBuilder
274+
.InGlobalScope(@"
274275
public class C : ExternalAssembly.I
275276
{
276277
public string M()
@@ -279,22 +280,22 @@ public string M()
279280
}
280281
}
281282
")
282-
.Build();
283+
.Build();
283284

284-
// Method ExternalAssembly.I.M() is externally annotated in side-by-side xml file, so expect no diagnostics.
285-
var analyzerTest = new ReusableAnalyzerOnFileSystemTest(fileSystem);
286-
analyzerTest.VerifyNullabilityDiagnostics(initialSource);
285+
// Method ExternalAssembly.I.M() is externally annotated in side-by-side xml file, so expect no diagnostics.
286+
var analyzerTest = new ReusableAnalyzerOnFileSystemTest(fileSystem);
287+
analyzerTest.VerifyNullabilityDiagnostics(initialSource);
287288

288-
// Update contents of the side-by-side xml file: remove the external annotation.
289-
fileSystem.File.WriteAllText(sideBySideAnnotationsPath, new ExternalAnnotationsBuilder()
290-
.IncludingMember(new ExternalAnnotationFragmentBuilder()
291-
.Named("M:ExternalAssembly.I.M"))
292-
.GetXml());
289+
// Update contents of the side-by-side xml file: remove the external annotation.
290+
fileSystem.File.WriteAllText(sideBySideAnnotationsPath, new ExternalAnnotationsBuilder()
291+
.IncludingMember(new ExternalAnnotationFragmentBuilder()
292+
.Named("M:ExternalAssembly.I.M"))
293+
.GetXml());
293294

294-
// Update source text (add markers) without recreating analyzer instance.
295-
ParsedSourceCode updatedSource = sourceBuilder
296-
.ClearGlobalScope()
297-
.InGlobalScope(@"
295+
// Update source text (add markers) without recreating analyzer instance.
296+
ParsedSourceCode updatedSource = sourceBuilder
297+
.ClearGlobalScope()
298+
.InGlobalScope(@"
298299
public class C : ExternalAssembly.I
299300
{
300301
public string [|M|]()
@@ -303,13 +304,14 @@ public class C : ExternalAssembly.I
303304
}
304305
}
305306
")
306-
.Build();
307+
.Build();
307308

308-
analyzerTest.WaitForFileEvictionFromSideBySideCache(sideBySideAnnotationsPath);
309+
analyzerTest.WaitForFileEvictionFromSideBySideCache(sideBySideAnnotationsPath);
309310

310-
// After update of the side-by-side file on disk, analyzer should detect the change and report a diagnostic this time.
311-
analyzerTest.VerifyNullabilityDiagnostics(updatedSource,
312-
analyzerTest.CreateMessageFor(SymbolType.Method, "M"));
311+
// After update of the side-by-side file on disk, analyzer should detect the change and report a diagnostic this time.
312+
analyzerTest.VerifyNullabilityDiagnostics(updatedSource,
313+
analyzerTest.CreateMessageFor(SymbolType.Method, "M"));
314+
}
313315
}
314316

315317
[Theory]

src/CodeContractNullability/CodeContractNullability.Test/TestDataBuilders/AnalyzerSettingsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public AnalyzerSettingsBuilder DisableReportOnNullableValueTypes
2525

2626
public AnalyzerSettings Build()
2727
{
28-
return new(disableReportOnNullableValueTypes);
28+
return new AnalyzerSettings(disableReportOnNullableValueTypes);
2929
}
3030

3131
[NotNull]

src/CodeContractNullability/CodeContractNullability.Test/TestDataBuilders/ExternalAnnotationFragmentBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal sealed class ExternalAnnotationFragmentBuilder : ITestDataBuilder<XElem
2424

2525
[NotNull]
2626
[ItemNotNull]
27-
private readonly List<XElement> parameters = new();
27+
private readonly List<XElement> parameters = new List<XElement>();
2828

2929
[NotNull]
3030
private string memberName = "value";

src/CodeContractNullability/CodeContractNullability.Test/TestDataBuilders/ExternalAnnotationsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal sealed class ExternalAnnotationsBuilder : ITestDataBuilder<ExternalAnno
1414
{
1515
[NotNull]
1616
[ItemNotNull]
17-
private readonly List<XElement> fragments = new();
17+
private readonly List<XElement> fragments = new List<XElement>();
1818

1919
public ExternalAnnotationsMap Build()
2020
{

src/CodeContractNullability/CodeContractNullability.Test/TestDataBuilders/MemberSourceCodeBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal sealed class MemberSourceCodeBuilder : SourceCodeBuilder
1010
{
1111
[NotNull]
1212
[ItemNotNull]
13-
private readonly List<string> members = new();
13+
private readonly List<string> members = new List<string>();
1414

1515
protected override string GetSourceCode()
1616
{

src/CodeContractNullability/CodeContractNullability.Test/TestDataBuilders/NullabilityAttributesBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ internal sealed class NullabilityAttributesBuilder : ITestDataBuilder<Nullabilit
88
{
99
[NotNull]
1010
[ItemNotNull]
11-
private readonly List<string> nestedTypes = new();
11+
private readonly List<string> nestedTypes = new List<string>();
1212

1313
[NotNull]
1414
private string codeNamespace = "Namespace.For.JetBrains.Annotation.Attributes";
1515

1616
public NullabilityAttributesDefinition Build()
1717
{
18-
return new(codeNamespace, nestedTypes);
18+
return new NullabilityAttributesDefinition(codeNamespace, nestedTypes);
1919
}
2020

2121
[NotNull]

src/CodeContractNullability/CodeContractNullability.Test/TestDataBuilders/SourceCodeBuilder.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ internal abstract class SourceCodeBuilder : ITestDataBuilder<ParsedSourceCode>
1818
private static readonly TextSpan[] EmptyTextSpanArray = new TextSpan[0];
1919

2020
[NotNull]
21-
public static readonly AnalyzerTestContext DefaultTestContext = new(string.Empty, EmptyTextSpanArray, LanguageNames.CSharp,
21+
public static readonly AnalyzerTestContext DefaultTestContext = new AnalyzerTestContext(string.Empty, EmptyTextSpanArray, LanguageNames.CSharp,
2222
new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty));
2323

2424
[NotNull]
2525
[ItemNotNull]
26-
private readonly HashSet<string> namespaceImports = new()
26+
private readonly HashSet<string> namespaceImports = new HashSet<string>
2727
{
2828
"System"
2929
};
@@ -41,7 +41,7 @@ internal abstract class SourceCodeBuilder : ITestDataBuilder<ParsedSourceCode>
4141
private NullabilityAttributesDefinition nullabilityAttributes = new NullabilityAttributesBuilder().InGlobalNamespace().Build();
4242

4343
[NotNull]
44-
private ExternalAnnotationsBuilder externalAnnotationsBuilder = new();
44+
private ExternalAnnotationsBuilder externalAnnotationsBuilder = new ExternalAnnotationsBuilder();
4545

4646
[NotNull]
4747
private string codeNamespaceImportExpected = string.Empty;
@@ -149,23 +149,24 @@ protected string GetLinesOfCode([NotNull] [ItemNotNull] IEnumerable<string> code
149149

150150
bool isOnFirstLineInBlock = true;
151151

152-
using var reader = new StringReader(codeBlock.TrimEnd());
153-
154-
string line;
155-
156-
while ((line = reader.ReadLine()) != null)
152+
using (var reader = new StringReader(codeBlock.TrimEnd()))
157153
{
158-
if (isOnFirstLineInBlock)
154+
string line;
155+
156+
while ((line = reader.ReadLine()) != null)
159157
{
160-
if (line.Trim().Length == 0)
158+
if (isOnFirstLineInBlock)
161159
{
162-
continue;
160+
if (line.Trim().Length == 0)
161+
{
162+
continue;
163+
}
164+
165+
isOnFirstLineInBlock = false;
163166
}
164167

165-
isOnFirstLineInBlock = false;
168+
builder.AppendLine(line);
166169
}
167-
168-
builder.AppendLine(line);
169170
}
170171
}
171172

src/CodeContractNullability/CodeContractNullability.Test/TestDataBuilders/TypeSourceCodeBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal sealed class TypeSourceCodeBuilder : SourceCodeBuilder
1010
{
1111
[NotNull]
1212
[ItemNotNull]
13-
private readonly List<string> types = new();
13+
private readonly List<string> types = new List<string>();
1414

1515
protected override string GetSourceCode()
1616
{

src/CodeContractNullability/CodeContractNullability/AnalyzerSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public sealed class AnalyzerSettings
1111
private const string SettingsNamespace = "ResharperCodeContractNullabilitySettings";
1212

1313
[NotNull]
14-
internal static readonly AnalyzerSettings Default = new();
14+
internal static readonly AnalyzerSettings Default = new AnalyzerSettings();
1515

1616
[DataMember(Name = "disableReportOnNullableValueTypes")]
1717
public bool DisableReportOnNullableValueTypes { get; private set; }

src/CodeContractNullability/CodeContractNullability/BaseAnalyzer.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public abstract class BaseAnalyzer : DiagnosticAnalyzer
3131
[NotNull]
3232
[ItemCanBeNull]
3333
private static readonly Lazy<MethodInfo> LazyEnableConcurrentExecutionMethod =
34-
new(() => typeof(AnalysisContext).GetMethod("EnableConcurrentExecution"), LazyThreadSafetyMode.PublicationOnly);
34+
new Lazy<MethodInfo>(() => typeof(AnalysisContext).GetMethod("EnableConcurrentExecution"), LazyThreadSafetyMode.PublicationOnly);
3535

3636
[NotNull]
3737
[ItemCanBeNull]
3838
private static readonly Lazy<MethodInfo> LazyConfigureGeneratedCodeAnalysisMethod =
39-
new(() => typeof(AnalysisContext).GetMethod("ConfigureGeneratedCodeAnalysis"), LazyThreadSafetyMode.PublicationOnly);
39+
new Lazy<MethodInfo>(() => typeof(AnalysisContext).GetMethod("ConfigureGeneratedCodeAnalysis"), LazyThreadSafetyMode.PublicationOnly);
4040

4141
private readonly bool appliesToItem;
4242

@@ -53,7 +53,7 @@ public abstract class BaseAnalyzer : DiagnosticAnalyzer
5353
private readonly DiagnosticDescriptor ruleForParameter;
5454

5555
[NotNull]
56-
private readonly DiagnosticDescriptor disableReportOnNullableValueTypesRule = new(DisableReportOnNullableValueTypesDiagnosticId,
56+
private readonly DiagnosticDescriptor disableReportOnNullableValueTypesRule = new DiagnosticDescriptor(DisableReportOnNullableValueTypesDiagnosticId,
5757
"Suggest to disable reporting on nullable value types.",
5858
"IMPORTANT: Due to a bug in Visual Studio, additional steps are needed. Expand the arrow to the left of this message for details.", "Configuration",
5959
DiagnosticSeverity.Hidden, true, @"
@@ -80,10 +80,11 @@ 5. Save and close the project file.
8080
ImmutableArray.Create(ruleForField, ruleForProperty, ruleForMethodReturnValue, ruleForParameter, disableReportOnNullableValueTypesRule);
8181

8282
[NotNull]
83-
public ExtensionPoint<INullabilityAttributeProvider> NullabilityAttributeProvider { get; } = new(() => new CachingNullabilityAttributeProvider());
83+
public ExtensionPoint<INullabilityAttributeProvider> NullabilityAttributeProvider { get; } =
84+
new ExtensionPoint<INullabilityAttributeProvider>(() => new CachingNullabilityAttributeProvider());
8485

8586
[NotNull]
86-
public ExtensionPoint<IFileSystem> FileSystem { get; } = new(() => FileSystemWrapper.Default);
87+
public ExtensionPoint<IFileSystem> FileSystem { get; } = new ExtensionPoint<IFileSystem>(() => FileSystemWrapper.Default);
8788

8889
[NotNull]
8990
public ExtensionPoint<IExternalAnnotationsResolver> ExternalAnnotationsResolver { get; }

0 commit comments

Comments
 (0)