Skip to content
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

Is there any way to be able to mock classes via tai-e at runtime. #114

Closed
Spr1n9T1me opened this issue Aug 15, 2024 · 4 comments
Closed

Comments

@Spr1n9T1me
Copy link

Overall Description

I want to use tai-e to analyze the proxy behavior in java. For example, following spring mybatis code:

import org.apache.ibatis.annotations.Select;

public interface UserMapper {
    @Select("SELECT * FROM users WHERE id = #{id}")
    User selectUserById(int id);

    @Select("SELECT * FROM users")
    List<User> selectAllUsers();
}

Spring Framework uses JDK dynamic proxies to generate proxy implementation classes for these Mapper interfaces. These proxy classes implement the methods defined by the interfaces and perform the corresponding SQL operations. Obviously, these implementation classes are generated at runtime and absent in source codes, which makes it unable for tai-e to analyze the calling relationships here.

Soot seems to be able to mock classes at runtime, such as the following code:

        SootClass clazz = new SootClass("className");
        clazz.setResolvingLevel(SootClass.BODIES);
	clazz.setModifiers(Modifier.PUBLIC);
	clazz.addField(field)
        clazz.addField(sootField)
	clazz.setSuperclass(sootMethod);
	Scene.v().addClass(clazz)

So is there similar APIs in tai-e that makes it possible to mock classes at runtime.

Expected Behavior

none

Current Behavior

none

Tai-e Arguments

none

Tai-e Log

none

Additional Information

none

@zhangt2333
Copy link
Member

Regarding mocking IR, Tai-e currently supports mocking IR within method at the statement level but does not support mocking an entire class. We will take this into consideration in the future.

In terms of semantic modeling, Tai-e offers support for both mocking IR and modeling side effects (you can see their subclasses).

@Spr1n9T1me
Copy link
Author

Appriciate your help! BTW, I noticed that the IR Mocking Model use SignatureMatcher to match target methods, and I found SignatureMatcherTest uses multiple kinds of regex, is regular expression syntax fully supported in this Matcher?

@zhangt2333
Copy link
Member

Appriciate your help! BTW, I noticed that the IR Mocking Model use SignatureMatcher to match target methods, and I found SignatureMatcherTest uses multiple kinds of regex, is regular expression syntax fully supported in this Matcher?

The SignatureMatcher introduces a new expression to balancing readability and functionality, distinct from regular expressions (RE). The feature has already been implemented, and the code has been pushed, though the documentation is still in progress.

We plan to release it along with the documentation in version v0.5.1.

@Spr1n9T1me
Copy link
Author

Got it, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants