Designing Auto Generated Codes
-
Upload
hiroshi-kikuchi -
Category
Technology
-
view
1.269 -
download
3
Transcript of Designing Auto Generated Codes
• Hiroshi Kikuchi (@kikuchy)
• Belonging to , inc , Working on , inc (mixi group)
• Making “Dating App” for Android
• Strict review OJISAN
Who am I
If you make an awesome library hiding generated codes…
// Fields@ExecuteSomethingString foo;
// Executor class “ThisClass$$Executor” is generated.// My library loads executor class automatically!AwesomeLibrary.execute(this);
If you make awesome “proguard-safe” library…
// Fields@ExecuteSomethingString foo;
// Executor class “ThisClassExecutor” is generated.// There are no reflection, no ClassNotFoundException!!new ThisClassExecutor().execute(this);
Bob often asks you “What’s the name of Generated Classes and methods and constructor arguments and
interfaces will use in Generated Code blablabla…”
“Why ask me repeatedly”? Why I have to remember invisible codes?
Bob
<
https://www.flickr.com/photos/greeblie/2190709020/
/ / / / / | / `、 i ! |i i , l / / // / | / | | | l ! i | | `/ー- 、 / / | / | l | l l ! ! i / ,,,,- ニ=x- 、_ !/ |i _, +十'イ i ! ! ''" / :;;r jヽ ` ̄ リ ,, -=、 レ | / / :| /:::::;;;;;;;:`::::::l / :;;r ヽヽ |/| / :! |::::::::;;;;;;;;:::::::l l:::;;;;;` ::| l // :! '、:_ '''' ノ l '''' ノ | / :| ::::::::..  ̄ ` ー ' ,' :| :::::::::::: , ..::::::::::::..l .:| :| :::::::::: :::::::::::::::::::| :| :| Mmmm… ::::::::::::::: l .:| l :| / :| :l :| , ' :::| :| :| ` 、 ⊂ニ==ー‐- , イ ::::| :| :|
Compare patterns“Butter Knife” pattern (hiding generated codes)
“Dagger2” pattern(no reflection)
How to load generated codes Library dose everything Developers have to import
Proguard configuration is needed not needed
Developers have to learn only usage of library + generated class naming rules
Type-Safe No Yes
Don’t forget proguard conf?
Start ↓
Like beautiful API?
Is not solidity app necessary? → →
Yes
No↓
“Dagger2” pattern
→
No
Yes
↓ No↓
“Dagger2” pattern “Dagger2” pattern
“Butter Knife”
pattern
Yes
• Java Annotated Source Codes
• Using APT.
• ex) Dagger2, ButterKinfe, JsonPullParser, etc…
• Externals
• Gradle Task (depends on “compileJava” task)
• ex ) R.java, genum (← I’m developing now!!!!!!!!!!!)
Source of Source Codes
Generated Class Depends on…• Only Interface
• MyOwnInterface instance = new GeneratedClass();
• ex) Dagger2, (Retrofit)
• Library Classes
• LibrarySuppliedBase instance = new GeneratedClass();
• ex) Shillelagh, etc…
• Nope || Unknown
• (Generated classes are hidden.)
• ex) ButterKnife, IntentBuilder, DeepLinkDispatch
public class UserSearchRequest { public EnumSet<UserKind> kind; public String freeWord; public int ageMax;
…}
@ToQueryMappublic class UserSearchRequest { @QueryParam(name = “kind”, adapter = UserKindAdapter.class) public EnumSet<UserKind> kind;
@QueryParam(name = “free_word”, adapter = StringAdapter.class) public String freeWord;
@QueryParam(name = “age_max”, adapter = IntAdapter.class) public int ageMax; …
public final class UserSearchRequestSerializer { public Map<String, String> serialize(UserSearchRequest request) {
Map<String, String> map = new Map<>(); map.put(“kind”, userKindAdapter.adapt(request.kind)); map.put(“free_word”, stringAdapter.adapt(request.freeWord)); map.put(“age_max”, intAdapter.adapt(request.ageMax)); …
return map;}
GENERATED