提交 e4163b02 编写于 作者: C CyrusNajmabadi

Merge remote-tracking branch 'upstream/master' into expressionBodySingleLine

......@@ -25,6 +25,15 @@
Roslyn provides open-source C# and Visual Basic compilers with rich code analysis APIs. It enables building code analysis tools with the same APIs that are used by Visual Studio.
### Language Design Discussion
We are now taking language feature discussion in other repositories:
- https://github.com/dotnet/csharplang for C# specific issues
- https://github.com/dotnet/vblang for VB-specific features
- https://github.com/dotnet/csharplang for features that affect both languages
Discussion about the transition of language design to the new repos is at https://github.com/dotnet/roslyn/issues/18002.
### Download C# and Visual Basic
Want to start developing in C# and Visual Basic? Download [Visual Studio 2015](https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx),
......
......@@ -1610,5 +1610,25 @@ void Foo()
}
}", ignoreTrivia: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)]
public async Task TestMissingOnUnderscore()
{
await TestMissingInRegularAndScriptAsync(
@"
using System;
class C
{
void M()
{
[|int|] _;
if (N(out _)
{
Console.WriteLine(_);
}
}
}");
}
}
}
\ No newline at end of file
......@@ -3,7 +3,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Tagging;
......@@ -61,25 +63,98 @@ internal async Task ProduceTagsAsync(TaggerContext<BraceHighlightTag> context, D
{
using (Logger.LogBlock(FunctionId.Tagger_BraceHighlighting_TagProducer_ProduceTags, context.CancellationToken))
{
await ProduceTagsForBracesAsync(context, document, snapshot, position, rightBrace: false).ConfigureAwait(false);
await ProduceTagsForBracesAsync(context, document, snapshot, position - 1, rightBrace: true).ConfigureAwait(false);
if (position >= 0 && position <= snapshot.Length)
{
var (bracesLeftOfPosition, bracesRightOfPosition) = await GetAllMatchingBracesAsync(
_braceMatcherService, document, position, context.CancellationToken).ConfigureAwait(false);
AddBraces(context, snapshot, bracesLeftOfPosition);
AddBraces(context, snapshot, bracesRightOfPosition);
}
}
}
private async Task ProduceTagsForBracesAsync(TaggerContext<BraceHighlightTag> context, Document document, ITextSnapshot snapshot, int position, bool rightBrace)
/// <summary>
/// Given code like ()^() (where ^ is the caret position), returns the two pairs of
/// matching braces on the left and the right of the position. Note: a brace matching
/// pair is only returned if the position is on the left-side of hte start brace, or the
/// right side of end brace. So, for example, if you have (^()), then only the inner
/// braces are returned as the position is not on the right-side of the outer braces.
///
/// This function also works for multi-character braces i.e. ([ ]) In this case,
/// the rule is that the position has to be on the left side of the start brace, or
/// inside the start brace (but not at the end). So, ^([ ]) will return this
/// as a brace match, as will (^[ ]). But ([^ ]) will not.
///
/// The same goes for the braces on the the left of the caret. i.e.: ([ ])^
/// will return the braces on the left, as will ([ ]^). But ([ ^]) will not.
/// </summary>
private static async Task<(BraceMatchingResult? leftOfPosition, BraceMatchingResult? rightOfPosition)> GetAllMatchingBracesAsync(
IBraceMatchingService service,
Document document,
int position,
CancellationToken cancellationToken)
{
if (position >= 0 && position <= snapshot.Length)
// These are the matching spans when checking the token to the right of the position.
var rightOfPosition = await service.GetMatchingBracesAsync(document, position, cancellationToken).ConfigureAwait(false);
// The braces to the right of the position should only be added if the position is
// actually within the span of the start brace. Note that this is what we want for
// single character braces as well as multi char braces. i.e. if the user has:
//
// ^{ } // then { and } are matching braces.
// {^ } // then { and } are not matching braces.
//
// ^<@ @> // then <@ and @> are matching braces.
// <^@ @> // then <@ and @> are matching braces.
// <@^ @> // then <@ and @> are not matching braces.
if (rightOfPosition.HasValue &&
!rightOfPosition.Value.LeftSpan.Contains(position))
{
var braces = await _braceMatcherService.GetMatchingBracesAsync(document, position, context.CancellationToken).ConfigureAwait(false);
if (braces.HasValue)
{
if ((!rightBrace && braces.Value.LeftSpan.Start == position) ||
(rightBrace && braces.Value.RightSpan.Start == position))
{
context.AddTag(snapshot.GetTagSpan(braces.Value.LeftSpan.ToSpan(), BraceHighlightTag.StartTag));
context.AddTag(snapshot.GetTagSpan(braces.Value.RightSpan.ToSpan(), BraceHighlightTag.EndTag));
}
}
// Not a valid match.
rightOfPosition = null;
}
if (position == 0)
{
// We're at the start of the document, can't find braces to the left of the position.
return (leftOfPosition: null, rightOfPosition);
}
// See if we're touching the end of some construct. i.e.:
//
// { }^
// <@ @>^
// <@ @^>
//
// But not
//
// { ^}
// <@ ^@>
var leftOfPosition = await service.GetMatchingBracesAsync(document, position - 1, cancellationToken).ConfigureAwait(false);
if (leftOfPosition.HasValue &&
position <= leftOfPosition.Value.RightSpan.End &&
position > leftOfPosition.Value.RightSpan.Start)
{
// Found a valid pair on the left of us.
return (leftOfPosition, rightOfPosition);
}
// No valid pair of braces on the left of us.
return (leftOfPosition: null, rightOfPosition);
}
private void AddBraces(
TaggerContext<BraceHighlightTag> context,
ITextSnapshot snapshot,
BraceMatchingResult? braces)
{
if (braces.HasValue)
{
context.AddTag(snapshot.GetTagSpan(braces.Value.LeftSpan.ToSpan(), BraceHighlightTag.StartTag));
context.AddTag(snapshot.GetTagSpan(braces.Value.RightSpan.ToSpan(), BraceHighlightTag.EndTag));
}
}
}
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
......@@ -13,14 +14,13 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.BraceMatching
[Export(typeof(IBraceMatchingService))]
internal class BraceMatchingService : IBraceMatchingService
{
private readonly List<Lazy<IBraceMatcher, LanguageMetadata>> _braceMatchers;
private readonly ImmutableArray<Lazy<IBraceMatcher, LanguageMetadata>> _braceMatchers;
[ImportingConstructor]
public BraceMatchingService(
[ImportMany] IEnumerable<Lazy<IBraceMatcher, LanguageMetadata>> braceMatchers)
{
////braceMatchers.RealizeImports();
_braceMatchers = braceMatchers.ToList();
_braceMatchers = braceMatchers.ToImmutableArray();
}
public async Task<BraceMatchingResult?> GetMatchingBracesAsync(Document document, int position, CancellationToken cancellationToken)
......
......@@ -47,11 +47,11 @@ internal static class IBraceMatchingServiceExtensions
}
else if (braces1.HasValue && position >= braces1.Value.RightSpan.Start && position < braces1.Value.RightSpan.End)
{
// { ^} -- return left span
// { ^} - return left span
return braces1.Value.LeftSpan;
}
return null;
}
}
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor.Implementation.BraceMatching;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
......@@ -24,7 +23,7 @@ protected async Task TestBraceHighlightingAsync(string markup, ParseOptions opti
WpfTestCase.RequireWpfFact($"{nameof(AbstractBraceHighlightingTests)}.{nameof(TestBraceHighlightingAsync)} creates asynchronous taggers");
var provider = new BraceHighlightingViewTaggerProvider(
workspace.GetService<IBraceMatchingService>(),
GetBraceMatchingService(workspace),
workspace.GetService<IForegroundNotificationService>(),
AggregateAsynchronousOperationListener.EmptyListeners);
......@@ -43,6 +42,9 @@ protected async Task TestBraceHighlightingAsync(string markup, ParseOptions opti
}
}
internal virtual IBraceMatchingService GetBraceMatchingService(TestWorkspace workspace)
=> workspace.GetService<IBraceMatchingService>();
protected abstract TestWorkspace CreateWorkspace(string markup, ParseOptions options);
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.UnitTests.BraceHighlighting
{
public class MultiCharacterBraceHighlightingTests : AbstractBraceHighlightingTests
{
protected override TestWorkspace CreateWorkspace(string markup, ParseOptions options)
=> TestWorkspace.Create(
NoCompilationConstants.LanguageName, compilationOptions: null, parseOptions: options, content: markup);
internal override IBraceMatchingService GetBraceMatchingService(TestWorkspace workspace)
=> new TestBraceMatchingService();
private ImmutableArray<TextSpan> GetSpans(BraceMatchingResult? result)
=> result.HasValue
? ImmutableArray.Create(result.Value.LeftSpan, result.Value.RightSpan)
: ImmutableArray<TextSpan>.Empty;
private class TestBraceMatchingService : IBraceMatchingService
{
public async Task<BraceMatchingResult?> GetMatchingBracesAsync(
Document document, int position, CancellationToken cancellationToken = default(CancellationToken))
{
var text = (await document.GetTextAsync(cancellationToken)).ToString();
var braces = GetMatchingBraces(text, position);
if (braces.HasValue)
{
Debug.Assert(text.Substring(braces.Value.LeftSpan.Start, braces.Value.LeftSpan.Length) == "<@");
Debug.Assert(text.Substring(braces.Value.RightSpan.Start, braces.Value.RightSpan.Length) == "@>");
}
return braces;
}
public BraceMatchingResult? GetMatchingBraces(
string text, int position)
{
if (position < text.Length)
{
var ch = text[position];
// Look for <@ @> depending on where the caret is.
// ^<@ @>
if (ch == '<')
{
Debug.Assert(text[position + 1] == '@');
var secondAt = text.IndexOf('@', position + 2);
return new BraceMatchingResult(new TextSpan(position, 2), new TextSpan(secondAt, 2));
}
// <^@ @> or <@ ^@>
if (ch == '@')
{
if (text[position - 1] == '<')
{
var secondAt = text.IndexOf('@', position + 1);
return new BraceMatchingResult(new TextSpan(position - 1, 2), new TextSpan(secondAt, 2));
}
else
{
Debug.Assert(text[position + 1] == '>');
var lessThan = text.LastIndexOf('<', position);
return new BraceMatchingResult(new TextSpan(lessThan, 2), new TextSpan(position, 2));
}
}
// <@ @^>
if (ch == '>')
{
Debug.Assert(text[position - 1] == '@');
var lessThan = text.LastIndexOf('<', position);
return new BraceMatchingResult(new TextSpan(lessThan, 2), new TextSpan(position - 1, 2));
}
}
return null;
}
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotOnBrace()
{
await TestBraceHighlightingAsync(
"$$ <@ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestOnLeftOfStartBrace()
{
await TestBraceHighlightingAsync(
"$$[|<@|] [|@>|]");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestInsideStartBrace()
{
await TestBraceHighlightingAsync(
"[|<$$@|] [|@>|]");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotOnRightOfStartBrace()
{
await TestBraceHighlightingAsync(
"<@$$ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotOnLeftOfCloseBrace()
{
await TestBraceHighlightingAsync(
"<@ $$@>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestInsideCloseBrace()
{
await TestBraceHighlightingAsync(
"[|<@|] [|@$$>|]");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestOnRightOfCloseBrace()
{
await TestBraceHighlightingAsync(
"[|<@|] [|@>$$|]");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotAfterBrace()
{
await TestBraceHighlightingAsync(
"<@ @> $$");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotOnBrace2()
{
await TestBraceHighlightingAsync(
"$$ <@ @><@ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestOnLeftOfStartBrace2()
{
await TestBraceHighlightingAsync(
"$$[|<@|] [|@>|]<@ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestInsideStartBrace2()
{
await TestBraceHighlightingAsync(
"[|<$$@|] [|@>|]<@ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotOnRightOfStartBrace2()
{
await TestBraceHighlightingAsync(
"<@$$ @><@ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotOnLeftOfCloseBrace2()
{
await TestBraceHighlightingAsync(
"<@ $$@><@ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestInsideCloseBrace3()
{
await TestBraceHighlightingAsync(
"[|<@|] [|@$$>|]<@ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestOnRightOfCloseBrace2()
{
await TestBraceHighlightingAsync(
"[|<@|] [|@>|]$$[|<@|] [|@>|]");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestInSecondBracePair()
{
await TestBraceHighlightingAsync(
"<@ @>[|<$$@|] [|@>|]");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotAfterSecondBracePairStart()
{
await TestBraceHighlightingAsync(
"<@ @><@$$ @>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotBeforeSecondBracePairEnd()
{
await TestBraceHighlightingAsync(
"<@ @><@ $$@>");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestInSecondBracePairEnd()
{
await TestBraceHighlightingAsync(
"<@ @>[|<@|] [|@$$>|]");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestAtSecondBracePairEnd()
{
await TestBraceHighlightingAsync(
"<@ @>[|<@|] [|@>|]$$");
}
[WorkItem(18050, "https://github.com/dotnet/roslyn/issues/18050")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BraceHighlighting)]
public async Task TestNotAfterSecondBracePairEnd()
{
await TestBraceHighlightingAsync(
"<@ @><@ @> $$");
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
......@@ -15,11 +16,6 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.BraceMatching
{
public abstract class AbstractBraceMatcherTests
{
private Document GetDocument(TestWorkspace workspace)
{
return workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id);
}
protected abstract TestWorkspace CreateWorkspaceFromCode(string code, ParseOptions options);
protected async Task TestAsync(string markup, string expectedCode, ParseOptions options = null)
......@@ -27,7 +23,7 @@ protected async Task TestAsync(string markup, string expectedCode, ParseOptions
using (var workspace = CreateWorkspaceFromCode(markup, options))
{
var position = workspace.Documents.Single().CursorPosition.Value;
var document = GetDocument(workspace);
var document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id);
var braceMatcher = workspace.GetService<IBraceMatchingService>();
var foundSpan = await braceMatcher.FindMatchingSpanAsync(document, position, CancellationToken.None);
......
......@@ -131,6 +131,7 @@
<Compile Include="BlindAggregatorFactory.cs" />
<Compile Include="BlockCommentEditing\AbstractBlockCommentEditingTests.cs" />
<Compile Include="BraceHighlighting\AbstractBraceHighlightingTests.cs" />
<Compile Include="BraceHighlighting\MultiCharacterBraceHighlightingTests.cs" />
<Compile Include="BraceMatching\AbstractBraceMatcherTests.cs" />
<Compile Include="CallHierarchy\CallHierarchyTestState.cs" />
<Compile Include="ChangeSignature\AbstractChangeSignatureTests.cs" />
......
......@@ -9,13 +9,11 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Threading;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.VisualBasic;
......@@ -29,7 +27,6 @@
namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
{
using System.Threading.Tasks;
using RelativePathResolver = WORKSPACES::Microsoft.CodeAnalysis.RelativePathResolver;
public partial class TestWorkspace
......
......@@ -113,6 +113,13 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context, INamedTypeSymb
var identifierName = (IdentifierNameSyntax)argumentExpression;
// Don't offer to inline variables named "_". It can cause is to create a discard symbol
// which would cause a break.
if (identifierName.Identifier.ValueText == "_")
{
return;
}
var containingStatement = argumentExpression.FirstAncestorOrSelf<StatementSyntax>();
if (containingStatement == null)
{
......
......@@ -90,7 +90,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpFeaturesResources.Inline_temporary_variable, createChangedDocument)
: base(FeaturesResources.Use_pattern_matching, createChangedDocument)
{
}
}
......
......@@ -97,7 +97,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpFeaturesResources.Inline_temporary_variable, createChangedDocument)
: base(FeaturesResources.Use_pattern_matching, createChangedDocument)
{
}
}
......
......@@ -10,12 +10,13 @@
<BinariesPath>$(RepoRoot)Binaries\$(Configuration)</BinariesPath>
<RoslynNuGetApiKey Condition="'$(RoslynNuGetApiKey)' == ''">"no key"</RoslynNuGetApiKey>
<PublishAssetsArgs Condition="'$(SkipPublish)' == 'true'">-test</PublishAssetsArgs>
<SignRoslynArgs>-msbuildPath "$(MSBuildBinPath)\msbuild.exe"</SignRoslynArgs>
</PropertyGroup>
<!-- Non-official builds / local testing have different defaults -->
<PropertyGroup Condition="'$(OfficialBuild)' != 'true'">
<BranchName Condition="'$(BranchName)' == ''">master</BranchName>
<SignRoslynArgs>-test -msbuildPath "$(MSBuildBinPath)\msbuild.exe"</SignRoslynArgs>
<SignRoslynArgs>$(SignRoslynArgs) -test</SignRoslynArgs>
<PublishAssetsArgs>-test</PublishAssetsArgs>
<CopyInsertionFileArgs>-test</CopyInsertionFileArgs>
<SetupStep2Properties>FinalizeValidate=false;ManifestPublishUrl=https://vsdrop.corp.microsoft.com/file/v1/Products/DevDiv/dotnet/roslyn/master/20160729.6</SetupStep2Properties>
......
......@@ -624,7 +624,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return list
End Function
Private Shared s_fieldModifiers As DeclarationModifiers = DeclarationModifiers.Const Or DeclarationModifiers.[New] Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.Static
Private Shared s_fieldModifiers As DeclarationModifiers = DeclarationModifiers.Const Or DeclarationModifiers.[New] Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.Static Or DeclarationModifiers.WithEvents
Private Shared s_methodModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.Async Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.Partial Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual
Private Shared s_constructorModifiers As DeclarationModifiers = DeclarationModifiers.Static
Private Shared s_propertyModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.WriteOnly Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual
......@@ -2468,6 +2468,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return DirectCast(declaration, EnumBlockSyntax).EnumStatement.Modifiers
Case SyntaxKind.EnumStatement
Return DirectCast(declaration, EnumStatementSyntax).Modifiers
Case SyntaxKind.ModuleBlock
Return DirectCast(declaration, ModuleBlockSyntax).ModuleStatement.Modifiers
Case SyntaxKind.ModuleStatement
Return DirectCast(declaration, ModuleStatementSyntax).Modifiers
Case SyntaxKind.DelegateFunctionStatement,
SyntaxKind.DelegateSubStatement
Return DirectCast(declaration, DelegateStatementSyntax).Modifiers
......@@ -2538,6 +2542,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return DirectCast(declaration, EnumBlockSyntax).WithEnumStatement(DirectCast(declaration, EnumBlockSyntax).EnumStatement.WithModifiers(tokens))
Case SyntaxKind.EnumStatement
Return DirectCast(declaration, EnumStatementSyntax).WithModifiers(tokens)
Case SyntaxKind.ModuleBlock
Return DirectCast(declaration, ModuleBlockSyntax).WithModuleStatement(DirectCast(declaration, ModuleBlockSyntax).ModuleStatement.WithModifiers(tokens))
Case SyntaxKind.ModuleStatement
Return DirectCast(declaration, ModuleStatementSyntax).WithModifiers(tokens)
Case SyntaxKind.DelegateFunctionStatement,
SyntaxKind.DelegateSubStatement
Return DirectCast(declaration, DelegateStatementSyntax).WithModifiers(tokens)
......@@ -2618,38 +2626,40 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Private Function CanHaveAccessibility(declaration As SyntaxNode) As Boolean
Select Case declaration.Kind
Case SyntaxKind.ClassBlock,
SyntaxKind.ClassStatement,
SyntaxKind.StructureBlock,
SyntaxKind.StructureStatement,
SyntaxKind.InterfaceBlock,
SyntaxKind.InterfaceStatement,
SyntaxKind.EnumBlock,
SyntaxKind.EnumStatement,
SyntaxKind.DelegateFunctionStatement,
SyntaxKind.DelegateSubStatement,
SyntaxKind.FieldDeclaration,
SyntaxKind.FunctionBlock,
SyntaxKind.SubBlock,
SyntaxKind.ConstructorBlock,
SyntaxKind.FunctionStatement,
SyntaxKind.SubStatement,
SyntaxKind.SubNewStatement,
SyntaxKind.PropertyBlock,
SyntaxKind.PropertyStatement,
SyntaxKind.OperatorBlock,
SyntaxKind.OperatorStatement,
SyntaxKind.EventBlock,
SyntaxKind.EventStatement,
SyntaxKind.GetAccessorBlock,
SyntaxKind.GetAccessorStatement,
SyntaxKind.SetAccessorBlock,
SyntaxKind.SetAccessorStatement,
SyntaxKind.AddHandlerAccessorBlock,
SyntaxKind.AddHandlerAccessorStatement,
SyntaxKind.RemoveHandlerAccessorBlock,
SyntaxKind.RemoveHandlerAccessorStatement,
SyntaxKind.RaiseEventAccessorBlock,
SyntaxKind.RaiseEventAccessorStatement
SyntaxKind.ClassStatement,
SyntaxKind.StructureBlock,
SyntaxKind.StructureStatement,
SyntaxKind.InterfaceBlock,
SyntaxKind.InterfaceStatement,
SyntaxKind.EnumBlock,
SyntaxKind.EnumStatement,
SyntaxKind.ModuleBlock,
SyntaxKind.ModuleStatement,
SyntaxKind.DelegateFunctionStatement,
SyntaxKind.DelegateSubStatement,
SyntaxKind.FieldDeclaration,
SyntaxKind.FunctionBlock,
SyntaxKind.SubBlock,
SyntaxKind.ConstructorBlock,
SyntaxKind.FunctionStatement,
SyntaxKind.SubStatement,
SyntaxKind.SubNewStatement,
SyntaxKind.PropertyBlock,
SyntaxKind.PropertyStatement,
SyntaxKind.OperatorBlock,
SyntaxKind.OperatorStatement,
SyntaxKind.EventBlock,
SyntaxKind.EventStatement,
SyntaxKind.GetAccessorBlock,
SyntaxKind.GetAccessorStatement,
SyntaxKind.SetAccessorBlock,
SyntaxKind.SetAccessorStatement,
SyntaxKind.AddHandlerAccessorBlock,
SyntaxKind.AddHandlerAccessorStatement,
SyntaxKind.RemoveHandlerAccessorBlock,
SyntaxKind.RemoveHandlerAccessorStatement,
SyntaxKind.RaiseEventAccessorBlock,
SyntaxKind.RaiseEventAccessorStatement
Return True
Case Else
Return False
......
......@@ -774,8 +774,8 @@ End Sub</x>.Value)
<x>Public fld As Integer</x>.Value)
VerifySyntax(Of FieldDeclarationSyntax)(
_g.FieldDeclaration("fld", _g.TypeExpression(SpecialType.System_Int32), modifiers:=DeclarationModifiers.Static Or DeclarationModifiers.ReadOnly),
<x>Shared ReadOnly fld As Integer</x>.Value)
_g.FieldDeclaration("fld", _g.TypeExpression(SpecialType.System_Int32), modifiers:=DeclarationModifiers.Static Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.WithEvents),
<x>Shared ReadOnly WithEvents fld As Integer</x>.Value)
End Sub
<Fact>
......@@ -2301,7 +2301,7 @@ End Class
Public Sub TestGetAccessibility()
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.ClassDeclaration("c", accessibility:=Accessibility.Internal)))
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.StructDeclaration("s", accessibility:=Accessibility.Internal)))
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.EnumDeclaration("i", accessibility:=Accessibility.Internal)))
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.InterfaceDeclaration("i", accessibility:=Accessibility.Internal)))
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.EnumDeclaration("e", accessibility:=Accessibility.Internal)))
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.DelegateDeclaration("d", accessibility:=Accessibility.Internal)))
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.MethodDeclaration("m", accessibility:=Accessibility.Internal)))
......@@ -2318,6 +2318,11 @@ End Class
Assert.Equal(Accessibility.NotApplicable, _g.GetAccessibility(_g.LocalDeclarationStatement(_g.IdentifierName("t"), "loc")))
Assert.Equal(Accessibility.NotApplicable, _g.GetAccessibility(_g.Attribute("a")))
Assert.Equal(Accessibility.NotApplicable, _g.GetAccessibility(SyntaxFactory.TypeParameter("tp")))
Dim m = SyntaxFactory.ModuleBlock(
SyntaxFactory.ModuleStatement("module2").
WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword))))
Assert.Equal(Accessibility.Public, _g.GetAccessibility(m))
End Sub
<Fact>
......@@ -2341,6 +2346,11 @@ End Class
Assert.Equal(Accessibility.NotApplicable, _g.GetAccessibility(_g.WithAccessibility(_g.LocalDeclarationStatement(_g.IdentifierName("t"), "loc"), Accessibility.Private)))
Assert.Equal(Accessibility.NotApplicable, _g.GetAccessibility(_g.WithAccessibility(_g.Attribute("a"), Accessibility.Private)))
Assert.Equal(Accessibility.NotApplicable, _g.GetAccessibility(_g.WithAccessibility(SyntaxFactory.TypeParameter("tp"), Accessibility.Private)))
Dim m = SyntaxFactory.ModuleBlock(
SyntaxFactory.ModuleStatement("module2").
WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword))))
Assert.Equal(Accessibility.Internal, _g.GetAccessibility(_g.WithAccessibility(m, Accessibility.Internal)))
End Sub
<Fact>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册