Skip to content

Commit

Permalink
Merge pull request #43367 from mavasani/MoveCodeStyleLayerAhead
Browse files Browse the repository at this point in the history
Move CodeStyle layer to Microsoft.CodeAnalysis 3.6.0
  • Loading branch information
msftbot[bot] authored Apr 17, 2020
2 parents 8a39dd2 + 01af39f commit ef734e1
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 81 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PropertyGroup>
<!-- Versions used by several individual references below -->
<RoslynDiagnosticsNugetPackageVersion>3.0.0-beta2.20169.3</RoslynDiagnosticsNugetPackageVersion>
<CodeStyleLayerCodeAnalysisVersion>3.3.1</CodeStyleLayerCodeAnalysisVersion>
<CodeStyleLayerCodeAnalysisVersion>3.6.0-2.final</CodeStyleLayerCodeAnalysisVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.20210.2</MicrosoftCodeAnalysisTestingVersion>
<CodeStyleAnalyzerVersion>3.7.0-1.20210.7</CodeStyleAnalyzerVersion>
<VisualStudioEditorPackagesVersion>16.4.248</VisualStudioEditorPackagesVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ private ForEachVariableStatementSyntax CreateForEachVariableStatement(INamedType
// However, convert the existing declaration over to a "var (x, y)" declaration or (int x, int y)
// tuple expression.
return SyntaxFactory.ForEachVariableStatement(
#if !CODE_STYLE // ForEachStatementSyntax.AttributeLists is not available in the version of Microsoft.CodeAnalysis used by CodeStyle layer
// https://github.com/dotnet/roslyn/issues/41462#issuecomment-595893953 tracks removing these conditional directives.
forEachStatement.AttributeLists,
#endif
forEachStatement.AwaitKeyword,
forEachStatement.ForEachKeyword,
forEachStatement.OpenParenToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,7 @@ void M()
}");
}

#if CODE_STYLE
[WorkItem(41462, "https://github.com/dotnet/roslyn/issues/41462")]
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/41462")]
#else
[Fact]
#endif
[WorkItem(42770, "https://github.com/dotnet/roslyn/issues/42770")]
[Trait(Traits.Feature, Traits.Features.CodeActionsUseDeconstruction)]
public async Task TestPreserveAwait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,6 @@ void Method(Program? x)
await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent());
}

#if !CODE_STYLE // TODO: Skipped tests in CodeStyle layer depend on new Nullable APIs that are not available in CodeStyle layer.
// https://github.com/dotnet/roslyn/issues/41462 tracks adding this support

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUseExplicitType)]
[WorkItem(40477, "https://github.com/dotnet/roslyn/issues/40477")]
public async Task NullableType()
Expand Down Expand Up @@ -1018,8 +1015,6 @@ void Method(System.Collections.Generic.IEnumerable<(Program, Program)> x)
await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent());
}

#endif

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUseExplicitType)]
[WorkItem(23907, "https://github.com/dotnet/roslyn/issues/23907")]
public async Task InPointerTypeWithIntrinsicType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ private void AnalyzeOperation(OperationAnalysisContext context)
.Add(PopulateSwitchStatementHelpers.MissingCases, missingCases.ToString())
.Add(PopulateSwitchStatementHelpers.MissingDefaultCase, missingDefaultCase.ToString());

#pragma warning disable CS8620 // Mismatch in nullability of 'properties' parameter and argument types - Parameter type for 'properties' has been updated to 'ImmutableDictionary<string, string?>?' in newer version of Microsoft.CodeAnalysis (3.7.x).
var diagnostic = Diagnostic.Create(
Descriptor,
GetDiagnosticLocation(switchBlock),
properties: properties,
additionalLocations: new[] { switchBlock.GetLocation() });
#pragma warning restore CS8620

context.ReportDiagnostic(diagnostic);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private static async Task<bool> MakeMultiLineAsync(
}

#if CODE_STYLE
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var tree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var wrappingLength = document.Project.AnalyzerOptions.GetOption(UseConditionalExpressionOptions.ConditionalExpressionWrappingLength, document.Project.Language, tree, cancellationToken);
#else
var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.SemanticModelWorkspaceService
{
Expand All @@ -19,7 +20,7 @@ public Task<SemanticModel> GetSemanticModelForNodeAsync(Document document, Synta
// TODO: port the GetSemanticModelForNodeAsync implementation from Workspaces layer,
// which currently relies on a bunch of internal APIs.
// For now, we fall back to the public API to fetch document's SemanticModel.
return document.GetSemanticModelAsync(cancellationToken);
return document.GetRequiredSemanticModelAsync(cancellationToken);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ public static bool IsKind<TNode>([NotNullWhen(returnValue: true)] this SyntaxNod
{
if (node.IsKind(kind))
{
#if !CODE_STYLE
result = (TNode)node;
#else
// The CodeStyle layer is referencing an older, unannotated version of Roslyn which doesn't know that IsKind guarantees the non-nullness
// of node. So we have to silence it here.
result = (TNode)node!;
#endif
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.Formatting
{
Expand All @@ -23,7 +24,7 @@ internal class SpacingFormattingRule : BaseFormattingRule
return nextOperation.Invoke();
}

System.Diagnostics.Debug.Assert(previousToken.Parent != null && currentToken.Parent != null);
RoslynDebug.Assert(previousToken.Parent != null && currentToken.Parent != null);

var previousKind = previousToken.Kind();
var currentKind = currentToken.Kind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ internal static partial class ITypeSymbolExtensions
private const string DefaultBuiltInParameterName = "v";

public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
#if CODE_STYLE // TODO: Remove this #if once 'WithNullableAnnotation' and 'NullableAnnotation' are available in CodeStyle layer.
=> type != null && (type.IsReferenceType || type.IsNullable());
#else
{
if (type == null)
return false;
Expand All @@ -35,7 +32,6 @@ public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSy

return isNullableValueType || isNonNullableReferenceType;
}
#endif

public static IList<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
{
Expand Down Expand Up @@ -714,22 +710,7 @@ public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbo
type?.AllInterfaces.Contains(iDisposableType) == true);

public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
{
#if CODE_STYLE // TODO: Remove this #if once 'WithNullableAnnotation' and 'NullableAnnotation' are available in CodeStyle layer.
return type;
#else
return type.WithNullableAnnotation(symbolForNullableAnnotation.NullableAnnotation);
#endif
}

public static ITypeSymbol WithNullableAnnotation(this ITypeSymbol type, NullableAnnotation nullableAnnotation)
{
#if CODE_STYLE // TODO: Remove this #if once 'WithNullableAnnotation' is available in CodeStyle layer.
return type;
#else
return type.WithNullableAnnotation(nullableAnnotation);
#endif
}
=> type.WithNullableAnnotation(symbolForNullableAnnotation.NullableAnnotation);

[return: NotNullIfNotNull(parameterName: "symbol")]
public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public override TypeSyntax VisitArrayType(IArrayTypeSymbol symbol)
{
underlyingType = innerArray.ElementType;

#if !CODE_STYLE // TODO: Remove the #if once NullableAnnotation is available.
// https://github.com/dotnet/roslyn/issues/41462 tracks adding this support
if (underlyingType.NullableAnnotation == NullableAnnotation.Annotated)
{
// If the inner array we just moved to is also nullable, then
Expand All @@ -81,7 +79,6 @@ public override TypeSyntax VisitArrayType(IArrayTypeSymbol symbol)

break;
}
#endif
}

var elementTypeSyntax = underlyingType.GenerateTypeSyntax();
Expand All @@ -98,13 +95,10 @@ public override TypeSyntax VisitArrayType(IArrayTypeSymbol symbol)

TypeSyntax arrayTypeSyntax = SyntaxFactory.ArrayType(elementTypeSyntax, ranks.ToSyntaxList());

#if !CODE_STYLE // TODO: Remove the #if once NullableAnnotation is available.
// https://github.com/dotnet/roslyn/issues/41462 tracks adding this support
if (symbol.NullableAnnotation == NullableAnnotation.Annotated)
{
arrayTypeSyntax = SyntaxFactory.NullableType(arrayTypeSyntax);
}
#endif

return AddInformationTo(arrayTypeSyntax, symbol);
}
Expand Down Expand Up @@ -258,13 +252,10 @@ public override TypeSyntax VisitNamedType(INamedTypeSymbol symbol)
}
}

#if !CODE_STYLE // TODO: Remove the #if once NullableAnnotation is available.
// https://github.com/dotnet/roslyn/issues/41462 tracks adding this support
if (symbol.NullableAnnotation == NullableAnnotation.Annotated)
{
typeSyntax = AddInformationTo(SyntaxFactory.NullableType(typeSyntax), symbol);
}
#endif

return typeSyntax;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,12 +1102,7 @@ static ITypeSymbol MakeNullable(ITypeSymbol symbol, Compilation compilation)
}
else if (symbol.IsReferenceType)
{
#if CODE_STYLE
// TODO: Remove the #if once WithNullableAnnotation is available.
return symbol;
#else
return symbol.WithNullableAnnotation(NullableAnnotation.Annotated);
#endif
}
else // it's neither a value nor reference type, so is an unconstrained generic
{
Expand Down Expand Up @@ -1531,14 +1526,7 @@ private IEnumerable<TypeInferenceInfo> GetTypesForRecursivePattern(RecursivePatt
}

private static ImmutableArray<NullableAnnotation> GetNullableAnnotations(ImmutableArray<ITypeSymbol> elementTypes)
{
return
#if CODE_STYLE // TODO: Remove the #if once NullableAnnotation is available.
default;
#else
elementTypes.SelectAsArray(e => e.NullableAnnotation);
#endif
}
=> elementTypes.SelectAsArray(e => e.NullableAnnotation);

private IEnumerable<TypeInferenceInfo> InferTypeInLockStatement(LockStatementSyntax lockStatement, SyntaxToken? previousToken = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@

#nullable enable


namespace Microsoft.CodeAnalysis
{
internal static partial class NullableExtensions
{
public static ITypeSymbol? GetConvertedTypeWithAnnotatedNullability(this TypeInfo typeInfo)
=> typeInfo.ConvertedType
#if !CODE_STYLE // TODO: Remove the #if once WithNullableAnnotation is available.
?.WithNullableAnnotation(typeInfo.ConvertedNullability.Annotation)
#endif
;
=> typeInfo.ConvertedType?.WithNullableAnnotation(typeInfo.ConvertedNullability.Annotation);

public static ITypeSymbol? GetTypeWithAnnotatedNullability(this TypeInfo typeInfo)
=> typeInfo.Type
#if !CODE_STYLE // TODO: Remove the #if once WithNullableAnnotation is available.
?.WithNullableAnnotation(typeInfo.Nullability.Annotation)
#endif
;
=> typeInfo.Type?.WithNullableAnnotation(typeInfo.Nullability.Annotation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ private ImmutableArray<TypeInferenceInfo> Filter(IEnumerable<TypeInferenceInfo>
}

protected IEnumerable<TypeInferenceInfo> CreateResult(SpecialType type, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
=> CreateResult(Compilation.GetSpecialType(type)
#if !CODE_STYLE // TODO: remove this #if directive once the below public API is available in CodeStyle layer.
.WithNullableAnnotation(nullableAnnotation)
#endif
);
=> CreateResult(Compilation.GetSpecialType(type).WithNullableAnnotation(nullableAnnotation));

protected IEnumerable<TypeInferenceInfo> CreateResult(ITypeSymbol type)
=> type == null
Expand Down

0 comments on commit ef734e1

Please sign in to comment.