Exemple #1
0
        /// <summary>
        /// Adds an attribute to match given annotation.
        /// </summary>
        /// <param name="memberName"></param>
        /// <param name="context"></param>
        private void Fix(QualifiedMemberName memberName, VBAParser.AnnotationContext context)
        {
            Debug.Assert(context.AnnotationType.HasFlag(AnnotationType.MemberAnnotation));

            var annotationName = Identifier.GetName(context.annotationName().unrestrictedIdentifier());
            var annotationType = context.AnnotationType;
            var attributeName  = memberName.MemberName + "." + _attributeNames[annotationName];

            var attributeInstruction = GetAttributeInstruction(context, attributeName, annotationType);
            var insertPosition       = FindInsertPosition(context);

            var rewriter = _state.GetAttributeRewriter(memberName.QualifiedModuleName);

            rewriter.InsertBefore(insertPosition, attributeInstruction);
        }
Exemple #2
0
        public IAnnotation Create(VBAParser.AnnotationContext context, QualifiedSelection qualifiedSelection)
        {
            string        annotationName = context.annotationName().GetText();
            List <string> parameters     = new List <string>();
            var           argList        = context.annotationArgList();

            if (argList != null)
            {
                parameters.AddRange(argList.annotationArg().Select(arg => arg.GetText()));
            }
            Type annotationCLRType = null;

            if (_creators.TryGetValue(annotationName.ToUpperInvariant(), out annotationCLRType))
            {
                return((IAnnotation)Activator.CreateInstance(annotationCLRType, qualifiedSelection, parameters));
            }
            return(null);
        }
Exemple #3
0
            public override void ExitAnnotation(VBAParser.AnnotationContext context)
            {
                var name           = Identifier.GetName(context.annotationName().unrestrictedIdentifier());
                var annotationType = (AnnotationType)Enum.Parse(typeof(AnnotationType), name, true);

                var moduleHasMembers = _members.Value.Any();

                var isMemberAnnotation = annotationType.HasFlag(AnnotationType.MemberAnnotation);
                var isModuleAnnotation = annotationType.HasFlag(AnnotationType.ModuleAnnotation);

                var isModuleAnnotatedForMemberAnnotation = isMemberAnnotation &&
                                                           (_currentScopeDeclaration?.DeclarationType.HasFlag(DeclarationType.Module) ?? false);

                var isMemberAnnotatedForModuleAnnotation = isModuleAnnotation &&
                                                           (_currentScopeDeclaration?.DeclarationType.HasFlag(DeclarationType.Member) ?? false);

                var isIllegal = !(isMemberAnnotation && moduleHasMembers && !_isFirstMemberProcessed) &&
                                (isMemberAnnotatedForModuleAnnotation || isModuleAnnotatedForMemberAnnotation);

                if (isIllegal)
                {
                    _contexts.Add(new QualifiedContext <ParserRuleContext>(CurrentModuleName, context));
                }
            }