-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathJavaLanguageInfo.cs
More file actions
88 lines (74 loc) · 3.29 KB
/
Copy pathJavaLanguageInfo.cs
File metadata and controls
88 lines (74 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace Tvl.VisualStudio.Language.Java
{
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Microsoft.VisualStudio.Text;
using Tvl.VisualStudio.Language.Java.Debugger;
using Tvl.VisualStudio.Shell;
using Tvl.VisualStudio.Text;
using IVsEditorAdaptersFactoryService = Microsoft.VisualStudio.Editor.IVsEditorAdaptersFactoryService;
using IVsTextBuffer = Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer;
using SVsServiceProvider = Microsoft.VisualStudio.Shell.SVsServiceProvider;
using TextSpan = Microsoft.VisualStudio.TextManager.Interop.TextSpan;
using VSConstants = Microsoft.VisualStudio.VSConstants;
[Guid(Constants.JavaLanguageGuidString)]
internal class JavaLanguageInfo : LanguageInfo
{
public JavaLanguageInfo(SVsServiceProvider serviceProvider)
: base(serviceProvider, typeof(JavaLanguageInfo).GUID)
{
}
public override string LanguageName
{
get
{
return Constants.JavaLanguageName;
}
}
public override IEnumerable<string> FileExtensions
{
get
{
yield return Constants.JavaFileExtension;
}
}
public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
{
var componentModel = ServiceProvider.GetComponentModel();
var adapterFactoryService = componentModel.DefaultExportProvider.GetExport<IVsEditorAdaptersFactoryService>();
ITextBuffer textBuffer = adapterFactoryService.Value.GetDataBuffer(buffer);
ITextSnapshot snapshot = textBuffer.CurrentSnapshot;
ITextSnapshotLine snapshotLine = snapshot.GetLineFromLineNumber(line);
string lineText = snapshotLine.GetText();
IList<IParseTree> statementTrees;
IList<IToken> tokens;
if (!LineStatementAnalyzer.TryGetLineStatements(textBuffer, line, out statementTrees, out tokens))
return VSConstants.E_FAIL;
IParseTree tree = null;
for (int i = statementTrees.Count - 1; i >= 0; i--)
{
// want the last tree ending at or after col
IParseTree current = statementTrees[i];
if (current.SourceInterval.Length == 0)
continue;
IToken token = tokens[current.SourceInterval.b];
if (token.Line - 1 < line)
break;
if (token.Line - 1 == line && (token.Column + token.StopIndex - token.StartIndex + 1) < col)
break;
tree = current;
}
if (tree == null)
return VSConstants.E_FAIL;
IToken startToken = tokens[tree.SourceInterval.a];
IToken stopToken = tokens[tree.SourceInterval.b];
pCodeSpan[0].iStartLine = startToken.Line - 1;
pCodeSpan[0].iStartIndex = startToken.Column;
pCodeSpan[0].iEndLine = stopToken.Line - 1;
pCodeSpan[0].iEndIndex = stopToken.Column + stopToken.StopIndex - stopToken.StartIndex + 1;
return VSConstants.S_OK;
}
}
}