Created
March 26, 2018 05:59
-
-
Save ChaitanyaPramod/fe42973e8c983563c86ade8d070daa7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JavaFile brewJava(int sdk, boolean debuggable) { | |
return JavaFile.builder(bindingClassName.packageName(), createType(sdk, debuggable)) | |
.addFileComment("Generated code from Butter Knife. Do not modify!") | |
.build(); | |
} | |
private TypeSpec createType(int sdk, boolean debuggable) { | |
TypeSpec.Builder result = TypeSpec.classBuilder(bindingClassName.simpleName()) | |
.addModifiers(PUBLIC); | |
if (isFinal) { | |
result.addModifiers(FINAL); | |
} | |
if (parentBinding != null) { | |
result.superclass(parentBinding.bindingClassName); | |
} else { | |
result.addSuperinterface(UNBINDER); | |
} | |
if (hasTargetField()) { | |
result.addField(targetTypeName, "target", PRIVATE); | |
} | |
if (isView) { | |
result.addMethod(createBindingConstructorForView()); | |
} else if (isActivity) { | |
result.addMethod(createBindingConstructorForActivity()); | |
} else if (isDialog) { | |
result.addMethod(createBindingConstructorForDialog()); | |
} | |
if (!constructorNeedsView()) { | |
// Add a delegating constructor with a target type + view signature for reflective use. | |
result.addMethod(createBindingViewDelegateConstructor()); | |
} | |
result.addMethod(createBindingConstructor(sdk, debuggable)); | |
if (hasViewBindings() || parentBinding == null) { | |
result.addMethod(createBindingUnbindMethod(result)); | |
} | |
return result.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment