Пример #1
0
            public override void ExitAttributeStmt(VBAParser.AttributeStmtContext context)
            {
                // We assume attributes can either be simple names (VB_Name) or, if they are inside procedures, member access expressions
                // (e.g. Foo.VB_UserMemId = 0)
                var    expr = context.attributeName().lExpression();
                string name;

                if (expr is VBAParser.SimpleNameExprContext)
                {
                    name = ((VBAParser.SimpleNameExprContext)expr).identifier().GetText();
                }
                else
                {
                    // Turns "Foo.VB_ProcData.VB_Invoke_Func" into "VB_ProcData.VB_Invoke_Func",
                    // because we are not interested in the subroutine name Foo.
                    name = GetAttributeNameWithoutProcedureName((VBAParser.MemberAccessExprContext)expr);
                }
                var values = context.attributeValue().Select(e => e.GetText().Replace("\"", string.Empty)).ToList();
                IEnumerable <string> existingValues;

                if (_currentScopeAttributes.TryGetValue(name, out existingValues))
                {
                    values.InsertRange(0, existingValues);
                }
                _currentScopeAttributes[name] = values;
            }
Пример #2
0
        public void AddContext(VBAParser.AttributeStmtContext context)
        {
            if (context == null || !Name.Equals(context.attributeName().GetText(), StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            _contexts.Add(context);
            var values = context.attributeValue().Select(e => e.GetText().Replace("\"", string.Empty)).ToList();

            foreach (var value in values.Where(v => !HasValue(v)))
            {
                AddValue(value);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the <see cref="AnnotationType"/>, if any, associated with the context.
        /// </summary>
        /// <returns>Returns <c>null</c> if no association is found.</returns>
        public static AnnotationType?AnnotationType(this VBAParser.AttributeStmtContext context)
        {
            var name  = context.attributeName().Stop.Text;
            var value = context.attributeValue().FirstOrDefault()?.GetText();

            var key = AttributeAnnotationTypes.Keys
                      // EndsWith the name, so we can match "VB_Description" to "DoSomething.VB_Description"
                      .SingleOrDefault(k => k.AttributeName.EndsWith(name) && (k.AttributeValue?.Equals(value, StringComparison.OrdinalIgnoreCase) ?? true));

            AnnotationType result;

            return(key != null && AttributeAnnotationTypes.TryGetValue(key, out result)
                ? (AnnotationType?)result
                : null);
        }
Пример #4
0
        public override void ExitAttributeStmt(VBAParser.AttributeStmtContext context)
        {
            var values = context.attributeValue().Select(e => e.GetText().Replace("\"", string.Empty)).ToList();

            var attribute = _currentScopeAttributes
                            .SingleOrDefault(a => a.Name.Equals(context.attributeName().GetText(), StringComparison.OrdinalIgnoreCase));

            if (attribute != null)
            {
                foreach (var value in values.Where(v => !attribute.HasValue(v)))
                {
                    attribute.AddValue(value);
                }
            }

            _currentScopeAttributes.Add(new AttributeNode(context));
        }
Пример #5
0
 public AttributeNode(VBAParser.AttributeStmtContext context)
 {
     _contexts.Add(context);
     Name    = context?.attributeName().GetText() ?? string.Empty;
     _values = context?.attributeValue().Select(a => a.GetText()).ToList() ?? new List <string>();
 }