Ejemplo n.º 1
0
        private static async Task <Document> RemoveLinearAttributeOptionFromAttribute(Document document, TextSpan span, FieldDeclarationSyntax declaration, CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var canUseSimplifiedName = semanticModel.CanReferenceNamedSymbol(span, "UdonSyncedAttribute");

            AttributeSyntax ModifyUdonSyncedAttribute(AttributeSyntax attribute)
            {
                var symbol = semanticModel.GetSymbolInfo(attribute);

                if (symbol.Symbol is not IMethodSymbol m)
                {
                    return(attribute); // UNREACHABLE
                }
                if (UdonSharpBehaviourUtility.PrettyTypeName(m) == "UdonSharp.UdonSyncedAttribute")
                {
                    if (canUseSimplifiedName)
                    {
                        return(SyntaxFactory.Attribute(SyntaxFactory.IdentifierName("UdonSynced"), null));
                    }
                    return(SyntaxFactory.Attribute(SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("UdonSharp"), SyntaxFactory.IdentifierName("UdonSynced")), null));
                }

                return(attribute);
            }

            var oldNode    = declaration.FirstAncestorOrSelf <FieldDeclarationSyntax>();
            var attributes = oldNode.AttributeLists.Select(w => SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(w.Attributes.Select(ModifyUdonSyncedAttribute))));
            var newNode    = oldNode.WithAttributeLists(SyntaxFactory.List(attributes));

            return(await document.ReplaceNodeAsync(oldNode, newNode, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        private static async Task <Document> CreatePropertyDeclaration(Document document, FieldDeclarationSyntax fieldDeclaration, CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var backingField = fieldDeclaration.Declaration.Variables.First().Identifier.ValueText;
            var type         = fieldDeclaration.Declaration.Type;
            var attribute    = fieldDeclaration.AttributeLists.SelectMany(w => w.Attributes)
                               .First(w => UdonSharpBehaviourUtility.PrettyTypeName(semanticModel.GetSymbolInfo(w).Symbol) == UdonConstants.UdonSharpFieldChangeCallbackFullName);
            var targetProperty = attribute.ArgumentList.Arguments.First().Expression.ParseValue();

            var modifiers = SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
            var getter    = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration, default, default, SyntaxFactory.ArrowExpressionClause(SyntaxFactory.IdentifierName(backingField)))