killme2008 / killme2008/aviatorscript

ClassMethodFunction类 addInstanceFunctions方法的使用问题分析

Open
#691 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5.2k
Forks
906
PR merge metrics
No merged PRs in 30d

Description

aviatorInstance.addInstanceFunctions("fnc",Xxxx.class);
对于非静态方法:
pTypes: [Class clazz, 原参数类型...] (长度 = n+1)
jArgs: 直接从所有 args 构建 (长度 = n)
结果: 参数数量不匹配,导致类型转换错误Cannot cast java.lang.String to xxxx.aviator.impl.Xxxx
我目前的处理方式是使用静态方法包了一层,
后面看你的测试类,发现在方法的使用上,要先把方法类对象作为第一个参数传入,这个有优化方案吗
TestUtils t = new TestUtils();
Map env = new HashMap<>();
env.put("t", t);
assertTrue((boolean) this.instance.execute("test.is_empty(t, '')", env));
assertFalse((boolean) this.instance.execute("test.is_empty(t, t)", env));

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at ClassMethodFunction.addInstanceFunctions and reproduce the non-static call using the TestUtils example shown in the issue. Trace how pTypes and jArgs are built for instance methods, then verify that the intended invocation no longer produces the reported type-cast or argument-count error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.