提交 50e27eba 编写于 作者: T Tanner Gooding

Merge pull request #3493 from tannergooding/master

[Automated] Merge 'stabilization' into 'master'
......@@ -16,9 +16,7 @@ call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd
REM Build the compiler so we can self host it for the full build
src\.nuget\NuGet.exe restore %RoslynRoot%/src/Toolset.sln -packagesdirectory packages
msbuild /nologo /v:m /m %RoslynRoot%/src/Compilers/Core/VBCSCompiler/VBCSCompiler.csproj /p:Configuration=%BuildConfiguration%
msbuild /nologo /v:m /m %RoslynRoot%/src/Compilers/CSharp/csc2/csc2.csproj /p:Configuration=%BuildConfiguration%
msbuild /nologo /v:m /m %RoslynRoot%/src/Compilers/VisualBasic/vbc2/vbc2.csproj /p:Configuration=%BuildConfiguration%
msbuild /nologo /v:m /m %RoslynRoot%/src/Toolset.sln /p:Configuration=%BuildConfiguration%
mkdir %RoslynRoot%\Binaries\Bootstrap
move Binaries\%BuildConfiguration%\* %RoslynRoot%\Binaries\Bootstrap
......@@ -32,6 +30,13 @@ if ERRORLEVEL 1 (
exit /b 1
)
msbuild /v:m /m /p:BootstrapBuildPath=%RoslynRoot%\Binaries\Bootstrap src/Samples/Samples.sln /p:CIBuild=true /p:Configuration=%BuildConfiguration%
if ERRORLEVEL 1 (
taskkill /F /IM vbcscompiler.exe
echo Build failed
exit /b 1
)
REM Kill any instances of VBCSCompiler.exe to release locked files;
REM otherwise future CI runs may fail while trying to delete those files.
taskkill /F /IM vbcscompiler.exe
......@@ -44,8 +49,4 @@ exit /b 0
@echo Usage: cibuild.cmd [/debug^|/release]
@echo /debug Perform debug build. This is the default.
@echo /release Perform release build
<<<<<<< HEAD
@goto :eof
=======
@goto :eof
>>>>>>> origin/stabilization
@goto :eof
\ No newline at end of file
......@@ -346,7 +346,7 @@ private BoundLabeledStatement BindLabeled(LabeledStatementSyntax node, Diagnosti
// result.Symbols can be empty in some malformed code, e.g. when a labeled statement is used an embedded statement in an if or foreach statement
// In this case we create new label symbol on the fly, and an error is reported by parser
var symbol = result.Symbols.Count != 0 ?
var symbol = result.Symbols.Count > 0 && result.IsMultiViable ?
(LabelSymbol)result.Symbols.First() :
new SourceLabelSymbol((MethodSymbol)ContainingMemberOrLambda, node.Identifier);
......
......@@ -1027,6 +1027,8 @@ public override bool DeclaresTheObjectClass
return _assembly.DeclaresTheObjectClass;
}
}
public override Compilation SourceCompilation => null;
}
private sealed class AssemblyDataForCompilation : AssemblyDataForMetadataOrCompilation
......@@ -1130,6 +1132,8 @@ public override bool DeclaresTheObjectClass
return _compilation.DeclaresTheObjectClass;
}
}
public override Compilation SourceCompilation => _compilation;
}
/// <summary>
......
......@@ -22455,5 +22455,35 @@ static void Main()
Diagnostic(ErrorCode.ERR_IllegalStatement, "x?.ToString()[1]").WithLocation(10, 9)
);
}
[Fact]
[WorkItem(1179322, "DevDiv")]
public void LabelSameNameAsParameter()
{
var text = @"
class Program
{
static object M(object obj, object value)
{
if (((string)obj).Length == 0) value: new Program();
}
}
";
var compilation = CreateCompilationWithMscorlib(text);
compilation.GetParseDiagnostics().Verify(
// (6,41): error CS1023: Embedded statement cannot be a declaration or labeled statement
// if (((string)obj).Length == 0) value: new Program();
Diagnostic(ErrorCode.ERR_BadEmbeddedStmt, "value: new Program();").WithLocation(6, 41));
// Make sure the compiler can handle producing method body diagnostics for this pattern when
// queriied via an API (command line compile would exit after parse errors were reported).
compilation.GetMethodBodyDiagnostics().Verify(
// (6,41): warning CS0164: This label has not been referenced
// if (((string)obj).Length == 0) value: new Program();
Diagnostic(ErrorCode.WRN_UnreferencedLabel, "value").WithLocation(6, 41),
// (4,19): error CS0161: 'Program.M(object, object)': not all code paths return a value
// static object M(object obj, object value)
Diagnostic(ErrorCode.ERR_ReturnExpected, "M").WithArguments("Program.M(object, object)").WithLocation(4, 19));
}
}
}
......@@ -23,6 +23,34 @@ public class ReferenceManagerTests : CSharpTestBase
WithCryptoKeyFile(SigningTestHelpers.KeyPairFile).
WithStrongNameProvider(new SigningTestHelpers.VirtualizedStrongNameProvider(ImmutableArray.Create<string>()));
[ClrOnlyFact(ClrOnlyReason.Signing)]
public void WinRtCompilationReferences()
{
var ifaceDef = CreateCompilationWithMscorlib(
@"
public interface ITest
{
}", options: TestOptions.DebugWinMD, assemblyName: "ITest");
ifaceDef.VerifyDiagnostics();
var ifaceImageRef = ifaceDef.EmitToImageReference();
var wimpl = AssemblyMetadata.CreateFromImage(TestResources.WinRt.WImpl).GetReference(display: "WImpl");
var implDef2 = CreateCompilationWithMscorlib(
@"
public class C
{
public static void Main()
{
ITest test = new WImpl();
}
}", references: new MetadataReference[] { ifaceDef.ToMetadataReference(), wimpl },
options: TestOptions.DebugExe);
implDef2.VerifyDiagnostics();
}
[ClrOnlyFact(ClrOnlyReason.Signing)]
public void VersionUnification_SymbolUsed()
{
......
......@@ -218,3 +218,4 @@ internal virtual bool ApplyUnificationPolicies(ref AssemblyIdentity reference, r
}
}
}
......@@ -57,6 +57,12 @@ internal abstract class AssemblyData
public abstract bool IsLinked { get; }
public abstract bool DeclaresTheObjectClass { get; }
/// <summary>
/// Get the source compilation backing this assembly, if one exists.
/// Returns null otherwise.
/// </summary>
public abstract Compilation SourceCompilation { get; }
}
}
}
......@@ -144,6 +144,8 @@ public override bool DeclaresTheObjectClass
return false;
}
}
public override Compilation SourceCompilation => null;
}
}
}
......@@ -10,6 +10,7 @@
namespace Microsoft.CodeAnalysis
{
using System.Reflection;
using MetadataOrDiagnostic = System.Object;
/// <summary>
......@@ -850,6 +851,32 @@ private static PortableExecutableReference ResolveReferenceDirective(string refe
}
}
// In the IDE it is possible the reference we're looking for is a
// compilation reference to a source assembly. However, if the reference
// is of ContentType WindowsRuntime then the compilation will never
// match since all C#/VB WindowsRuntime compilations output .winmdobjs,
// not .winmds, and the ContentType of a .winmdobj is Default.
// If this is the case, we want to ignore the ContentType mismatch and
// allow the compilation to match the reference.
if (reference.ContentType == AssemblyContentType.WindowsRuntime)
{
for (int i = definitionOffset; i < definitions.Length; i++)
{
var definition = definitions[i].Identity;
var sourceCompilation = definitions[i].SourceCompilation;
if (definition.ContentType == AssemblyContentType.Default &&
sourceCompilation?.Options.OutputKind == OutputKind.WindowsRuntimeMetadata &&
AssemblyIdentityComparer.SimpleNameComparer.Equals(reference.Name, definition.Name) &&
reference.Version.Equals(definition.Version) &&
reference.IsRetargetable == definition.IsRetargetable &&
AssemblyIdentityComparer.CultureComparer.Equals(reference.CultureName, definition.CultureName) &&
AssemblyIdentity.KeysEqual(reference, definition))
{
return new AssemblyReferenceBinding(reference, i);
}
}
}
// As in the native compiler (see IMPORTER::MapAssemblyRefToAid), we compare against the
// compilation (i.e. source) assembly as a last resort. We follow the native approach of
// skipping the public key comparison since we have yet to compute it.
......
......@@ -401,6 +401,8 @@
<None Include="packages.config" />
<None Include="SymbolsTests\netModule\hash_module.cs" />
<None Include="SymbolsTests\NoPia\MissingPIAAttributes.dll" />
<None Include="WinRt\WImpl.il" />
<None Include="WinRt\WImpl.winmd" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Analyzers\AnalyzerTests.resx">
......
......@@ -5,3 +5,4 @@ ilasm W1.il /mdv="WindowsRuntime 1.2" /msv:1.1 /dll /out=W1.winmd
ilasm W2.il /mdv="WindowsRuntime 1.2" /msv:1.1 /dll /out=W2.winmd
ilasm WB.il /mdv="WindowsRuntime 1.2" /msv:1.1 /dll /out=WB.winmd
ilasm WB_Version1.il /mdv="WindowsRuntime 1.2" /msv:1.1 /dll /out=WB_Version1.winmd
ilasm WImpl.il /mdv="WindowsRuntime 1.3" /msv:1.1 /dll /out=WImpl.winmd
.assembly extern windowsruntime ITest {}
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 255:255:255:255
}
.assembly windowsruntime WImpl
{
.hash algorithm 0x00008004
.ver 255:255:255:255
}
.module WImpl.winmd
.class public auto ansi windowsruntime sealed WImpl
extends System.Object
implements [ITest]ITest
{
.method public hidebysig specialname rtspecialname
instance void .ctor() runtime managed
{
}
}
\ No newline at end of file
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.18326
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
......@@ -104,6 +104,16 @@ Namespace TestResources
End Get
End Property
'''<summary>
''' Looks up a localized resource of type System.Byte[].
'''</summary>
Public Shared ReadOnly Property WImpl() As Byte()
Get
Dim obj As Object = ResourceManager.GetObject("WImpl", resourceCulture)
Return CType(obj,Byte())
End Get
End Property
'''<summary>
''' Looks up a localized resource of type System.Byte[].
'''</summary>
......
......@@ -147,4 +147,7 @@
<data name="WinMDPrefixing_dump" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>WinMDPrefixing.ildump;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="WImpl" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>WImpl.winmd;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
......@@ -758,13 +758,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim methodSym = DirectCast(implementingMember, SourceMemberMethodSymbol)
Dim diagbag = DiagnosticBag.GetInstance()
Dim boundClause = methodSym.BindSingleHandlesClause(handlesClause,
binder,
diagbag,
eventSymbolBuilder,
containerSymbolBuilder,
propertySymbolBuilder,
resultKind)
methodSym.BindSingleHandlesClause(handlesClause,
binder,
diagbag,
eventSymbolBuilder,
containerSymbolBuilder,
propertySymbolBuilder,
resultKind)
diagbag.Free()
End If
......
......@@ -869,6 +869,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return _assembly.DeclaresTheObjectClass
End Get
End Property
Public Overrides ReadOnly Property SourceCompilation As Compilation
Get
Return Nothing
End Get
End Property
End Class
Private NotInheritable Class AssemblyDataForCompilation
......@@ -955,6 +961,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return _compilation.DeclaresTheObjectClass
End Get
End Property
Public Overrides ReadOnly Property SourceCompilation As Compilation
Get
Return _compilation
End Get
End Property
End Class
''' <summary>
......
......@@ -743,6 +743,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
diagBag)
End If
Select Case ContainingType.TypeKind
Case TypeKind.Interface, TypeKind.Structure, TypeKind.Enum, TypeKind.Delegate
' Handles clause is invalid in this context.
Return Nothing
Case TypeKind.Class, TypeKind.Module
' Valid context
Case Else
Debug.Assert(False)
End Select
Dim receiverOpt As BoundExpression = Nothing
' synthesize delegate creation (may involve relaxation)
......
......@@ -2100,5 +2100,114 @@ End Structure
}
]]>)
End Sub
<Fact, WorkItem(3448, "https://github.com/dotnet/roslyn/issues/3448")>
Public Sub HandlesInAnInterface()
Dim compilation = CreateCompilationWithMscorlibAndVBRuntime(
<compilation>
<file name="a.vb"><![CDATA[
Interface I
Event E()
Sub M() Handles Me.E
End Interface
]]></file>
</compilation>, options:=TestOptions.DebugDll)
Dim expected = <expected>
BC30270: 'Handles' is not valid on an interface method declaration.
Sub M() Handles Me.E
~~~~~~~~~~~~
</expected>
compilation.AssertTheseDiagnostics(expected)
compilation.AssertTheseEmitDiagnostics(expected)
Dim tree = compilation.SyntaxTrees.Single()
Dim node = tree.GetRoot().DescendantNodes().OfType(Of IdentifierNameSyntax)().Where(Function(n) n.Identifier.ValueText = "E").Single()
Assert.Equal("Me.E", node.Parent.ToString())
Dim semanticModel = compilation.GetSemanticModel(tree)
Dim symbolInfo = semanticModel.GetSymbolInfo(node)
Assert.Equal("Event I.E()", symbolInfo.Symbol.ToTestDisplayString())
End Sub
<Fact, WorkItem(3448, "https://github.com/dotnet/roslyn/issues/3448")>
Public Sub HandlesInAStruct()
Dim compilation = CreateCompilationWithMscorlibAndVBRuntime(
<compilation>
<file name="a.vb"><![CDATA[
Structure S
Event E()
Sub M() Handles Me.E
End Sub
End Structure
]]></file>
</compilation>, options:=TestOptions.DebugDll)
Dim expected = <expected>
BC30728: Methods declared in structures cannot have 'Handles' clauses.
Sub M() Handles Me.E
~
</expected>
compilation.AssertTheseDiagnostics(expected)
compilation.AssertTheseEmitDiagnostics(expected)
Dim tree = compilation.SyntaxTrees.Single()
Dim node = tree.GetRoot().DescendantNodes().OfType(Of IdentifierNameSyntax)().Where(Function(n) n.Identifier.ValueText = "E").Single()
Assert.Equal("Me.E", node.Parent.ToString())
Dim semanticModel = compilation.GetSemanticModel(tree)
Dim symbolInfo = semanticModel.GetSymbolInfo(node)
Assert.Equal("Event S.E()", symbolInfo.Symbol.ToTestDisplayString())
End Sub
<Fact, WorkItem(3448, "https://github.com/dotnet/roslyn/issues/3448")>
Public Sub HandlesInAnEnum()
Dim compilation = CreateCompilationWithMscorlibAndVBRuntime(
<compilation>
<file name="a.vb"><![CDATA[
Enum E1
'Event E()
Sub M() Handles Me.E
End Sub
End Enum
]]></file>
</compilation>, options:=TestOptions.DebugDll)
Dim expected = <expected>
BC30185: 'Enum' must end with a matching 'End Enum'.
Enum E1
~~~~~~~
BC30280: Enum 'E1' must contain at least one member.
Enum E1
~~
BC30619: Statement cannot appear within an Enum body. End of Enum assumed.
Sub M() Handles Me.E
~~~~~~~~~~~~~~~~~~~~
BC30590: Event 'E' cannot be found.
Sub M() Handles Me.E
~
BC30184: 'End Enum' must be preceded by a matching 'Enum'.
End Enum
~~~~~~~~
</expected>
compilation.AssertTheseDiagnostics(expected)
compilation.AssertTheseEmitDiagnostics(expected)
Dim tree = compilation.SyntaxTrees.Single()
Dim node = tree.GetRoot().DescendantNodes().OfType(Of IdentifierNameSyntax)().Where(Function(n) n.Identifier.ValueText = "E").Single()
Assert.Equal("Me.E", node.Parent.ToString())
Dim semanticModel = compilation.GetSemanticModel(tree)
Dim symbolInfo = semanticModel.GetSymbolInfo(node)
Assert.Null(symbolInfo.Symbol)
Assert.Equal(0, symbolInfo.CandidateSymbols.Length)
End Sub
End Class
End Namespace
......@@ -448,6 +448,207 @@ End Class
Item("CancelKeyPress", Glyph.EventPublic, hasNavigationSymbolId:=False)}))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.NavigationBar), WorkItem(1185589)>
Public Sub WithEventsField_EventsFromInheritedInterfaces()
AssertItemsAre(
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Interface I1
Event I1Event(sender As Object, e As EventArgs)
End Interface
Interface I2
Event I2Event(sender As Object, e As EventArgs)
End Interface
Interface I3
Inherits I1, I2
Event I3Event(sender As Object, e As EventArgs)
End Interface
Class Test
WithEvents i3 As I3
End Class
</Document>
</Project>
</Workspace>,
Item("I1", Glyph.InterfaceInternal, bolded:=True, children:={
Item("I1Event", Glyph.EventPublic, bolded:=True)}),
Item("I2", Glyph.InterfaceInternal, bolded:=True, children:={
Item("I2Event", Glyph.EventPublic, bolded:=True)}),
Item("I3", Glyph.InterfaceInternal, bolded:=True, children:={
Item("I3Event", Glyph.EventPublic, bolded:=True)}),
Item("Test", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}),
Item("i3", Glyph.FieldPrivate, hasNavigationSymbolId:=False, indent:=1, children:={
Item("I1Event", Glyph.EventPublic, hasNavigationSymbolId:=False),
Item("I2Event", Glyph.EventPublic, hasNavigationSymbolId:=False),
Item("I3Event", Glyph.EventPublic, hasNavigationSymbolId:=False)}))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.NavigationBar), WorkItem(1185589), WorkItem(530506)>
Public Sub DoNotIncludeShadowedEvents()
AssertItemsAre(
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Class B
Event E(sender As Object, e As EventArgs)
End Class
Class C
Inherits B
Shadows Event E(sender As Object, e As EventArgs)
End Class
Class Test
WithEvents c As C
End Class
</Document>
</Project>
</Workspace>,
Item("B", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False),
Item("E", Glyph.EventPublic, bolded:=True)}),
Item(String.Format(VBEditorResources.Events, "B"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E", Glyph.EventPublic, hasNavigationSymbolId:=False)}),
Item("C", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False),
Item("E", Glyph.EventPublic, bolded:=True)}),
Item(String.Format(VBEditorResources.Events, "C"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E", Glyph.EventPublic, hasNavigationSymbolId:=False)}), ' Only one E under the "(C Events)" node
Item("Test", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}),
Item("c", Glyph.FieldPrivate, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E", Glyph.EventPublic, hasNavigationSymbolId:=False)})) ' Only one E for WithEvents handling
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.NavigationBar), WorkItem(1185589), WorkItem(530506)>
Public Sub EventList_EnsureInternalEventsInEventListAndInInheritedEventList()
AssertItemsAre(
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Class C
Event E()
End Class
Class D
Inherits C
End Class
</Document>
</Project>
</Workspace>,
Item("C", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False),
Item("E", Glyph.EventPublic, bolded:=True)}),
Item(String.Format(VBEditorResources.Events, "C"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E", Glyph.EventPublic, hasNavigationSymbolId:=False)}),
Item("D", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}),
Item(String.Format(VBEditorResources.Events, "D"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E", Glyph.EventPublic, hasNavigationSymbolId:=False)}))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.NavigationBar), WorkItem(1185589), WorkItem(530506)>
Public Sub EventList_EnsurePrivateEventsInEventListButNotInInheritedEventList()
AssertItemsAre(
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Class C
Private Event E()
End Class
Class D
Inherits C
End Class
</Document>
</Project>
</Workspace>,
Item("C", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False),
Item("E", Glyph.EventPrivate, bolded:=True)}),
Item(String.Format(VBEditorResources.Events, "C"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E", Glyph.EventPrivate, hasNavigationSymbolId:=False)}),
Item("D", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.NavigationBar), WorkItem(1185589), WorkItem(530506)>
Public Sub EventList_TestAccessibilityThroughNestedAndDerivedTypes()
AssertItemsAre(
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Class C
Public Event E0()
Protected Event E1()
Private Event E2()
Class N1
Class N2
Inherits C
End Class
End Class
End Class
Class D2
Inherits C
End Class
Class T
WithEvents c As C
End Class
</Document>
</Project>
</Workspace>,
Item("C", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False),
Item("E0", Glyph.EventPublic, bolded:=True),
Item("E1", Glyph.EventProtected, bolded:=True),
Item("E2", Glyph.EventPrivate, bolded:=True)}),
Item(String.Format(VBEditorResources.Events, "C"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E0", Glyph.EventPublic, hasNavigationSymbolId:=False),
Item("E1", Glyph.EventProtected, hasNavigationSymbolId:=False),
Item("E2", Glyph.EventPrivate, hasNavigationSymbolId:=False)}),
Item("D2", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}),
Item(String.Format(VBEditorResources.Events, "D2"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E0", Glyph.EventPublic, hasNavigationSymbolId:=False),
Item("E1", Glyph.EventProtected, hasNavigationSymbolId:=False)}),
Item("N1 (C)", Glyph.ClassPublic, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}),
Item("N2 (C.N1)", Glyph.ClassPublic, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}),
Item(String.Format(VBEditorResources.Events, "N2"), Glyph.EventPublic, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E0", Glyph.EventPublic, hasNavigationSymbolId:=False),
Item("E1", Glyph.EventProtected, hasNavigationSymbolId:=False),
Item("E2", Glyph.EventPrivate, hasNavigationSymbolId:=False)}),
Item("T", Glyph.ClassInternal, bolded:=True, children:={
Item(NavigationItemNew, Glyph.MethodPublic, hasNavigationSymbolId:=False),
Item("Finalize", Glyph.MethodProtected, hasNavigationSymbolId:=False)}),
Item("c", Glyph.FieldPrivate, hasNavigationSymbolId:=False, indent:=1, children:={
Item("E0", Glyph.EventPublic, hasNavigationSymbolId:=False)}))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)>
Public Sub GenerateEventHandler()
AssertGeneratedResultIs(
......
......@@ -45,7 +45,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Dim semanticModel = Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False)
Contract.ThrowIfNull(semanticModel)
Dim types = GetTypesInFile(semanticModel, cancellationToken)
Dim typesAndDeclarations = GetTypesAndDeclarationsInFile(semanticModel, cancellationToken)
Dim typeItems As New List(Of NavigationBarItem)
Dim typeSymbolIndexProvider As New NavigationBarSymbolIdIndexProvider(caseSensitive:=False)
......@@ -53,8 +53,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Dim symbolDeclarationService = document.GetLanguageService(Of ISymbolDeclarationService)
Dim workspaceSupportsDocumentChanges = document.Project.Solution.Workspace.CanApplyChange(ApplyChangesKind.ChangeDocument)
For Each typeSymbol In types
typeItems.AddRange(CreateItemsForType(typeSymbol, typeSymbolIndexProvider.GetIndexForSymbolId(typeSymbol.GetSymbolKey()), semanticModel, workspaceSupportsDocumentChanges, symbolDeclarationService, cancellationToken))
For Each typeAndDeclaration In typesAndDeclarations
Dim type = typeAndDeclaration.Item1
Dim position = typeAndDeclaration.Item2.SpanStart
typeItems.AddRange(CreateItemsForType(type, position, typeSymbolIndexProvider.GetIndexForSymbolId(type.GetSymbolKey()), semanticModel, workspaceSupportsDocumentChanges, symbolDeclarationService, cancellationToken))
Next
Return typeItems
......@@ -65,23 +67,23 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Return TypeOf item IsNot AbstractGenerateCodeItem
End Function
Private Function GetTypesInFile(semanticModel As SemanticModel, cancellationToken As CancellationToken) As IEnumerable(Of INamedTypeSymbol)
Private Function GetTypesAndDeclarationsInFile(semanticModel As SemanticModel, cancellationToken As CancellationToken) As IEnumerable(Of Tuple(Of INamedTypeSymbol, SyntaxNode))
Try
Dim types As New HashSet(Of INamedTypeSymbol)
Dim typesAndDeclarations As New Dictionary(Of INamedTypeSymbol, SyntaxNode)
Dim nodesToVisit As New Stack(Of SyntaxNode)
nodesToVisit.Push(DirectCast(semanticModel.SyntaxTree.GetRoot(cancellationToken), SyntaxNode))
Do Until nodesToVisit.IsEmpty
If cancellationToken.IsCancellationRequested Then
Return SpecializedCollections.EmptyEnumerable(Of INamedTypeSymbol)()
Return SpecializedCollections.EmptyEnumerable(Of Tuple(Of INamedTypeSymbol, SyntaxNode))()
End If
Dim node = nodesToVisit.Pop()
Dim type = TryCast(semanticModel.GetDeclaredSymbol(node, cancellationToken), INamedTypeSymbol)
If type IsNot Nothing Then
types.Add(type)
typesAndDeclarations(type) = node
End If
If TypeOf node Is MethodBlockBaseSyntax OrElse
......@@ -99,13 +101,14 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Next
Loop
Return types.OrderBy(Function(t) t.Name)
Return typesAndDeclarations.Select(Function(kvp) Tuple.Create(kvp.Key, kvp.Value)).OrderBy(Function(t) t.Item1.Name)
Catch ex As Exception When FatalError.ReportUnlessCanceled(ex)
Throw ExceptionUtilities.Unreachable
End Try
End Function
Private Function CreateItemsForType(type As INamedTypeSymbol,
position As Integer,
typeSymbolIdIndex As Integer,
semanticModel As SemanticModel,
workspaceSupportsDocumentChanges As Boolean,
......@@ -120,6 +123,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
If type.TypeKind <> TypeKind.Interface Then
Dim typeEvents = CreateItemForEvents(
type,
position,
type,
eventContainer:=Nothing,
semanticModel:=semanticModel,
......@@ -139,6 +143,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
items.Add(
CreateItemForEvents(
type,
position,
propertySymbol.Type,
propertySymbol,
semanticModel,
......@@ -279,6 +284,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
''' <param name="eventContainer">If this is an entry for a WithEvents member, the WithEvents
''' property itself.</param>
Private Function CreateItemForEvents(containingType As INamedTypeSymbol,
position As Integer,
eventType As ITypeSymbol,
eventContainer As IPropertySymbol,
semanticModel As SemanticModel,
......@@ -288,10 +294,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Dim rightHandMemberItems As New List(Of NavigationBarItem)
' Get all of the events and methods implementing them. We must include events from base
' types, as well as static events.
Dim allEvents = eventType.GetBaseTypesAndThis().SelectMany(Function(t) t.GetMembers()).OfType(Of IEventSymbol)().OrderBy(Function(e) e.Name)
Dim accessibleEvents = allEvents.Where(Function(e) e.IsAccessibleWithin(containingType))
Dim accessibleEvents = semanticModel.LookupSymbols(position, eventType).OfType(Of IEventSymbol).OrderBy(Function(e) e.Name)
Dim methodsImplementingEvents = containingType.GetMembers().OfType(Of IMethodSymbol) _
.Where(Function(m) m.HandledEvents.Any(Function(he) Object.Equals(he.EventContainer, eventContainer)))
......@@ -299,10 +303,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
For Each method In methodsImplementingEvents
For Each handledEvent In method.HandledEvents
Dim list As list(Of IMethodSymbol) = Nothing
Dim list As List(Of IMethodSymbol) = Nothing
If Not eventToImplementingMethods.TryGetValue(handledEvent.EventSymbol, list) Then
list = New list(Of IMethodSymbol)
list = New List(Of IMethodSymbol)
eventToImplementingMethods.Add(handledEvent.EventSymbol, list)
End If
......
......@@ -193,6 +193,6 @@
</ImportGroup>
<Target Name="AfterBuild">
<Message Text="AfterBuild" />
<Exec Command="$(SolutionDir)..\..\packages\NuGet.CommandLine.$(NuGetCommandLineVersion)\tools\NuGet.exe pack Diagnostic.nuspec -NoPackageAnalysis -OutputDirectory $(OutDir)" />
<Exec Condition="'$(CIBuild)' != 'true'" Command="$(SolutionDir)..\..\packages\NuGet.CommandLine.$(NuGetCommandLineVersion)\tools\NuGet.exe pack Diagnostic.nuspec -NoPackageAnalysis -OutputDirectory $(OutDir)" />
</Target>
</Project>
......@@ -413,7 +413,8 @@ private static string GetAssemblyName(string outputPath)
// dev11 sometimes gives us output path w/o extension, so removing extension becomes problematic
if (outputPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ||
outputPath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
outputPath.EndsWith(".netmodule", StringComparison.OrdinalIgnoreCase))
outputPath.EndsWith(".netmodule", StringComparison.OrdinalIgnoreCase) ||
outputPath.EndsWith(".winmdobj", StringComparison.OrdinalIgnoreCase))
{
return Path.GetFileNameWithoutExtension(outputPath);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册