从Antlr 4 Dart Parser访问小部件
我想分析颤音源代码,以确定是否使用了文本窗口小部件,其内容为“文本”及其线条。据我所知,我可以使用听众提供的任何CTX访问getText()和getline()方法。
例如,我以功能来做到这一点。 (这是Java代码)
@Override public void enterFunctionSignature(Dart2Parser.FunctionSignatureContext ctx) {
Token methodName = ctx.getStart();
String text = ctx.getStart().getText();
Integer line = ctx.getStart().getLine();
methods.add(methodName);
}
我直接在getStart()的返回令牌的地方使用getline()。
无论如何,dart2parser显然不会以任何方式包含一个令牌,并且如此答案指出,可以有一种使用“对象文字”访问它们的方法。
但是,我还没有找到一种在运行Parsetreewalker时打印小部件或其内容的方法。因此,有什么方法可以访问它们,还是我需要为此进行自定义语法?
例如,在此Flutter代码中进行编辑
,有一个文本窗口小部件,我希望能够提取“设置”或该小部件中注入的任何字符串。重要的是要提到这部分代码在脚手架内部深处,因此ID需要首先进入它。 (除非要求,否则代码太大而无法显示)
ListTile(
leading: Icon(Icons.settings),
title: Text("Settings",style: TextStyle(fontSize:16.0)),
onTap: (){
if(!_loading){
Navigator.push(context,MaterialPageRoute(builder: (context) => Settings()));
}
}
),
I want to analyze flutter source code in order to determine whether a Text widget is used, its content "text" and it's line. As far as i know i can access the getText() and getLine() methods with any of the ctx provided by the Listener.
I do this with Functions, for example. (This is java code)
@Override public void enterFunctionSignature(Dart2Parser.FunctionSignatureContext ctx) {
Token methodName = ctx.getStart();
String text = ctx.getStart().getText();
Integer line = ctx.getStart().getLine();
methods.add(methodName);
}
i use the getLine() somewhere else directly from the returned Token by getStart().
Anyway, the dart2Parser does not include in any way a token for a widget obviously, and as this answer points out, there could be a way to access them with "Object Literals".
However, i havent found a way to print the Widgets or their contents while running the ParsetreeWalker. So is there any way to access them, or would i need to make a custom grammar for that?
EDIT
For example, in this flutter code there is a Text widget used, and i would like to be able to extract "Settings", or whatever string is being injected in that widget. Important to mention that this section of code is deep inside an Scaffold, so id need to be able to get inside it first. (code is too large to show, unless requested)
ListTile(
leading: Icon(Icons.settings),
title: Text("Settings",style: TextStyle(fontSize:16.0)),
onTap: (){
if(!_loading){
Navigator.push(context,MaterialPageRoute(builder: (context) => Settings()));
}
}
),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论