Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DataBinding読みかけ
# DataBinding
## repo
https://android.googlesource.com/platform/frameworks/data-binding
master is quite behind. studio-master-dev seems good.
## Parts
* baseLibrary - base library sources, to be embedded to .apk.
* compiler - APT, expression parser,
* compilerCommon - parser for XML and binding expressions
* developmentPlugins - only 'localizeMavenPlugin' (ignorable?)
* extensions - adapters, and base library sources here too?
* gradlePlugin - only 'DataBindingExcludeGeneratedTask'
## Parsers
XmlParser (compilerCommon/src/main/xml-gen/android/databinding/parser/)
implemented with ANTLR. WTF (実装が雑い...!)
### compiler/src/main/kotlin
android/databinding/tool
layout XMLからコードを生成する必要がある→Kotlinプロジェクトではktを生成
## Android Gradle Plugin integration
### DataBindingBuilder.java (in compilerCommon/..../android/databinding/tool) says:
/**
* This class is used by Android Gradle plugin.
*/
So...
In gradle-core-2.1.0-alphaX-sources.jar.
https://bintray.com/package/files/android/android-tools/com.android.tools.build.gradle-core?order=asc&sort=name&basePath=com%2Fandroid%2Ftools%2Fbuild%2Fgradle-core%2F2.1.0-alpha5&tab=files
- com/android/build/gradle/internal/*TaskManager.java
ただし、用途はほとんどdata binding tool compiler version取得など
### DataBindingProcessLayoutsTask.java in Android Gradle Plugin
in com/android/build/gradle/internal/tasks/databinding/
DataBindingProcessLayoutsTask.processResources()
-> LayoutXmlProcessor.processResources()
-> LayoutFileParser.parseXml()
.stripFile()
-> XmlEditor.strip() - remove <layout> root element.
.parseOriginalXml()
.parseData()
.parseExpressions()
-> LayoutXmlProcessor.writeLayoutInfoFiles()
## その他
compiler/src/main/resources/api-versions.xml - なぜこんなところに?
-> ApiChecker.getMinApi()
-> used everywhere...!
## build intermediaries
- res/merged/debug/layout/* ... step 1.
- data-binding-layout-out/debug/layout/* - stripped out 'layout' and 'value' elements.
- data-binding-info/debug/* - XML like below:
<Layout layout="content_main" modulePackage="name.astshieno.myapplication2" absoluteFilePath="/home/atsushi/Desktop/MyApplication2/app/src/main/res/layout/content_main.xml" directory="layout" isMerge="false">
<Variables declared="true" type="name.astshieno.myapplication2.User" name="user">
<location startLine="3" startOffset="8" endLine="3" endOffset="72"/>
</Variables>
<Targets>
<Target tag="layout/content_main_0" view="LinearLayout">
<Expressions/>
<location startLine="6" startOffset="0" endLine="20" endOffset="14"/>
</Target>
<Target tag="binding_1" view="TextView">
<Expressions>
<Expression text="user.firstName" attribute="android:text">
<Location startLine="18" startOffset="8" endLine="18" endOffset="39"/>
<TwoWay>false</TwoWay>
<ValueLocation startLine="18" startOffset="24" endLine="18" endOffset="37"/>
</Expression>
</Expressions>
<location startLine="15" startOffset="4" endLine="18" endOffset="42"/>
</Target>
</Targets>
</Layout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment