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

feat:Spoon agent #2645

Merged
merged 27 commits into from Oct 16, 2018
Merged

feat:Spoon agent #2645

merged 27 commits into from Oct 16, 2018

Conversation

nharrand
Copy link
Collaborator

@nharrand nharrand commented Oct 9, 2018

With the help of IncrementalLauncher and Decompiler, we can propose an abstraction of java standard ClassFileTransformer interface that let an user define Spoon transformations applied on bytecode at load time.

Every time a class is loaded:

  • if it matches a filter
  • it is decompiled
  • its decompiled sources are added to the Spoon Model
  • users transformation are applied on the new CtType
  • the type is recompiled
  • loading resumres

@monperrus
Copy link
Collaborator

This is a pretty neat and unconventional usage of Spoon, I like it :-)

@zielint0
Copy link
Contributor

zielint0 commented Oct 9, 2018

I think it may have an enormous potential of practical uses!

@nharrand
Copy link
Collaborator Author

nharrand commented Oct 11, 2018

Currently this only includes a ClassFileTransformer abstraction, which allows user to implements agent. But may be we should add something similar to Launcher with a real premain that actually load Processor(s) and apply them. A RuntimeLauncher if you will.

WDYT?

@nharrand nharrand changed the title WiP: feat:Spoon agent feat:Spoon agent Oct 11, 2018
File cache;
Set<String> classPath;
public Decompiler decompiler;
Set<File> inputSources;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess all the members above should be private or at least protected. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes definitly.

@pvojtechovsky
Copy link
Collaborator

Nice idea!

I have few comments to design. Actually client has to extend SpoonClassFileTransformer and must implement two methods.
Problems:

  • client has to implement accept even if s/he doesn't need filter.
  • if client extends wrong methods then it will not work

May be it would be nicer if

  • SpoonClassFileTransformer would have method setTransformer(ClassTransformer) ... or ClassTransfomer might be a new constructor parameter.
  • ClassTransformer would be interface with 2 methods: transform(CtType) and boolean accept(CtType)
  • boolean accept(CtType) would be marker default with body return true;
  • optionally there might be method SpoonClassFileTransformer#setFilter(Filter<? super CtType>), which would allow to define extra type filter too.

Then all the implementation can be done by lambda expressions

@nharrand
Copy link
Collaborator Author

@pvojtechovsky Seems like good ideas. I'll try to implement them.

@monperrus monperrus merged commit d9c26c6 into INRIA:master Oct 16, 2018
@monperrus
Copy link
Collaborator

Thanks a lot for this potentially game-changing PR.

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

Successfully merging this pull request may close these issues.

None yet

4 participants