Ejemplo n.º 1
0
            public override void ExitAttributeStmt(VBAParser.AttributeStmtContext context)
            {
                var name   = context.implicitCallStmt_InStmt().GetText().Trim();
                var values = context.literal().Select(e => e.GetText().Replace("\"", string.Empty)).ToList();

                _currentScopeAttributes.Add(name, values);
            }
Ejemplo n.º 2
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;
            }
        // get the name of the file
        public override void EnterAttributeStmt([NotNull] VBAParser.AttributeStmtContext context)
        {
            if (context.implicitCallStmt_InStmt().GetText() == "VB_Name")
            {
                FileName = context.literal()[0].GetText().Trim('"');
            }

            // remove all attributes
            Rewriter.Replace(context.Start, context.Stop, "");
        }
Ejemplo n.º 4
0
        private void Fix(QualifiedModuleName moduleName, VBAParser.AttributeStmtContext context)
        {
            var annotationType = context.AnnotationType();

            Debug.Assert(annotationType.HasValue);

            var annotation = $"'@{annotationType}\r\n";

            var rewriter = _state.GetRewriter(moduleName);

            rewriter.InsertAfter(((VBAParser.ModuleAttributesContext)context.Parent).Stop.TokenIndex, annotation);
        }
Ejemplo n.º 5
0
 private void Fix(QualifiedMemberName memberName, VBAParser.AttributeStmtContext context)
 {
     if (context.AnnotationType() == AnnotationType.Description)
     {
         FixMemberDescriptionAnnotation(_state, memberName);
     }
     else
     {
         // only '@Description member annotation is parameterized, so AnnotationType.ToString() works:
         Debug.Assert(context.AnnotationType().HasValue);
         AddMemberAnnotation(_state, memberName, context.AnnotationType());
     }
 }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
            public override void ExitAttributeStmt(VBAParser.AttributeStmtContext context)
            {
                var annotations = CurrentScopeDeclaration?.Annotations;

                var type = context.AnnotationType();

                if (type != null && (annotations?.All(a => a.AnnotationType != type) ?? false))
                {
                    if (type.Value.HasFlag(AnnotationType.ModuleAnnotation))
                    {
                        // attribute is mapped to an annotation, but current scope doesn't have that annotation:
                        AddContext(new QualifiedContext <ParserRuleContext>(CurrentModuleName, context));
                    }

                    if (type.Value.HasFlag(AnnotationType.MemberAnnotation))
                    {
                        AddContext(new QualifiedContext <ParserRuleContext>(CurrentScopeDeclaration.QualifiedName, context));
                    }
                }
            }
Ejemplo n.º 10
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>();
 }
Ejemplo n.º 11
0
 public AttributeNode(VBAParser.AttributeStmtContext context)
 {
     Context = context;
 }