Skip to content

Add python script for generating brige and wrapper code.#1

Open
sqliu wants to merge 12 commits intowang16:reflection_layerfrom
Shouqun:add-reflection-generator
Open

Add python script for generating brige and wrapper code.#1
sqliu wants to merge 12 commits intowang16:reflection_layerfrom
Shouqun:add-reflection-generator

Conversation

@sqliu
Copy link
Copy Markdown

@sqliu sqliu commented May 30, 2014

For share mode in core, use python script to generate bridge and wrapper code.

BUG=

Shiliu Wang added 11 commits May 29, 2014 10:26
This script is used to create xwalk core internal from
current xwalk core.
The reason to scripten this process is to make it easy
for rebasing.
The whole feature for shared xwalk core is so complex that
it will take amount of time to review. The rebase for
moving core to core_internal will be a nightmare then.
The commit is generated by create_internal.py.
It contains renaming the package and rename the classes
Embedding API exposes with "Intenal" suffix appended.
1. Previous commit does:
  a. Move all xwalk core java classes include extension related to
     xwalk core internal.
  b. Rename all classes Embedding API exposes as ClassInternal.
2. This commit does:
  a. Create a thin layer which is now xwalk core, simply wraps core
     internal and override the functions returns internal objects
     by creating and returnning wrapped objects in xwalk core.
  b. Create target core_internal_java and let core_java depends on it.
  c. Some necessary package name changing in tools and scripts.
… core library

For core library usage, the internal resources ids are mapped to
org.xwalk.core.R at runtime dynamically to ensure the ids using
internally is correct.

Since now xwalk core uses org.xwalk.core.internal.R instead of
org.xwalk.core.R, the ids in org.xwalk.core.internal.R also
needs initialization before use at runtime.
enum type is not friendly to be used in reflection. Use int instead.
Generator is a java project which depends on xwalk core internal
to get class definitions.
When executing Generator, it will read the class from specified
list and generate wrapper/bridge class of it based on annotation
XWalkAPI.
The bridge class belongs to internal package, provides two functions
for each API internal class wants to expose: wrapperCall and superCall.
wrapperCall is to call wrapper which might be overriden by embedders.
superCall is to call internal which is called by wrapper for default
implementation.
The wrapper class belongs to core package, provides API to embedders.
Wrapper class will call bridge's superCall by default.
If no overridden by embedders, the call stack will be:
bridge::foo => wrapper::foo => bridge::fooSuper => internal::foo.

TODO:
1. Documentation annotation support, currently all documentation annotation
is in internal class. Need to automatically generate those annotation in
wrapper class.
2. GYP dependency, in gyp world, each java target will add its output to
jars_input_paths of dependent target. For reflection layer, it depends
on core_internal, but in future after real reflection established, the
shared embedders don't want to include core internal in it's APK.
… in XWalkAPI

If a class declares instance in its XWalkAPI annotation, use that class's
bridge type in other classes' bridge call.
Previously, the invoking between wrapper bridge is still directly
funtion call. This commit turns them into real reflection.

Including following parts:
1. Method call will use bridge/wrapper object to get Class and then
get method to invoke. The methods for all exposed API will be get
at instance creation time to avoid getting method object for each call.
2. Static method has no instance to get Class, it has to use class
name to get Class. So it will try to load method for each call.
3. Constructor is complicated, for each class which is not interface,
will register all their constructors' parameter list to ReflectionHelper
in static area. When ReflectionHelper got initialized with specified
ClassLoader, will try to load all registered constructor. Each constructor
will be assigned a unique string to use.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do we need to consider generic type here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

currently I haven't met generic type to be processed, maybe for further this should be added, I'll add a TODO here

For share mode in core, use python script to generate bridge and wrapper code.

BUG=
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

method_return might need to be mangled?

@sqliu
Copy link
Copy Markdown
Author

sqliu commented Jun 3, 2014

@wang16 script updated, thanks!

@wang16 wang16 force-pushed the reflection_layer branch 2 times, most recently from 781ccea to 88dc0bc Compare August 22, 2014 08:49
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.

3 participants