public NotRecognizedAnnotation( QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.NotRecognized, qualifiedSelection, context) { }
public TestModuleAnnotation( QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.TestModule, qualifiedSelection, context) { }
private static void RemoveAnnotationMarker(IModuleRewriter rewriter, VBAParser.AnnotationContext annotationContext) { var endOfAnnotationMarker = annotationContext.start.TokenIndex - 1; var startOfAnnotationMarker = endOfAnnotationMarker - ParseTreeAnnotation.ANNOTATION_MARKER.Length + 1; rewriter.RemoveRange(startOfAnnotationMarker, endOfAnnotationMarker); }
public ObsoleteAnnotation(QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.Obsolete, qualifiedSelection, context) { var firstParameter = parameters.FirstOrDefault(); ReplacementDocumentation = string.IsNullOrWhiteSpace(firstParameter) ? "" : firstParameter; }
public override void ExitAnnotation(VBAParser.AnnotationContext context) { if (context.annotationName() != null) { _contexts.Add(new QualifiedContext <ParserRuleContext>(CurrentModuleName, context)); } }
public IAnnotation Create(VBAParser.AnnotationContext context, QualifiedSelection qualifiedSelection) { var annotationName = context.annotationName().GetText(); var parameters = AnnotationParametersFromContext(context); return(CreateAnnotation(annotationName, parameters, qualifiedSelection, context)); }
public override void ExitAnnotation(VBAParser.AnnotationContext context) { if (context.annotationName() != null) { _contexts.Add(context); } }
protected AnnotationBase(AnnotationType annotationType, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context) { AnnotationType = annotationType; QualifiedSelection = qualifiedSelection; Context = context; _annotatedLine = new Lazy <int?>(GetAnnotatedLine); }
public FolderAnnotation( QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.Folder, qualifiedSelection, context) { FolderName = parameters.FirstOrDefault() ?? string.Empty; }
internal ParseTreeAnnotation(IAnnotation annotation, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context) { QualifiedSelection = qualifiedSelection; Context = context; Annotation = annotation; _annotatedLine = new Lazy <int?>(GetAnnotatedLine); AnnotationArguments = AnnotationParametersFromContext(Context); }
public IgnoreAnnotation( QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.Ignore, qualifiedSelection, context) { _inspectionNames = parameters; }
public override void ExitAnnotation([NotNull] VBAParser.AnnotationContext context) { var newAnnotation = _factory.Create(context, new QualifiedSelection(_qualifiedName, context.GetSelection())); // It might be an annotation we don't support or a typo. if (newAnnotation != null) { _annotations.Add(newAnnotation); } }
public DescriptionAnnotation(QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.Description, qualifiedSelection, context) { Description = parameters?.FirstOrDefault(); if ((Description?.StartsWith("\"") ?? false) && Description.EndsWith("\"")) { // strip surrounding double quotes Description = Description.Substring(1, Description.Length - 2); } }
private IAnnotation CreateAnnotation(string annotationName, List <string> parameters, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context) { if (_creators.TryGetValue(annotationName.ToUpperInvariant(), out var annotationClrType)) { return((IAnnotation)Activator.CreateInstance(annotationClrType, qualifiedSelection, context, parameters)); } return(new NotRecognizedAnnotation(qualifiedSelection, context, parameters)); }
public IParseTreeAnnotation Create(VBAParser.AnnotationContext context, QualifiedSelection qualifiedSelection) { var annotationName = context.annotationName().GetText(); if (_lookup.TryGetValue(annotationName.ToLowerInvariant(), out var annotation)) { return(new ParseTreeAnnotation(annotation, qualifiedSelection, context)); } return(new ParseTreeAnnotation(unrecognized, qualifiedSelection, context)); }
private static List <string> AnnotationParametersFromContext(VBAParser.AnnotationContext context) { var parameters = new List <string>(); var argList = context.annotationArgList(); if (argList != null) { parameters.AddRange(argList.annotationArg().Select(arg => arg.GetText())); } return(parameters); }
private static void RemoveSingleAnnotation(IModuleRewriter rewriter, VBAParser.AnnotationContext annotationContext, VBAParser.AnnotationListContext annotationListContext) { var commentSeparator = annotationListContext.COLON(); if (commentSeparator == null) { RemoveEntireLine(rewriter, annotationContext); } else { RemoveAnnotationMarker(rewriter, annotationContext); rewriter.Remove(annotationContext); rewriter.Remove(commentSeparator); } }
/// <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); }
public TestMethodAnnotation( QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.TestMethod, qualifiedSelection, context) { var firstParameter = parameters.FirstOrDefault(); if ((firstParameter?.StartsWith("\"") ?? false) && firstParameter.EndsWith("\"")) { // Strip surrounding double quotes firstParameter = firstParameter.Substring(1, firstParameter.Length - 2); } Category = string.IsNullOrWhiteSpace(firstParameter) ? string.Empty : firstParameter; }
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); }
private string GetAttributeInstruction(VBAParser.AnnotationContext context, string attributeName, AnnotationType annotationType) { string attributeInstruction = string.Empty; if (annotationType.HasFlag(AnnotationType.ModuleAnnotation)) { switch (annotationType) { case AnnotationType.Exposed: attributeInstruction = $"Attribute {attributeName} = True\n"; break; case AnnotationType.PredeclaredId: attributeInstruction = $"Attribute {attributeName} = True\n"; break; } } else if (annotationType.HasFlag(AnnotationType.MemberAnnotation)) { switch (annotationType) { case AnnotationType.Description: var description = context.annotationArgList().annotationArg().FirstOrDefault()?.GetText() ?? string.Empty; description = description.StartsWith("\"") && description.EndsWith("\"") ? description : $"\"{description}\""; attributeInstruction = $"Attribute {attributeName} = \"{description}\"\n"; break; case AnnotationType.DefaultMember: attributeInstruction = $"Attribute {attributeName} = 0"; break; case AnnotationType.Enumerator: attributeInstruction = $"Attribute {attributeName} = -4"; break; } } return(attributeInstruction); }
public override void ExitAnnotation(VBAParser.AnnotationContext context) { var annotationType = context.AnnotationType; if (!annotationType.HasFlag(AnnotationType.Attribute)) { return; } var isMemberAnnotation = annotationType.HasFlag(AnnotationType.MemberAnnotation); var isModuleScope = CurrentScopeDeclaration.DeclarationType.HasFlag(DeclarationType.Module); if (isModuleScope && !isMemberAnnotation) { // module-level annotation var module = State.DeclarationFinder.UserDeclarations(DeclarationType.Module).Single(m => m.QualifiedName.QualifiedModuleName.Equals(CurrentModuleName)); if (!module.Attributes.HasAttributeFor(context.AnnotationType)) { AddContext(new QualifiedContext <ParserRuleContext>(CurrentModuleName, context)); } } else if (isMemberAnnotation) { // member-level annotation is above the context for the first member in the module.. if (isModuleScope) { CurrentScopeDeclaration = FirstMember; } var member = Members.Value.Single(m => m.Key.Equals(CurrentScopeDeclaration.QualifiedName.MemberName)); if (!member.Value.Attributes.HasAttributeFor(context.AnnotationType, member.Key)) { AddContext(new QualifiedContext <ParserRuleContext>(CurrentModuleName, context)); } } else { // annotation is illegal. ignore. } }
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)); } }
protected FlexibleAttributeAnnotationBase(AnnotationType annotationType, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IReadOnlyList <string> parameters) : base(annotationType, qualifiedSelection, context) { Attribute = parameters?.FirstOrDefault() ?? string.Empty; AttributeValues = parameters?.Skip(1).ToList() ?? new List <string>(); }
public IgnoreTestAnnotation(QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.IgnoreTest, qualifiedSelection, context) { }
public EnumeratorMemberAnnotation(QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.Enumerator, qualifiedSelection, context) { Description = parameters.FirstOrDefault(); }
public override void ExitAnnotation([NotNull] VBAParser.AnnotationContext context) { var newAnnotation = _factory.Create(context, new QualifiedSelection(_qualifiedName, context.GetSelection())); _annotations.Add(newAnnotation); }
protected FixedAttributeValueAnnotationBase(AnnotationType annotationType, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context) : base(annotationType, qualifiedSelection, context) { var fixedAttributeValueInfo = FixedAttributeValueInfo(annotationType); Attribute = fixedAttributeValueInfo?.attribute ?? string.Empty; AttributeValues = fixedAttributeValueInfo?.attributeValues ?? new List <string>(); }
public PredeclaredIdAnnotation(QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.PredeclaredId, qualifiedSelection, context) { }
public ModuleDescriptionAnnotation(QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable <string> parameters) : base(AnnotationType.ModuleDescription, qualifiedSelection, context, parameters) { }