private IdentifierReference CreateReference(ParserRuleContext callSiteContext, Declaration callee, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false) { if (callSiteContext == null) { return(null); } var name = callSiteContext.GetText(); var selection = callSiteContext.GetSelection(); return(new IdentifierReference(_qualifiedModuleName, name, selection, callSiteContext, callee, isAssignmentTarget, hasExplicitLetStatement)); }
/// <summary> /// Represents a context in the code tree. /// </summary> /// <param name="context">The parser rule context, obtained from an ANTLR-generated parser method.</param> /// <param name="parentScope">The scope this context belongs to. <c>null</c> for the root context.</param> /// <param name="localScope">The scope this context defines, if any. <c>null</c> if omitted.</param> /// <param name="childNodes">The child nodes.</param> /// <remarks> /// Specifying a <c>localScope</c> ensures child nodes can be added, regardless of /// </remarks> protected Node(ParserRuleContext context, string parentScope, string localScope = null, ICollection <Node> childNodes = null) { _context = context; _selection = context.GetSelection(); _parentScope = parentScope; _localScope = localScope; _childNodes = (localScope != null && childNodes == null) ? new List <Node>() : childNodes; }
/// <summary> /// Represents a context in the code tree. /// </summary> /// <param name="context">The parser rule context, obtained from an ANTLR-generated parser method.</param> /// <param name="parentScope">The scope this context belongs to. <c>null</c> for the root context.</param> /// <param name="localScope">The scope this context defines, if any. <c>null</c> if omitted.</param> /// <param name="childNodes">The child nodes.</param> /// <remarks> /// Specifying a <c>localScope</c> ensures child nodes can be added, regardless of /// </remarks> protected Node(ParserRuleContext context, string parentScope, string localScope = null, ICollection<Node> childNodes = null) { _context = context; _selection = context.GetSelection(); _parentScope = parentScope; _localScope = localScope; _childNodes = (localScope != null && childNodes == null) ? new List<Node>() : childNodes; }
public UnboundMemberDeclaration(Declaration parentDeclaration, ParserRuleContext unboundIdentifier, ParserRuleContext callingContext, IEnumerable <IAnnotation> annotations) : base(new QualifiedMemberName(parentDeclaration.QualifiedName.QualifiedModuleName, unboundIdentifier.GetText()), parentDeclaration, parentDeclaration, "Variant", string.Empty, false, false, Accessibility.Implicit, DeclarationType.UnresolvedMember, unboundIdentifier, unboundIdentifier.GetSelection(), false, null, false, annotations) { CallingContext = callingContext; }
public NavigateCodeEventArgs(QualifiedModuleName qualifiedName, ParserRuleContext context) { QualifiedName = qualifiedName; Selection = context.GetSelection(); }
/// <summary> /// Returns <c>true</c> if specified <c>Selection</c> contains this node. /// </summary> public static bool IsInSelection(this ParserRuleContext context, Selection selection) { var contextSelection = context.GetSelection(); return(selection.Contains(contextSelection)); }
public NavigateCodeEventArgs(QualifiedModuleName qualifiedName, ParserRuleContext context) { _qualifiedName = qualifiedName; _selection = context.GetSelection(); }
private void AddAnnotation(IRewriteSession rewriteSession, QualifiedModuleName moduleName, ParserRuleContext context, IAnnotation annotationInfo, IReadOnlyList <string> values = null) { var annotationValues = values ?? new List <string>(); if (context == null) { _logger.Warn("Tried to add an annotation to a context that is null."); _logger.Trace($"Tried to add annotation {annotationInfo.Name} with values {AnnotationValuesText(annotationValues)} to a context that is null."); return; } var annotationText = AnnotationText(annotationInfo.Name, annotationValues); string codeToAdd; IModuleRewriter rewriter; if (context.start.Line == 1) { codeToAdd = $"{annotationText}{Environment.NewLine}"; rewriter = rewriteSession.CheckOutModuleRewriter(moduleName); rewriter.InsertBefore(0, codeToAdd); return; } var previousEndOfLine = PreviousEndOfLine(context); if (previousEndOfLine == null) { //We are on the first logical line, but not the first physical line. return; } if (context.start.Line > previousEndOfLine.stop.Line + 1) { _logger.Warn("Tried to add an annotation to a context not on the first physical line of a logical line."); _logger.Trace($"Tried to add annotation {annotationInfo.Name} with values {AnnotationValuesText(annotationValues)} to a the context with text '{context.GetText()}' at {context.GetSelection()} in module {moduleName}."); return; } codeToAdd = previousEndOfLine.TryGetFollowingContext(out VBAParser.WhiteSpaceContext whitespaceAtStartOfLine) ? $"{whitespaceAtStartOfLine.GetText()}{annotationText}{Environment.NewLine}" : $"{annotationText}{Environment.NewLine}"; rewriter = rewriteSession.CheckOutModuleRewriter(moduleName); rewriter.InsertAfter(previousEndOfLine.stop.TokenIndex, codeToAdd); }
/// <summary> /// Convenience method for validating that a selection is inside a specified parser rule context. /// </summary> /// <param name="selection">The selection that should be contained within the ParserRuleContext</param> /// <param name="context">The containing ParserRuleContext</param> /// <returns>Boolean with true indicating that the selection is inside the given context</returns> public static bool IsContainedIn(this Selection selection, ParserRuleContext context) { return context.GetSelection().Contains(selection); }