summaryrefslogtreecommitdiff
path: root/compiler/src/main/java/android/databinding
AgeCommit message (Collapse)Author
2019-02-07Fix "Cannot find symbol ...<E>" error in generic parametersDavid Herman
Due to a bug in the code generation logic, generic variables that don't have their type specified cause compile errors. e.g. this works fine <variable type="java.util.List<Integer>" ... /> but this was broken: <variable type="java.util.List" /> Change-Id: I7ef8f23ff01cace11f7613c5fc926b9a100fdd5f Fixes: 123409929 Test: Integration tests updated
2019-02-01Incap: Make data binding incremental (2/3).Hung Nguyen
See CL 1/3 for full context. This CL adds a META-INF file indicating that data binding is a "dynamic" incremental annotation processor ("dynamic" means that its actual type will be determined later at run time). At run time, if the android.databinding.incremental feature flag is true, data binding will register with Gradle that it is an "aggregating" annotation processor. Otherwise, it will remain a non-incremental annotation processor. Test: See CL 1/3 Bug: 110061530 Bug: 117725060 Change-Id: If17d83d9c3dd56d743b53808a872e0937fec9879
2019-01-17Add support for dependency artifact packagesYigit Boyar
This CL adds a new argument to the compiler args that has the list of packages that are directly accessible. Normally, data binding discovers this automatically from avaiable classes but blaze/bazel makes transitive dependencies available, which makes data binding access them and then break strict deps rules. This new flag is not used by gradle. I've also updated the google3 push script to partial jetify classes since Google3 is jetified in pieces. Bug: 119645762 Test: google3 Change-Id: I0f2d330671b9b046f591a29a6cae0b7b5e4a6096
2019-01-14Prepare data binding for incremental annotation processing.Hung Nguyen
This CL updates data binding so that it can support incremental annotation processing in the next CL: 1. Add missing supported annotation types to ProcessDataBinding as Gradle needs to know about all supported annotation types. 2. Remove RetentionPolicy.SOURCE in BindingBuildInfo as Gradle needs to see the annotations in the *class files*. Also remove unused buildId() method in BindingBuildInfo. Test: Existing tests Bug: 110061530 Bug: 117725060 Change-Id: I0b4255b556a72ad8725a39b95b5061d38f11d3bd
2019-01-08Update data binding errors for readabilityDavid Herman
Also, update how databinding errors are encoded, using JSON instead of our custom format. This both reduces boilerplate parsing code, and also helps as error messages now contain newlines in them, which was causing issues with the previous logic. Change-Id: Idcf6c984187121e7759b0c1b86a8024edb7f6679 Fixes: 120626727 Fixes: 62685775 Bug: 119440634 Test: Mostly covered by existing tests; some tests updated to use ErrorMessage constants; SafeUnboxingTest removed as the warning is no longer shown
2019-01-08Fix two way binding for field access expressionsYigit Boyar
This CL fixes a bug in FIeldAccessExpr's two way resolution logic. FieldAccessExpr is the last stop in two way resolution as it is either targeted to a view (check for two way) or not (nothing to do). But this breaks in cases where it might have nested access levels. e.g. textView.text.length has a nested FieldAccessExpr which is two way (textView.text) but the target for the parent is textView.text which is a FieldAccessExpression. Previous logic was stopping resolution when it is not ViewAccess but it should've continued to call the parent to check nested items. Bug: 116536168 Test: TwoWayBetweenViewsTest Change-Id: I74e9c62ee21fc06f6128c6baaebde21496c495b9
2018-12-14Update data binding for blazeYigit Boyar
This CL changes some compilation to be compatible with blaze, updates the google3 push script and adds more logging. Bug: 112038432 Test: existing tests and g3 taps Change-Id: I58737cf8c7e6daa6d131cd35cf72d2cff7d3d7a9
2018-12-01Close reader to avoid leaking file descriptors.Jerome Dochez
Test: fixed tests on Windows. Bug: N/A Change-Id: I2b9f4e86f50361475ec5281fa4bfbf659ac4264a
2018-10-29Cache found classesYigit Boyar
We spend a lot of time re-finding same classes and then querying their properties. This CL introduces a new class finder cache that holds onto already found classes keyed by its name and available imports. The hit rate for TestApp is quite crazy (97%) and brings down no-cache compilation from 3 sec to ~ 2.5 sec. Bug: 117808327 Test: ClassFinderCacheTest Change-Id: I1981627588fe411b1970df99c722a91fe4b657b2
2018-10-19Change ModelClass to use Lists instead of ArraysYigit Boyar
This avoids creating an unnecessary array. Also moved Injected class to be kotlin as well. Bug: 117808327 Test: existing tests Change-Id: I481106b1089e5d1066ec0733683876926d519fad
2018-10-19Move ModelClass to kotlinYigit Boyar
Bug: 117808327 Test: existing tests pass Change-Id: Iec0d01d9c0d76d8889794ee1fa3a69cbca115128
2018-10-17Move ModelAnalyzer & AnnotationModel to KotlinYigit Boyar
This is a preliminary cleanup step before adding more caching to these classes. Bug: 117808327 Test: n/a Change-Id: I888d4506b5079b8904d59955c9006397b68f0368
2018-10-17Move imports to a concrete classYigit Boyar
This CL moves Map<String(alias), String(qname)> imports to a concrete ImportBag class. It is mostly a cleanup so that in a follow-up CL, we can start caching findClass calls based on available imports. Right now it is not possible since imports are all bloated with java.lang. This CL also stops adding all java.lang.* as static identifiers to every single model. Instead, it lazily registers it if an identifier expression cannot be found and name matches a java.lang class. Bug: 117808327 Test: ImportBagTest, existing tests pass Change-Id: Ideb41ab8cfc68aa4c7b55e84ffa218ba65558eb3
2018-10-15Don't generate V1Compat mapper for libsYigit Boyar
This CL fixes a bug where if a module depends on a V1 library, we would generate the V1 mapper for it which does not compile because R files for V1 are not final at that stage. We should actually not generate it and instead delegate the application to do it. We still generate the stub binding for those so that the code can compile but we'll strip them as usual. Bug: 117666264 Test: MultiModuleTestApp with LibCompiledWithV1 dependency Change-Id: I9cc6b04573776141b021d0d516f10fc0213e8270
2018-10-10Auto jetify during class findingYigit Boyar
This CL fixes an issue in data binding where if a binding adapter from a dependency was writting in android.support and app is using androidX, we would not be able to use it. Now, the annotation class finder automatically jetifies a class if it cannot find it. This CL also updates BindingAdapterStore to ignore all android.databinding.adapter* artifacts which might lurk into dependencies if the dependency was compiled with V1. This CL also includes a small optimization in ModelAnalyzer where we would always query a known class even if it is not there (e.g. LiveData). This avoids such unnecssary queries. Bug: 117266727 Test: MultiModuleTestApp Change-Id: Ic8079160f8a5aa3c14c40f673a6339c090fa9f9a
2018-09-27Null check class analyzer callsYigit Boyar
This is a quick fix to null check class anayzer results to avoid NPE while traversing adapters. It is tricky to test since this only happens with a dependency that was both compiled with android.support and pre 3.2 version. This is why I've added LibCompiledWith3.1 to the list of integration tests which is compiled manually and the final aar is put under MultiModuleTestApp/app/libs. Bug: 116361870 Test: MultiModuleTestApp Change-Id: Ibaf6174980de08d50b0ef1b9679db6cf99e1121a
2018-09-24Use qualified R for included layoutsYigit Boyar
An included layout might be coming from a dependency and if that dependency is a feature (base feature), we need to use the correct R.layout file. This will also be necessary with namespaced resources. Bug:112042862 Test: InstantApp integration test Change-Id: Iaaf99ab7a9f7ac03757cdea19c8ddc111505d9ed
2018-08-07Fix binding adapter de-duplicationYigit Boyar
This CL fixes a bug in binding adapters where it would crash compilation when there is a conflict in keys. Now we check the data before failing and also print a warning instead of an error since app might be overriding dependencies. Bug:37100286 Test: MultiModuleTestApp#GeneratedLayoutTest.testOverriddenAdapters Change-Id: Idee39ed81bc4e52be39df1362fbed29700a4b8b7
2018-07-13Update exec path to support blaze.Yigit Boyar
This CL brings back support for old args to support google3 blaze which cannot update in lock step (e.g. cannot move to new args w/o updating the library). So in this CL, we make data binding args backwards compatible. It also fixes the encoding for layout-info files which only affected google3. Bug: 111400388 Change-Id: I32a6f7807892f938bcdc12d55b19ae38f6750342 Test: in google3
2018-07-10Consistent SetterStore outputYigit Boyar
This CL changes the Intermediate format for SetterStore to use sorted maps that are later serialized into JSON. This will allow us to make future changes in the Intermediate format w/o breaking compatibility. To accomodate it, GenerationalClassUtil now supports JSON type. I've also de-coupled the information storage into a BindingAdapterStore class to make sure that SetterStore cannot dig into details of that class. This way, we can serialize just the adapter in this class, minimizing unexpected invalidations. Bug: 80553728 Bug: 110855984 Test: DataBindingMultiModuleTest.kt Change-Id: I9800e075b3317228e7f96ca6dfc84f6f2e0cc22d
2018-06-19Refactor data binding to use BuildableArtifacts (2/2).Hung Nguyen
Fixes: 110198434 Bug: 69243050 (related by not fixed by this CL) Test: Refactoring change - Should be covered by existing tests Change-Id: I39534def1220cbda3950c39ce26e0d7eba2fab8b
2018-06-01Data Binding gradle implementation API supportYigit Boyar
This CL adds support for using "implementation" dependencies in gradle, greatly reducing compilation times if app is setup properly. There are 2 big changes: * SetterStore will not use an adapter if it is not available in the compile classpath * MergedDataBindingMapper will only initialize the App's mapper. Each time a mapper is added, we ask it to provide it's dependencies. This way, an app can initialize all of its dependencies w/o directly calling them out. Bug: 77539932 Test: MutliModuleTestApp#connectedCheck Change-Id: I686b06180a062c071f1577cb782897ff6cce1199
2018-05-18Fix kotlin.Unit method references in binding layouts.Yigit Boyar
When there is a binding adapter that receives a kotlin function which does not return, Kotlin converts it to Function0<kotlin.Unit>. But if there is a kotlin class with a method that does not return value, kotlin converts it to void. This becomes a problem for data binding because it cannot match the two when using function references. We cannot simply convert kotlin.Unit to void because we still generate code in java so we have to return a value in the implementation. Instead, this CL changes function matcher to accept the two as equals and also changes the code generators to handle the case manually. Also added a kotlin test app (finally). Bug: 70915745 Bug: 78662035 Test: KotlinTestApp Change-Id: I019ee7eb1dd635b12efd7725ccc22f0c63dc2d72
2018-05-01Refactor data binding to use Gradle ArgumentProvider (2/2).Hung Nguyen
This is the preparation step to make data binding work with task output caching in a subsequent CL. Test: N/A (no functional changes) Bug: 69243050 Change-Id: Icff729cb87465d0a158771ed3ee84d731bc819d3
2018-04-09Integration tests w/ AndroidXYigit Boyar
This CL adds integration tests w/ AndroidX and fixes some androidX issues that i've discovered during the move. Old tests are copied to integration-tests-support so that we still run them. I tried to keep the tests as similar as possible but sometimes needed to move classes (e.g. for cases where we have package private access). I've changed the applicationId of TestApp to use a different package so that it wo't conflict w/ the other one while testing on the same device. For other simpler tests, we were not using android.databinding so i just changed their package names not to conflict w/ their twins. I've also removed App With Spaces test which does not work w/ gradle5 anymore and we were not running it anyways. Bug: 77166878 Test: new andoridX tests Change-Id: I86f68fd6bee2ca849c6472c0411234bb3a08b132
2018-03-30Data Binding Android X supportYigit Boyar
This CL adds partial support for Android X. We duplicate baseLibrary and extensions (runtime libs) to have copies that are in the androidX namespace. Gradle picks the right version to include based on shared androidX flag. Right now, we have only 1 test that use androidX (DataBindingIncrementalTest) so all other tests still use the old package. I'll add testing for androidX in a followup CL. Bug: 77166878 Test: existing tests pass Change-Id: I77ec65b872cae0821513ca78ef9b6ab1b0300ed1
2018-03-09Support v1 dependencies in v1 compilationYigit Boyar
This CL adds backward compatibility into data binding v2 such that it can consume dependencies that were compiled with v1. We achieve this in 2 steps: * Inside the gradle task, we deserialize v1 layout info and convert it into GenClassLog. This allows gradle task to generate the right code. (albeit, it might depend on not yet existing classes but that is how v1 works anyways). * Then in the annotation processor, we reload the same layout info, create a CompilerChef that thinks it is in v1 and let it generate the code. Finally, we create 1 mapper for all v1 compat classes. All code generated for v1 is stripped for libraries. This is necessary because if 2 separate libraries in an app depend on the same v1 lbirary, both of them will generate code for it, causing duplicate class issues. For apps compiled w/ v2 and has v2 dependencies, cost is almost none (is just the gradle task has 1 more dependency). For apps compiled w/ v1 and has v1 dependencies, it is as slow as v1 is, + a bit more since we end up writing mode classes than we would but it is negligible. Bug: 74264651 Test: MultiModuleTestApp (gradle invokes it w/ v1 - v2 setup) Change-Id: I0e04e7f04b67eb010d4a1bf32e0fce32586a4b90
2018-03-06Hacky solution to clean lazy mappingYigit Boyar
From the early days of data binding,we have an easy way to add properties to java objects w/o adding them the complexity of codegen. It is causing problems now since they are static and kept foreever. This CL just adds a hack to clean them up afterwards. Bug: 68339615 Test: n/a Change-Id: Ibf79d9cfb53dbc19f0ed590f492a0db60a3f5703
2018-02-16Enable featuresYigit Boyar
This CL adds a new build type called FEATURE, which is a new version where we generate BR classes for only runtime dependencies (dependencies that are not inherited from base or any other feature). This new BR file generation logic looks up the existing ids and re-uses if the BR id matches the id in a dependency. For any other id, we generate them with an offset (provided by gradle) so that it cannot conflict w/ other features. The integration test app is not a real test app right now because features do not support instrumentation tests. It is more of a manual testing ground until features have the capability. Bug: 63814741 Test: in the other CL Change-Id: I6f3feda908b3925a29ff76a29cd3659cab3f8f8d
2018-02-08Remove dynamic util.Yigit Boyar
This class was only necessary when we had 2 different release cycles. We don't need it anymore, even for backwards compatibility. if developer is in v1, the library's code is regenerated so it won't use DynamicUtil. If developer is in v2, it was broken for libraries so there is no way that a library w/ dynamic util reference exist. Bug: 73020925 Test: TestApp/IndependentLibraryTest Change-Id: Id43ca24a096de16c89c0913ee309ba29accccdcb
2018-01-25Hacky solution to clear singletons from data binding.Yigit Boyar
Bug: 68339615 Test: existing tests pass Change-Id: I8a9004bc7b2e7c9cfe3b0ad914c721d77069d46e
2018-01-10Merge "Default to unwrapping ObservableFields for Object method params" into ↵TreeHugger Robot
studio-master-dev
2018-01-09Default to unwrapping ObservableFields for Object method paramsGeorge Mount
Bug: 70367050 ObservableFields were only unwrapped when it couldn't be assigned to the target type of the method parameter. When the parameter type is Object the ObservableField matched and that isn't what the developer wants. Test: ran TestApp tests Change-Id: I300c8a009575fb219c4f1a615e194fb743d7c46d
2018-01-09Detect common null check ternary opsYigit Boyar
This CL adds logic to the Ternary expression to avoid unboxing if the predicate is a null check. e.g. if it is a == null ? b : a, we don't need to unbox for the false statement because it will not be executed if a is null. This is not a complete nullability detection code, it only covers the common cases. Bug: 37127560 Test: SafeUnboxingTest Change-Id: I7a090b7dc92f1c127cc3b63f7eab3f6c37a250a8
2017-12-27Ignore serial uid for IntermediateV1Yigit Boyar
This CL fixes a backward compatibility issue by ignoring the serial id in a class which we forgot to put a serial id. Bug: 71057619 Test: local Change-Id: I345ed2e6296ab6b338809153a38ac16052af2433
2017-12-12Merge "Revert "Do not include package name twice in the name of generated ↵Yigit Boyar
files"" into studio-master-dev
2017-12-12Revert "Do not include package name twice in the name of generated files"Yigit Boyar
This reverts commit 252fee6b12d9b69176c007f54ab060f96e6c679e. Reason for revert: The change broke blaze integration. Change-Id: I5e6bc9fb8b02085acae8d32119dd64cc9f912cf3
2017-12-05Generate data binding mappers in librariesYigit Boyar
This CL changes compilation to generate mappers in libraries. Then they are merged in the mapper generated by the app. This is 1 step further to keep generated code in libraries. Now we only have data binding component and BR left. Bug: 68392907 Test: existing tests pass Change-Id: Id3c68429fa157d9f7969890d0a4c8a344899a7f4
2017-12-01Revert "Revert Change I6e5c5a77"George Mount
This reverts commit 7ed559d3b0cb484549fda48abe1b7244343b5308. Reason for revert: The build now works after CL I39c8c25b90ec58a8b452e34310b57acc4b77c1d1 Reverted unnecessary BUILD.bazel changes Test: bazel, ant, and gradle builds Change-Id: If78b462fa9cb0ed2c10dd1a52a4f94b87e46c840
2017-12-01Keep generated binding codes in librariesYigit Boyar
This CL changes data binding to not strip binding code that is generated for libraries. This will allow data binding to be more incremental and only generate binding code for the current app/module. Generated DataBindingMapper and BR classes are still stripped as they require final R class and/or final list of BR classes. Bug: 68392907 Test: existing tests pass Change-Id: I39c8c25b90ec58a8b452e34310b57acc4b77c1d1
2017-12-01Revert Change I6e5c5a77Dana Dahlstrom
… which caused compilation to fail in the continuous build. Change-Id: I194506416d5db43e828ada65efa1c79e29eec885
2017-11-30Fix problem with wrong InverseBindingAdapter being chosen.George Mount
Bug: 65167377 The wrong inverse binding adapter was being chosen because priority was given improperly. This CL adjusts the way priority is given so that it is consistent between parameters accepting arguments and return values being set to values. Test: CollisionAdapterTest Change-Id: I6e5c5a77d664ddda29313e3570fc579af70a1fd4
2017-11-28Generate base binding classes in gradleYigit Boyar
This CL adds a new gradle.property called android.databinding.enableV2 which enables a new compiler setup in data binding. In that setup, generated binding classes that are accessed by user code are created with the Data binding source gen task rather than the annotation processor. This works around a problem in javac where if the compilation fails for any reason, it would print an error for each place user accesses this generated code, practically hiding the actual error in a moderate size project. Bug: 68393034 Test: existing tests pass, gradle plugin runs tests both in v1/v2 Change-Id: If25049a308160c3646983f26e69580a10aabde1d
2017-11-27Make LiveData observable by data binding.George Mount
Bug: 36122539 Data binding needed to support observing LiveData with a LifecycleOwner. This CL adds listening to LiveData change events. If no LifecycleOwner exists, the LiveData will not be observed. Test: LiveDataTest Change-Id: I76b0a4d38a9107a0fd7f6e03594aea49be9d645b
2017-11-10Integrate data binding build with tools buildYigit Boyar
This CL makes data binding runtime build part of tools as well, allowing us to run presubmit with tools. Integration tests are now run via gradle or bazel. bazel/bazel test //tools/base/build-system/integration-test/src/test/java/com/android/build/gradle/integration/databinding/... --test_output=streamed Bug: 68392816 Test: existing tests pass Change-Id: I88a47dcde85e519b281fee63791757a713b314b0
2017-08-14Fix lambda expression referencing two-way bound property.George Mount
Bug 64645736 When a lambda expression referenced a two-way bound view property, it would error. This fixes two problems. First, the sub-expression wasn't being replaced in the lambda expression's model. Second, the lambda expression was being sealed before the inverse binding substitutions were being made. Test: gw runAllTests Change-Id: If8ac14f7203404da97f61e8dee7c44e338db0eba
2017-08-04Do not include package name twice in the name of generated filesSergey Prigogin
Test: existing tests Change-Id: Iab53d01f5bb6dd486bfe45aceb58db811a0c8027
2017-08-03Generate BR.java for dependent libraries when compiling librariesSergey Prigogin
Test: cd tools/data-binding; ./gradlew runTestsOfMultiModuleTestApp Bug: 63118321 Change-Id: I68ba49dfa14ef9906fcb349bc358115522188463
2017-07-31Fix case statements are not generatedKenji Abe
When using ObservableFields wrap BaseObservabale extended class, notifyPropertyChanged does not work. Set Expr parent to unwrapped ObservableFields to generate case statements for notifyPropertyChanged working. https://issuetracker.google.com/issues/37137588 Test: gw runAllTests Change-Id: I755061f32cc3562c344c45bedc3abb35629341b3 Signed-off-by: Kenji Abe <kenji.01.star@gmail.com>
2017-07-31Make changes so tests start passing.George Mount
Fixed gradle version. Removed obsolete test. Removed test for legacy versions. Test: gw runAllTests Taken from: Ia5a37722af011a41efbffe6ae809917a722b93a2 Change-Id: Id313c1118f267071d671f02b7f08d370b9979cc2