-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qlexpress #2978
base: master
Are you sure you want to change the base?
Qlexpress #2978
Conversation
# Conflicts: # core/pom.xml # pom.xml
|
缺少测试,有冲突需要解决。 |
# Conflicts: # core/src/main/java/com/taobao/arthas/core/GlobalOptions.java # core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
* 是否切换使用表达式ognl/qlexpress开关 | ||
*/ | ||
@Option(level = 1, | ||
name = "express-type", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是可以考虑短一点,比如就缩写成 el(expression language)
* qlexpress使用参数 | ||
*/ | ||
@Option(level = 1, | ||
name = "qlexpress-config", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这么复杂的东西暂时没必要交给用户设置吧。我们直接给一个最推荐的就行了,没必要暴露给用户,毕竟这个场景比较单一,给个通用配置就够了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
public QLExpress(ClassSupplier classResolver) { | ||
initQLExpress(classResolver); | ||
initConfig(); | ||
initContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实这三个函数就是分别初始化三个成员变量,下面这种写法可能更加清晰:
this.expressRunner = initQLExpress(classResolver);
this.qlOptions = initConfig();
this.qlGlobalContext = initContext();
尽量不要使用有副作用的函数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
|
||
@Override | ||
public Express bind(String name, Object value) { | ||
qlGlobalContext.put(name, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
个人觉得在 put 的是很加上 "#" 前缀,要比 get 的时候 replace 要好。这样 context 的逻辑更加简单纯粹。replace 可能会导致改变不该改变的字符。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
||
public void clear() { | ||
context.clear(); | ||
this.context.put("reflectLoader",reflectLoader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的用处是?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
每次bind之前调用清理现成参数
if ((this.reflectLoader != null) && (this.object != null) && !variableName.startsWith("#")) { | ||
return this.reflectLoader.loadField(this.object, variableName, true, PureErrReporter.INSTANCE); | ||
} | ||
String newVariableName = variableName.replace("#",""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
个人觉得在 put 的时候加上前缀,比 get 的时候隐藏一个 # 替换逻辑要更好
@Override | ||
public Value get(Map<String, Object> attachments, String variableName) { | ||
if ((this.reflectLoader != null) && (this.object != null) && !variableName.startsWith("#")) { | ||
return this.reflectLoader.loadField(this.object, variableName, true, PureErrReporter.INSTANCE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 api 有点底层,可以考虑继承 ObjectFieldExpressContext,然后额外加一个 map 功能,而不是直接调用 reflectLoader。或者我直接在 Express4Runner 上开个 api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待讨论点
* @Author TaoKan | ||
* @Date 2024/9/22 12:39 PM | ||
*/ | ||
public class QLGlobalContext implements ExpressContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑继承 ObjectFieldExpressContext 添加额外功能
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new ObjectFieldExpressContext(runner);
+ " ognl -c 5d113a51 '@com.taobao.arthas.core.GlobalOptions@isDump' \n" | ||
+ Constants.WIKI + Constants.WIKI_HOME + "ognl\n" | ||
+ " https://commons.apache.org/proper/commons-ognl/language-guide.html") | ||
+ " ognl '@java.lang.System@out.println(\"hello \\u4e2d\\u6587\")' \n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是也得有一个类似 ognl 这样的纯执行 qlexpress 表达式的命令
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待讨论点
支持切换ognl语法为qlexpress,具体详情输入options语句查看,默认ognl
除了ognl命令,其余的命令均支持切换,使用的qlexpress语法为qlexpress4的语法
对于观察表达式,默认值:OGNL用法{params, target, returnObj} --> QLEXPRESS用法[params, target, returnObj]
举例
OGNL语法
$ watch demo.MathGame primeFactors '{params, returnObj}' '#cost>200' -x 2
QLEXPRESS4语法
$ watch demo.MathGame primeFactors '[params, returnOb]' '#cost>200' -x 2
条件表达式同样需要满足qlexpress语法
https://github.com/alibaba/QLExpress/tree/v4.0.0-beta.1