예제 #1
0
 public virtual void VisitTargetScopeSyntax(TargetScopeSyntax syntax)
 {
     this.VisitNodes(syntax.LeadingNodes);
     this.Visit(syntax.Keyword);
     this.Visit(syntax.Assignment);
     this.Visit(syntax.Value);
 }
예제 #2
0
        public static ResourceScope GetTargetScope(TargetScopeSyntax targetScopeSyntax)
        {
            // TODO: Revisit when adding support for multiple target scopes

            // Type checking will pick up any errors if we fail to process the syntax correctly in this function.
            // There's no need to do error checking here - just return "None" as the scope type.

            if (!(targetScopeSyntax.Value is StringSyntax stringSyntax))
            {
                return(ResourceScope.None);
            }

            var literalValue = stringSyntax.TryGetLiteralValue();

            if (literalValue == null)
            {
                return(ResourceScope.None);
            }

            return(literalValue switch {
                LanguageConstants.TargetScopeTypeTenant => ResourceScope.Tenant,
                LanguageConstants.TargetScopeTypeManagementGroup => ResourceScope.ManagementGroup,
                LanguageConstants.TargetScopeTypeSubscription => ResourceScope.Subscription,
                LanguageConstants.TargetScopeTypeResourceGroup => ResourceScope.ResourceGroup,
                _ => ResourceScope.None,
            });
예제 #3
0
        protected virtual TargetScopeSyntax ReplaceTargetScopeSyntax(TargetScopeSyntax syntax)
        {
            var hasChanges = Rewrite(syntax.Keyword, out var keyword);

            hasChanges |= Rewrite(syntax.Assignment, out var assignment);
            hasChanges |= Rewrite(syntax.Value, out var value);

            if (!hasChanges)
            {
                return(syntax);
            }

            return(new TargetScopeSyntax(keyword, assignment, value));
        }
예제 #4
0
        protected virtual SyntaxBase ReplaceTargetScopeSyntax(TargetScopeSyntax syntax)
        {
            var hasChanges = TryRewrite(syntax.LeadingNodes, out var leadingNodes);

            hasChanges |= TryRewriteStrict(syntax.Keyword, out var keyword);
            hasChanges |= TryRewrite(syntax.Assignment, out var assignment);
            hasChanges |= TryRewrite(syntax.Value, out var value);

            if (!hasChanges)
            {
                return(syntax);
            }

            return(new TargetScopeSyntax(leadingNodes, keyword, assignment, value));
        }
예제 #5
0
 void ISyntaxVisitor.VisitTargetScopeSyntax(TargetScopeSyntax syntax) => ReplaceCurrent(syntax, ReplaceTargetScopeSyntax);