Esempio n. 1
0
        public void TestSetBaseType_NoBaseOrInterface()
        {
            var code =
                @"class C
{
}

class A
{
}";

            var expected =
                @"class C
: A
{
}

class A
{
}";

            var solution = GetSolution(code);
            var symbol   = (INamedTypeSymbol)GetSymbols(solution, "C").First();

            var editor = SymbolEditor.Create(solution);

            // set base to A
            var newSymbolC = editor.SetBaseTypeAsync(symbol, g => g.IdentifierName("A")).Result;

            var actual = GetActual(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        public async Task TestRemoveAllOfManyDeclarationsReturnsNull()
        {
            var code =
                @"partial class C
{
}

partial class C
{
}";

            var expected =
                @"
";

            var solution = GetSolution(code);
            var symbol   = (await GetSymbolsAsync(solution, "C")).First();
            var editor   = SymbolEditor.Create(solution);

            var newSymbol = (INamedTypeSymbol)await editor.EditAllDeclarationsAsync(symbol, (e, d) => e.RemoveNode(d));

            Assert.Null(newSymbol);

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        internal sealed override async Task <Document> GetUpdatedDocumentAsync(Document document, SemanticModel model, SyntaxNode root, SyntaxNode nodeToFix, Diagnostic diagnostic, CancellationToken cancellationToken)
        {
            ISymbol declaredSymbol = model.GetDeclaredSymbol(nodeToFix, cancellationToken);

            Debug.Assert(declaredSymbol != null);

            var editor = SymbolEditor.Create(document);

            foreach (var customTag in diagnostic.Descriptor.CustomTags)
            {
                switch (customTag)
                {
                case CA1008DiagnosticAnalyzer.RuleRenameCustomTag:
                    return(await GetUpdatedDocumentForRuleNameRenameAsync(document, (IFieldSymbol)declaredSymbol, cancellationToken).ConfigureAwait(false));

                case CA1008DiagnosticAnalyzer.RuleMultipleZeroCustomTag:
                    await ApplyRuleNameMultipleZeroAsync(editor, (INamedTypeSymbol)declaredSymbol, cancellationToken).ConfigureAwait(false);

                    return(editor.GetChangedDocuments().First());

                case CA1008DiagnosticAnalyzer.RuleNoZeroCustomTag:
                    await ApplyRuleNameNoZeroValueAsync(editor, (INamedTypeSymbol)declaredSymbol, cancellationToken).ConfigureAwait(false);

                    return(editor.GetChangedDocuments().First());
                }
            }

            return(document);
        }
        private async Task <Document> ChangeToPublicInterfaceImplementation(Document document, ISymbol symbolToChange, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            IEnumerable <ISymbol> explicitImplementations = GetExplicitImplementations(symbolToChange);

            if (explicitImplementations == null)
            {
                return(document);
            }

            await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) =>
            {
                SyntaxNode newDeclaration = declaration;
                foreach (ISymbol implementedMember in explicitImplementations)
                {
                    SyntaxNode interfaceTypeNode = docEditor.Generator.TypeExpression(implementedMember.ContainingType);
                    newDeclaration = docEditor.Generator.AsPublicInterfaceImplementation(newDeclaration, interfaceTypeNode);
                }

                docEditor.ReplaceNode(declaration, newDeclaration);
            }, cancellationToken).ConfigureAwait(false);

            return(editor.GetChangedDocuments().First());
        }
Esempio n. 5
0
        public async Task TestSetBaseType_UnknownBase()
        {
            var code =
                @"class C : X
{
}

class A
{
}";

            var expected =
                @"class C : A
{
}

class A
{
}";

            var solution = GetSolution(code);
            var symbol   = (INamedTypeSymbol)(await GetSymbolsAsync(solution, "C")).First();

            var editor = SymbolEditor.Create(solution);

            // set base to A
            var newSymbolC = editor.SetBaseTypeAsync(symbol, g => g.IdentifierName("A"));

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 6
0
            protected async override Task <Solution> GetChangedSolutionAsync(CancellationToken cancellationToken)
            {
                var editor = SymbolEditor.Create(this.Solution);
                await editor.EditAllDeclarationsAsync(this.Symbol, (e, d) => e.SetAccessibility(d, _newAccessibility), cancellationToken).ConfigureAwait(false);

                return(editor.ChangedSolution);
            }
Esempio n. 7
0
        public async Task TestEditAllDeclarations_SameFile()
        {
            var code =
                @"public partial class C
{
}

public partial class C
{
}";

            var expected =
                @"internal partial class C
{
}

internal partial class C
{
}";

            var solution = GetSolution(code);
            var symbol   = (await GetSymbolsAsync(solution, "C")).First();
            var editor   = SymbolEditor.Create(solution);

            var newSymbol = (INamedTypeSymbol)await editor.EditAllDeclarationsAsync(symbol, (e, d) => e.SetAccessibility(d, Accessibility.Internal));

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 8
0
        public async Task TestSetBaseType_Null_ExistingBase()
        {
            var code =
                @"class C : A
{
}

class A
{
}";

            var expected =
                @"class C
{
}

class A
{
}";

            var solution = GetSolution(code);
            var symbol   = (INamedTypeSymbol)(await GetSymbolsAsync(solution, "C")).First();

            var editor = SymbolEditor.Create(solution);

            // set base to null
            var newSymbolC = await editor.SetBaseTypeAsync(symbol, g => null);

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 9
0
        public void TestRemovedOneOfManyDeclarationsReturnsChangedSymbol()
        {
            var code =
                @"partial class C
{
}

partial class C
{
}";

            var expected =
                @"
partial class C
{
}";

            var solution = GetSolution(code);
            var symbol   = GetSymbols(solution, "C").First();
            var editor   = SymbolEditor.Create(solution);

            var newSymbol = (INamedTypeSymbol)editor.EditOneDeclarationAsync(symbol, (e, d) => e.RemoveNode(d)).Result;

            Assert.NotNull(newSymbol);
            Assert.Equal("C", newSymbol.Name);

            var actual = GetActual(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 10
0
        public async Task TestEditOneDeclaration()
        {
            var code =
                @"class C
{
}";

            var expected =
                @"class C
{
    void m()
    {
    }
}";

            var solution = GetSolution(code);
            var symbol   = (await GetSymbolsAsync(solution, "C")).First();
            var editor   = SymbolEditor.Create(solution);

            var newSymbol = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(symbol, (e, d) => e.AddMember(d, e.Generator.MethodDeclaration("m")));

            Assert.Equal(1, newSymbol.GetMembers("m").Length);

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 11
0
        public async Task TestChangeLogicalIdentityReturnsCorrectSymbol_OneDeclaration()
        {
            // proves that APIs return the correct new symbol even after a change that changes the symbol's logical identity.
            var code =
                @"class C
{
}";

            var expected =
                @"class X
{
}";

            var solution = GetSolution(code);
            var symbol   = (await GetSymbolsAsync(solution, "C")).First();
            var editor   = SymbolEditor.Create(solution);

            var newSymbol = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(symbol, (e, d) => e.SetName(d, "X"));

            Assert.Equal("X", newSymbol.Name);

            // original symbols cannot be rebound after identity change.
            var reboundSymbol = await editor.GetCurrentSymbolAsync(symbol);

            Assert.Null(reboundSymbol);

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 12
0
        public void TestSetBaseType_Null_ExistingInterface()
        {
            var code =
                @"class C : I
{
}

interface I
{
}";

            var expected =
                @"class C : I
{
}

interface I
{
}";

            var solution = GetSolution(code);
            var symbol   = (INamedTypeSymbol)GetSymbols(solution, "C").First();

            var editor = SymbolEditor.Create(solution);

            // set base to null
            var newSymbolC = editor.SetBaseTypeAsync(symbol, g => null).Result;

            var actual = GetActual(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
Esempio n. 13
0
            public override async Task <CodeAction?> GetFixAsync(FixAllContext fixAllContext)
            {
                ImmutableArray <Diagnostic> diagnostics = await GetAllDiagnosticsInScope(fixAllContext).ConfigureAwait(false);

                Dictionary <(INamedTypeSymbol marshallerType, ITypeSymbol managedType, bool isLinearCollectionMarshaller), HashSet <string> > uniqueMarshallersToFix = new();

                // Organize all the diagnostics by marshaller, managed type, and whether or not it's a collection marshaller
                foreach (Diagnostic diagnostic in diagnostics)
                {
                    Document      doc   = fixAllContext.Solution.GetDocument(diagnostic.Location.SourceTree);
                    SemanticModel model = await doc.GetSemanticModelAsync(fixAllContext.CancellationToken).ConfigureAwait(false);

                    var         entryPointTypeSymbol = (INamedTypeSymbol)model.GetEnclosingSymbol(diagnostic.Location.SourceSpan.Start, fixAllContext.CancellationToken);
                    ITypeSymbol?managedType          = GetManagedTypeInAttributeSyntax(diagnostic.Location, entryPointTypeSymbol);

                    SyntaxNode root = await diagnostic.Location.SourceTree.GetRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);

                    SyntaxNode node                   = root.FindNode(diagnostic.Location.SourceSpan);
                    var        marshallerType         = (INamedTypeSymbol)model.GetSymbolInfo(node, fixAllContext.CancellationToken).Symbol;
                    var        uniqueMarshallerFixKey = (marshallerType, managedType, ManualTypeMarshallingHelper.IsLinearCollectionEntryPoint(entryPointTypeSymbol));
                    if (!uniqueMarshallersToFix.TryGetValue(uniqueMarshallerFixKey, out HashSet <string> membersToAdd))
                    {
                        uniqueMarshallersToFix[uniqueMarshallerFixKey] = membersToAdd = new HashSet <string>();
                    }

                    membersToAdd.UnionWith(diagnostic.Properties[MissingMemberNames.Key].Split(MissingMemberNames.Delimiter));
                }

                Dictionary <INamedTypeSymbol, INamedTypeSymbol> partiallyUpdatedSymbols = new(SymbolEqualityComparer.Default);

                SymbolEditor symbolEditor = SymbolEditor.Create(fixAllContext.Solution);

                // Apply each fix
                foreach (var marshallerInfo in uniqueMarshallersToFix)
                {
                    var(marshallerType, managedType, isLinearCollectionMarshaller) = marshallerInfo.Key;
                    HashSet <string> missingMembers = marshallerInfo.Value;

                    if (!partiallyUpdatedSymbols.TryGetValue(marshallerType, out INamedTypeSymbol newMarshallerType))
                    {
                        newMarshallerType = marshallerType;
                    }

                    newMarshallerType = (INamedTypeSymbol)await symbolEditor.EditOneDeclarationAsync(
                        marshallerType,
                        (editor, decl) => AddMissingMembers(
                            editor,
                            decl,
                            marshallerType,
                            managedType,
                            missingMembers,
                            isLinearCollectionMarshaller),
                        fixAllContext.CancellationToken).ConfigureAwait(false);

                    partiallyUpdatedSymbols[marshallerType] = newMarshallerType;
                }

                return(CodeAction.Create(SR.AddMissingCustomTypeMarshallerMembers, ct => Task.FromResult(symbolEditor.ChangedSolution)));
            }
Esempio n. 14
0
        public async Task TestSequentialEdits_SeparateSymbolsAndFiles()
        {
            var code1 =
                @"class A
{
}";

            var code2 =
                @"class B
{
}";

            var expected1 =
                @"class A
{
    void ma()
    {
    }
}";

            var expected2 =
                @"class B
{
    void mb()
    {
    }
}";

            var solution = GetSolution(code1, code2);
            var comp     = await solution.Projects.First().GetCompilationAsync();

            var symbolA = comp.GlobalNamespace.GetMembers("A").First();
            var symbolB = comp.GlobalNamespace.GetMembers("B").First();

            var editor = SymbolEditor.Create(solution);

            var newSymbolA = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(
                symbolA,
                (e, d) => e.AddMember(d, e.Generator.MethodDeclaration("ma"))
                );

            Assert.Equal(1, newSymbolA.GetMembers("ma").Length);

            var newSymbolB = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(
                symbolB,
                (e, d) => e.AddMember(d, e.Generator.MethodDeclaration("mb"))
                );

            Assert.Equal(1, newSymbolB.GetMembers("mb").Length);

            var docs    = editor.GetChangedDocuments().ToList();
            var actual1 = await GetActualAsync(docs[0]);

            var actual2 = await GetActualAsync(docs[1]);

            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);
        }
Esempio n. 15
0
        public static async Task <Solution> ChangeMemberAccessibility(Solution solution, ISymbol memberSymbol, Accessibility accessibility, CancellationToken cancellationToken)
        {
            var editor = SymbolEditor.Create(solution);
            await editor.EditAllDeclarationsAsync(memberSymbol, (docEditor, syntaxNode) =>
            {
                docEditor.SetAccessibility(syntaxNode, accessibility);
            }, cancellationToken).ConfigureAwait(false);

            return(editor.ChangedSolution);
        }
Esempio n. 16
0
        public async Task TestEditDeclarationWithLocation_SequentialEdits_NewLocation()
        {
            var code =
                @"partial class C
{
}

partial class C
{
}";

            var expected =
                @"partial class C
{
}

partial class C
{
    void m()
    {
    }

    void m2()
    {
    }
}";

            var solution = GetSolution(code);
            var symbol   = (await GetSymbolsAsync(solution, "C")).First();
            var location = symbol.Locations.Last();
            var editor   = SymbolEditor.Create(solution);

            var newSymbol = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(
                symbol,
                location,
                (e, d) => e.AddMember(d, e.Generator.MethodDeclaration("m"))
                );

            Assert.Equal(1, newSymbol.GetMembers("m").Length);

            // use location from new symbol
            var newLocation = newSymbol.Locations.Last();
            var newSymbol2  = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(
                newSymbol,
                newLocation,
                (e, d) => e.AddMember(d, e.Generator.MethodDeclaration("m2"))
                );

            Assert.Equal(1, newSymbol2.GetMembers("m").Length);
            Assert.Equal(1, newSymbol2.GetMembers("m2").Length);

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);
        }
        private static async Task <Document> AddSerializableAttributeToType(Document document, ITypeSymbol type, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);
            await editor.EditOneDeclarationAsync(type, (docEditor, declaration) =>
            {
                SyntaxNode serializableAttr = docEditor.Generator.Attribute(docEditor.Generator.TypeExpression(WellKnownTypes.SerializableAttribute(docEditor.SemanticModel.Compilation)));
                docEditor.AddAttribute(declaration, serializableAttr);
            }, cancellationToken).ConfigureAwait(false);

            return(editor.GetChangedDocuments().First());
        }
        private async Task <Document> MakeProtected(Document document, ISymbol symbolToChange, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) =>
            {
                docEditor.SetAccessibility(declaration, Accessibility.Protected);
            }, cancellationToken).ConfigureAwait(false);

            return(editor.GetChangedDocuments().First());
        }
Esempio n. 19
0
        private void DefaultSymbolButton_Click(object sender, RoutedEventArgs e)
        {
            var editor = new SymbolEditor();

            editor.Symbol = Renderer.DefaultSymbol?.Clone() ?? new SimpleMarkerSymbol();
            var result = MetroDialog.ShowDialog("Symbol Editor", editor, this);

            if (result == true)
            {
                Renderer.DefaultSymbol = editor.Symbol;
            }
        }
        private static async Task <Document> AddAccessor(Document document, SyntaxNode parameter, CancellationToken cancellationToken)
        {
            SymbolEditor  symbolEditor = SymbolEditor.Create(document);
            SemanticModel model        = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            if (model.GetDeclaredSymbol(parameter, cancellationToken) is not IParameterSymbol parameterSymbol)
            {
                return(document);
            }

            // Make the first character uppercase since we are generating a property.
            string propName = char.ToUpper(parameterSymbol.Name[0], CultureInfo.InvariantCulture).ToString() + parameterSymbol.Name[1..];
Esempio n. 21
0
        private async Task <Document> MakeContainingTypeSealed(Document document, IMethodSymbol methodSymbol, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            await editor.EditAllDeclarationsAsync(methodSymbol.ContainingType, (docEditor, declaration) =>
            {
                DeclarationModifiers modifiers = docEditor.Generator.GetModifiers(declaration);
                docEditor.SetModifiers(declaration, modifiers + DeclarationModifiers.Sealed);
            }, cancellationToken).ConfigureAwait(false);

            return(editor.GetChangedDocuments().First());
        }
Esempio n. 22
0
        public async Task TestRemoveFieldFromMultiFieldDeclaration()
        {
            var code =
                @"class C
{
    public int X, Y;
}";

            var expected =
                @"class C
{
    public int Y;
}";

            var expected2 =
                @"class C
{
}";

            var solution = GetSolution(code);
            var symbol   = (INamedTypeSymbol)(await GetSymbolsAsync(solution, "C")).First();
            var symbolX  = symbol.GetMembers("X").First();
            var symbolY  = symbol.GetMembers("Y").First();

            var editor = SymbolEditor.Create(solution);

            // remove X -- should remove only part of the field declaration.
            var newSymbolX = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(
                symbolX,
                (e, d) => e.RemoveNode(d)
                );

            Assert.Null(newSymbolX);

            var actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected, actual);

            // now remove Y -- should remove entire remaining field declaration
            var newSymbolY = (INamedTypeSymbol)await editor.EditOneDeclarationAsync(
                symbolY,
                (e, d) => e.RemoveNode(d)
                );

            Assert.Null(newSymbolY);

            actual = await GetActualAsync(editor.GetChangedDocuments().First());

            Assert.Equal(expected2, actual);
        }
        private static async Task <Document> SetAccessibilityAsync(Document document, IMethodSymbol methodSymbol, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            // This would be constructor and can have only one definition.
            Debug.Assert(methodSymbol.IsConstructor() && methodSymbol.DeclaringSyntaxReferences.HasExactly(1));
            await editor.EditOneDeclarationAsync(methodSymbol, (docEditor, declaration) =>
            {
                Accessibility newAccessibility = methodSymbol.ContainingType.IsSealed ? Accessibility.Private : Accessibility.Protected;
                docEditor.SetAccessibility(declaration, newAccessibility);
            }, cancellationToken).ConfigureAwait(false);

            return(editor.GetChangedDocuments().First());
        }
Esempio n. 24
0
 public static async Task <Solution> ChangeMemberStaticModifier(Solution solution, ISymbol memberSymbol, bool isStatic, CancellationToken cancellationToken)
 {
     var editor = SymbolEditor.Create(solution);
     await editor.EditAllDeclarationsAsync(memberSymbol, (docEditor, syntaxNode) =>
     {
         var newMods = DeclarationModifiers.From(memberSymbol).WithIsStatic(isStatic);
         if (memberSymbol is IPropertySymbol propertySymbol && propertySymbol.IsReadOnly)
         {
             // Looks like there's a bug in Roslyn where SetModifiers applies the 'readonly'
             // keyword to a get-only property, producing illegal syntax.
             newMods = newMods.WithIsReadOnly(false);
         }
         docEditor.SetModifiers(syntaxNode, newMods);
     }, cancellationToken).ConfigureAwait(false);
Esempio n. 25
0
        private async Task ApplyRuleNameNoZeroValueAsync(SymbolEditor editor, INamedTypeSymbol enumType, CancellationToken cancellationToken)
        {
            // remove any non-zero member named 'None'
            foreach (IFieldSymbol field in enumType.GetMembers().Where(m => m.Kind == SymbolKind.Field))
            {
                if (CA1008DiagnosticAnalyzer.IsMemberNamedNone(field))
                {
                    await editor.EditOneDeclarationAsync(field, (e, d) => e.RemoveNode(d), cancellationToken).ConfigureAwait(false);
                }
            }

            // insert zero-valued member 'None' to top
            await editor.EditOneDeclarationAsync(enumType, (e, d) => e.InsertMembers(d, 0, new[] { e.Generator.EnumMember("None") }), cancellationToken).ConfigureAwait(false);
        }
        private async Task <Document> SetAccessibility(Document document, SyntaxNode node, ISymbol symbol, CancellationToken cancellationToken)
        {
            var editor       = SymbolEditor.Create(document);
            var methodSymbol = symbol as IMethodSymbol;

            // This would be constructor and can have only one definition.
            Debug.Assert(methodSymbol.IsConstructor() && methodSymbol.DeclaringSyntaxReferences.Count() == 1);
            await editor.EditOneDeclarationAsync(methodSymbol, (docEditor, declaration) =>
            {
                var newAccessibility = methodSymbol.ContainingType.IsSealed ? Accessibility.Private : Accessibility.Protected;
                docEditor.SetAccessibility(declaration, newAccessibility);
            }, cancellationToken);

            return(editor.GetChangedDocuments().First());
        }
            protected async override Task <Solution> GetChangedSolutionAsync(CancellationToken cancellationToken)
            {
                var editor = SymbolEditor.Create(this.Solution);
                await editor.EditAllDeclarationsAsync(this.Symbol, (e, d) =>
                {
                    e.SetModifiers(d, _newModifiers);

                    if (this.Symbol.IsAbstract && !_newModifiers.IsAbstract && this.Symbol.Kind == SymbolKind.Method)
                    {
                        e.ReplaceNode(d, (_d, g) => g.WithStatements(_d, new SyntaxNode[] { }));
                    }
                }
                                                      , cancellationToken).ConfigureAwait(false);

                return(editor.ChangedSolution);
            }
        private void OnTreeViewItemMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var item = (sender as FrameworkElement).DataContext as Esri.ArcGISRuntime.Toolkit.Preview.UI.TocItem;

            if (item?.Content is LegendInfo legendInfo)
            {
                Symbol          symbolReference = null;
                Action <Symbol> symbolSetter    = null;
                // Find the symbol in the layer that matches the one in the legend
                var layer = item.Layer;
                if (layer is FeatureLayer fl)
                {
                    var renderer = fl.Renderer;
                    if (renderer is SimpleRenderer sr)
                    {
                        symbolReference = sr.Symbol;
                        symbolSetter    = (s) => sr.Symbol = s;
                    }
                    else if (renderer is UniqueValueRenderer uvr)
                    {
                        // TODO: Also handle uvr.DefaultSymbol
                        var uv = uvr.UniqueValues.Where(u => u.Label == legendInfo.Name);
                        if (uv.Count() > 1) // In case multiple symbols matches
                        {
                            uv = uv.Where(u => u.Symbol.ToJson() == legendInfo.Symbol.ToJson());
                        }
                        if (uv.Count() == 1)
                        {
                            var u = uv.First();
                            symbolReference = u.Symbol;
                            symbolSetter    = (s) => u.Symbol = s;
                        }
                    }
                    else
                    {
                        // TODO
                    }
                }

                if (symbolReference != null && symbolSetter != null)
                {
                    var editor = new SymbolEditor();
                    editor.Symbol = symbolReference?.Clone();
                    ShowSidePanelDialog(editor, () => { symbolSetter(editor.Symbol); item.Parent.RefreshLegend(); });
                }
            }
        }
        private async Task <Document> AddAccessor(Document document, SyntaxNode parameter, CancellationToken cancellationToken)
        {
            SymbolEditor  symbolEditor = SymbolEditor.Create(document);
            SemanticModel model        = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var parameterSymbol = model.GetDeclaredSymbol(parameter, cancellationToken) as IParameterSymbol;

            if (parameterSymbol == null)
            {
                return(document);
            }

            // Make the first character uppercase since we are generating a property.
            string propName = char.ToUpper(parameterSymbol.Name[0]).ToString() + parameterSymbol.Name.Substring(1);

            INamedTypeSymbol typeSymbol     = parameterSymbol.ContainingType;
            ISymbol          propertySymbol = typeSymbol.GetMembers(propName).Where(m => m.Kind == SymbolKind.Property).FirstOrDefault();

            // Add a new property
            if (propertySymbol == null)
            {
                await symbolEditor.EditOneDeclarationAsync(typeSymbol,
                                                           parameter.GetLocation(), // edit the partial declaration that has this parameter symbol.
                                                           (editor, typeDeclaration) =>
                {
                    SyntaxNode newProperty = editor.Generator.PropertyDeclaration(propName,
                                                                                  editor.Generator.TypeExpression(parameterSymbol.Type),
                                                                                  Accessibility.Public,
                                                                                  DeclarationModifiers.ReadOnly);
                    newProperty = editor.Generator.WithGetAccessorStatements(newProperty, null);
                    editor.AddMember(typeDeclaration, newProperty);
                },
                                                           cancellationToken).ConfigureAwait(false);
            }
            else
            {
                await symbolEditor.EditOneDeclarationAsync(propertySymbol,
                                                           (editor, propertyDeclaration) =>
                {
                    editor.SetGetAccessorStatements(propertyDeclaration, null);
                    editor.SetModifiers(propertyDeclaration, editor.Generator.GetModifiers(propertyDeclaration) - DeclarationModifiers.WriteOnly);
                },
                                                           cancellationToken).ConfigureAwait(false);
            }

            return(symbolEditor.GetChangedDocuments().First());
        }
    //シンボルのメニューを作成
    private void CreateSymbolMenu()
    {
        //シンボル分メニュー作成
        List <DefineSymbol> symbolList = SymbolEditor.SymbolList;

        for (int i = 0; i < symbolList.Count; i++)
        {
            CreateSymbolMenuParts(symbolList [i], i);
            GUILayout.Space(5);
        }

        //新規に追加できるよう、空白のメニューを追加
        DefineSymbol newSymbol = new DefineSymbol("", false);

        CreateSymbolMenuParts(newSymbol, symbolList.Count);

        GUILayout.Space(10);

        //保存されている状態に戻すボタン
        if (GUILayout.Button("Reset"))
        {
            SymbolEditor.Init();
        }

        GUILayout.Space(10);

        //全部無効にするボタン
        if (GUILayout.Button("All Invalid"))
        {
            SymbolEditor.SetAllEnabled(false);
        }

        //全部有効にするボタン
        if (GUILayout.Button("All Valid"))
        {
            SymbolEditor.SetAllEnabled(true);
        }

        GUILayout.Space(10);

        //全部削除するボタン
        if (GUILayout.Button("All Delete"))
        {
            SymbolEditor.AllDelete();
        }
    }