protected override void OnParseComplete(ParseResultEventArgs e) { PreviousParseResult = e as AntlrParseResultEventArgs; base.OnParseComplete(e); }
private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs) { List<IEditorNavigationTarget> navigationTargets = new List<IEditorNavigationTarget>(); IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope; var result = resultArgs != null ? resultArgs.Tree as CommonTree : null; if (result != null) { ITextSnapshot snapshot = antlrParseResultArgs.Snapshot; string package = string.Empty; /* ^('package' qualifiedName) * * ^(CLASS_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}')) * * ^(INTERFACE_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}')) * * ^(ANNOTATION_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}')) * * ^(FIELD_DECLARATION modifiers (.* ^(VARIABLE_IDENTIFIER .*))*) * * ^(METHOD_IDENTIFIER modifiers .* ^(FORMAL_PARAMETERS .* ')') .* ^(METHOD_BODY .* '}')) */ /* STATEMENT COMPLETION (description unrelated to this file) * * IDENTIFIER ('.' IDENTIFIER)* * * ^(CALL IDENTIFIER .*) * * ^('(' ^('==' .*) ')') * */ for (CommonTreeNodeStream treeNodeStream = new CommonTreeNodeStream(result); treeNodeStream.LA(1) != CharStreamConstants.EndOfFile; treeNodeStream.Consume()) { switch (treeNodeStream.LA(1)) { case Java2Lexer.PACKAGE: // ^('package' qualifiedName) { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null && child.ChildCount > 0) { package = GetQualifiedIdentifier(child.GetChild(0)); } } break; case Java2Lexer.VARIABLE_IDENTIFIER: // ^(FIELD_DECLARATION (.* ^(VARIABLE_IDENTIFIER))*) { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null && child.HasAncestor(Java2Lexer.FIELD_DECLARATION)) { string name = child.Token.Text; IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members); var startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; var stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; SnapshotSpan span = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0)); StandardGlyphGroup glyphGroup = StandardGlyphGroup.GlyphGroupJSharpField; StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier((CommonTree)child.GetAncestor(Java2Lexer.FIELD_DECLARATION)); ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style)); } } break; case Java2Lexer.METHOD_IDENTIFIER: // ^(METHOD_IDENTIFIER ^(FORMAL_PARAMETERS formalParameterDecls?) ^(METHOD_BODY .* END_METHOD_BODY)) { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null) { string name = child.Token.Text; IEnumerable<string> args = ProcessArguments((CommonTree)child.GetFirstChildWithType(Java2Lexer.FORMAL_PARAMETERS)); string sig = string.Format("{0}({1})", name, string.Join(", ", args)); IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members); var startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; var stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; SnapshotSpan span = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0)); StandardGlyphGroup glyphGroup = StandardGlyphGroup.GlyphGroupJSharpMethod; StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier(child); ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style)); } } break; case Java2Lexer.ENUM_TYPE_IDENTIFIER: case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER: case Java2Lexer.INTERFACE_TYPE_IDENTIFIER: case Java2Lexer.CLASS_TYPE_IDENTIFIER: { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null) { string name = child.Token.Text; for (ITree parent = child.Parent; parent != null; parent = parent.Parent) { switch (parent.Type) { case Java2Lexer.ENUM_TYPE_IDENTIFIER: case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER: case Java2Lexer.INTERFACE_TYPE_IDENTIFIER: case Java2Lexer.CLASS_TYPE_IDENTIFIER: name = parent.Text + "." + name; continue; default: continue; } } if (!string.IsNullOrEmpty(package)) { name = package + "." + name; } IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types); var startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; var stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; SnapshotSpan span = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0)); StandardGlyphGroup glyphGroup; switch (child.Type) { case Java2Lexer.ENUM_TYPE_IDENTIFIER: glyphGroup = StandardGlyphGroup.GlyphGroupEnum; break; case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER: case Java2Lexer.INTERFACE_TYPE_IDENTIFIER: glyphGroup = StandardGlyphGroup.GlyphGroupJSharpInterface; break; case Java2Lexer.CLASS_TYPE_IDENTIFIER: default: glyphGroup = StandardGlyphGroup.GlyphGroupJSharpClass; break; } StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier(child); ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style)); } } break; default: continue; } } } this._navigationTargets = navigationTargets; OnNavigationTargetsChanged(EventArgs.Empty); }
private void UpdateNavigationTargets(AntlrParseResultEventArgs antlrParseResultArgs) { Contract.Requires(antlrParseResultArgs != null); List<IEditorNavigationTarget> navigationTargets = new List<IEditorNavigationTarget>(); if (antlrParseResultArgs != null) { IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope; var result = resultArgs != null ? resultArgs.Tree as CommonTree : null; if (result != null) { foreach (CommonTree child in result.Children) { if (child == null || string.IsNullOrEmpty(child.Text)) continue; if (child.Text == "rule" && child.ChildCount > 0) { var ruleName = child.GetChild(0).Text; if (string.IsNullOrEmpty(ruleName)) continue; if (ruleName == "Tokens") continue; var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType; IToken startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; IToken stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span); SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)child.GetChild(0)).Token.StartIndex, 0)); var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph; navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph)); } else if (child.Text.StartsWith("tokens")) { foreach (CommonTree tokenChild in child.Children) { if (tokenChild.Text == "=" && tokenChild.ChildCount == 2) { var ruleName = tokenChild.GetChild(0).Text; if (string.IsNullOrEmpty(ruleName)) continue; var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType; IToken startToken = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex]; IToken stopToken = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span); SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)tokenChild.GetChild(0)).Token.StartIndex, 0)); var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph; navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph)); } else if (tokenChild.ChildCount == 0) { var ruleName = tokenChild.Text; if (string.IsNullOrEmpty(ruleName)) continue; var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType; IToken startToken = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex]; IToken stopToken = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span); SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(tokenChild.Token.StartIndex, 0)); var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph; navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph)); } } } } } } this._navigationTargets = navigationTargets; OnNavigationTargetsChanged(EventArgs.Empty); }
private void UpdateNavigationTargets(AntlrParseResultEventArgs antlrParseResultArgs) { Contract.Requires(antlrParseResultArgs != null); List<IEditorNavigationTarget> navigationTargets = null; if (antlrParseResultArgs != null) { IAstRuleReturnScope parseResult = antlrParseResultArgs.Result as IAstRuleReturnScope; if (parseResult != null) navigationTargets = AlloyEditorNavigationSourceWalker.ExtractNavigationTargets(parseResult, antlrParseResultArgs.Tokens, _provider, antlrParseResultArgs.Snapshot); } this._navigationTargets = navigationTargets ?? new List<IEditorNavigationTarget>(); OnNavigationTargetsChanged(EventArgs.Empty); }