├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_fragment.xml
│ │ │ │ ├── fragment_main.xml
│ │ │ │ ├── fragment_transitions.xml
│ │ │ │ └── activity_transitions.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── bennyhuo
│ │ │ │ └── tieguanyin
│ │ │ │ └── sample
│ │ │ │ ├── utils
│ │ │ │ └── ActivityUtils.kt
│ │ │ │ ├── App.kt
│ │ │ │ ├── PrimitiveDefaultTestActivity.java
│ │ │ │ ├── FragmentContainerActivity.kt
│ │ │ │ ├── inherited
│ │ │ │ └── AbsActivity.java
│ │ │ │ ├── inner
│ │ │ │ └── OutterClass.java
│ │ │ │ ├── childfragment
│ │ │ │ ├── ParentFragment.kt
│ │ │ │ └── ChildFragment.kt
│ │ │ │ ├── EditUserActivity.java
│ │ │ │ ├── fragments
│ │ │ │ ├── KotlinFragment.kt
│ │ │ │ └── JavaFragment.java
│ │ │ │ ├── transitions
│ │ │ │ ├── DetailsActivity.kt
│ │ │ │ └── DetailsFragment.kt
│ │ │ │ ├── KotlinActivity.kt
│ │ │ │ ├── GenerateBothActivity.kt
│ │ │ │ └── UserActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bennyhuo
│ │ │ └── tieguanyin
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── annotations
├── .gitignore
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── annotations
│ │ ├── ResultEntity.java
│ │ ├── SharedElementWithName.java
│ │ ├── SharedElement.java
│ │ ├── SharedElementByNames.java
│ │ ├── PendingTransition.java
│ │ ├── Generated.java
│ │ ├── Required.java
│ │ ├── GenerateMode.java
│ │ ├── Optional.java
│ │ └── Builder.java
└── build.gradle
├── app-java
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── layout
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── fragment_main.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── bennyhuo
│ │ │ │ └── tieguanyin
│ │ │ │ └── javademo
│ │ │ │ ├── App.java
│ │ │ │ └── fragments
│ │ │ │ └── JavaFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bennyhuo
│ │ │ └── tieguanyin
│ │ │ └── javademo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── javademo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── compiler
├── .gitignore
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ ├── services
│ │ │ └── javax.annotation.processing.Processor
│ │ │ └── gradle
│ │ │ └── incremental.annotation.processors
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── compiler
│ │ ├── utils
│ │ ├── Extensions.kt
│ │ └── CamelUtils.kt
│ │ ├── fragment
│ │ ├── builder
│ │ │ ├── ConstantBuilder.kt
│ │ │ ├── SaveStateMethodBuilder.kt
│ │ │ └── InjectMethodBuilder.kt
│ │ ├── FragmentClassBuilder.kt
│ │ └── FragmentClass.kt
│ │ ├── activity
│ │ ├── builder
│ │ │ ├── SaveStateMethodBuilder.kt
│ │ │ ├── InjectMethodBuilder.kt
│ │ │ ├── NewIntentKFunctionBuilder.kt
│ │ │ ├── ConstantBuilder.kt
│ │ │ ├── FinishKFunctionBuilder.kt
│ │ │ ├── NewIntentMethodBuilder.kt
│ │ │ └── FinishMethodBuilder.kt
│ │ └── ActivityClassBuilder.kt
│ │ ├── basic
│ │ ├── builder
│ │ │ ├── BasicConstantBuilder.kt
│ │ │ └── BasicSaveStateMethodBuilder.kt
│ │ └── entity
│ │ │ ├── SharedElementEntity.kt
│ │ │ ├── Field.kt
│ │ │ ├── ResultParameter.kt
│ │ │ └── OptionalField.kt
│ │ └── BuilderProcessor.kt
└── build.gradle
├── runtime-kt
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── bennyhuo
│ │ │ └── tieguanyin
│ │ │ └── runtime
│ │ │ └── kotlin
│ │ │ └── fragment
│ │ │ └── Fragments.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bennyhuo
│ │ │ └── tieguanyin
│ │ │ └── runtime
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── runtime
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── runtime
├── .gitignore
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ ├── com
│ │ │ └── bennyhuo
│ │ │ │ └── tieguanyin
│ │ │ │ └── runtime
│ │ │ │ ├── core
│ │ │ │ ├── OnFragmentCreateListener.java
│ │ │ │ ├── OnActivityCreateListener.java
│ │ │ │ ├── OnActivityResultListener.java
│ │ │ │ └── BuilderClassFinder.java
│ │ │ │ ├── ActivityBuilderCallback.java
│ │ │ │ ├── result
│ │ │ │ └── fields
│ │ │ │ │ ├── ActivityField.java
│ │ │ │ │ ├── ViewField.java
│ │ │ │ │ ├── FragmentField.java
│ │ │ │ │ └── ListenerField.java
│ │ │ │ ├── Tieguanyin.java
│ │ │ │ └── utils
│ │ │ │ ├── BundleUtils.java
│ │ │ │ ├── Logger.java
│ │ │ │ └── ViewUtils.java
│ │ │ └── android
│ │ │ └── support
│ │ │ └── v4
│ │ │ └── app
│ │ │ └── SupportFragmentUtils.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── runtime
│ │ └── core
│ │ ├── FinderTestClasses
│ │ └── A$B.java
│ │ └── BuilderClassFinderTest.java
├── build.gradle
└── proguard-rules.pro
├── sample-common
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── bennyhuo
│ │ │ └── tieguanyin
│ │ │ └── sample
│ │ │ └── common
│ │ │ └── BaseActivity.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bennyhuo
│ │ │ └── tieguanyin
│ │ │ └── sample
│ │ │ └── common
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── sample
│ │ └── common
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── app-androidx
├── .gitignore
├── gradle.properties
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_fragment.xml
│ │ │ │ ├── activity_parcelable.xml
│ │ │ │ ├── fragment_main.xml
│ │ │ │ ├── fragment_transitions.xml
│ │ │ │ └── activity_transitions.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── bennyhuo
│ │ │ │ └── tieguanyin
│ │ │ │ └── sample
│ │ │ │ ├── utils
│ │ │ │ └── ActivityUtils.kt
│ │ │ │ ├── App.kt
│ │ │ │ ├── SubActivity.kt
│ │ │ │ ├── inherited
│ │ │ │ ├── SubActivity.kt
│ │ │ │ └── AbsActivity.java
│ │ │ │ ├── PrimitiveDefaultTestActivity.java
│ │ │ │ ├── FragmentContainerActivity.kt
│ │ │ │ ├── inner
│ │ │ │ └── OutterClass.java
│ │ │ │ ├── childfragment
│ │ │ │ ├── ParentFragment.kt
│ │ │ │ └── ChildFragment.kt
│ │ │ │ ├── ParcelableActivity.kt
│ │ │ │ ├── EditUserActivity.java
│ │ │ │ ├── fragments
│ │ │ │ ├── KotlinFragment.kt
│ │ │ │ └── JavaFragment.java
│ │ │ │ ├── transitions
│ │ │ │ ├── DetailsActivity.kt
│ │ │ │ └── DetailsFragment.kt
│ │ │ │ ├── UserActivity.java
│ │ │ │ ├── GenerateBothActivity.kt
│ │ │ │ └── KotlinActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bennyhuo
│ │ │ └── tieguanyin
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── ExampleInstrumentedTest.kt
└── proguard-rules.pro
├── compiler-ksp
├── .gitignore
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── com.google.devtools.ksp.processing.SymbolProcessorProvider
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── compiler
│ │ └── ksp
│ │ ├── utils
│ │ ├── Extensions.kt
│ │ ├── CamelUtils.kt
│ │ ├── TypeUtils.kt
│ │ ├── ClassType.kt
│ │ └── TypeExtensions.kt
│ │ ├── fragment
│ │ ├── builder
│ │ │ ├── ConstantBuilder.kt
│ │ │ ├── InjectMethodBuilder.kt
│ │ │ └── SaveStateMethodBuilder.kt
│ │ ├── FragmentClass.kt
│ │ └── FragmentClassBuilder.kt
│ │ ├── activity
│ │ └── builder
│ │ │ ├── InjectMethodBuilder.kt
│ │ │ ├── SaveStateMethodBuilder.kt
│ │ │ ├── NewIntentKFunctionBuilder.kt
│ │ │ ├── ConstantBuilder.kt
│ │ │ ├── OnIntentKFunctionBuilder.kt
│ │ │ ├── FinishKFunctionBuilder.kt
│ │ │ ├── NewIntentMethodBuilder.kt
│ │ │ └── FinishMethodBuilder.kt
│ │ ├── core
│ │ └── KspContext.kt
│ │ ├── basic
│ │ ├── entity
│ │ │ ├── SharedElementEntity.kt
│ │ │ ├── ResultParameter.kt
│ │ │ └── Field.kt
│ │ ├── builder
│ │ │ ├── BasicConstantBuilder.kt
│ │ │ └── BasicSaveStateMethodBuilder.kt
│ │ └── BasicClassBuilder.kt
│ │ └── BuilderSymbolProcessorProvider.kt
└── build.gradle
├── runtime-androidx
├── .gitignore
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ ├── com
│ │ │ └── bennyhuo
│ │ │ │ └── tieguanyin
│ │ │ │ └── runtime
│ │ │ │ ├── core
│ │ │ │ ├── OnFragmentCreateListener.java
│ │ │ │ ├── OnActivityCreateListener.java
│ │ │ │ ├── OnActivityResultListener.java
│ │ │ │ └── BuilderClassFinder.java
│ │ │ │ ├── ActivityBuilderCallback.java
│ │ │ │ ├── result
│ │ │ │ └── fields
│ │ │ │ │ ├── ActivityField.java
│ │ │ │ │ ├── ViewField.java
│ │ │ │ │ ├── FragmentField.java
│ │ │ │ │ └── ListenerField.java
│ │ │ │ ├── Tieguanyin.java
│ │ │ │ └── utils
│ │ │ │ ├── BundleUtils.java
│ │ │ │ ├── Logger.java
│ │ │ │ └── ViewUtils.java
│ │ │ └── androidx
│ │ │ └── fragment
│ │ │ └── app
│ │ │ └── SupportFragmentUtils.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── bennyhuo
│ │ └── tieguanyin
│ │ └── runtime
│ │ └── core
│ │ ├── FinderTestClasses
│ │ └── A$B.java
│ │ └── BuilderClassFinderTest.java
├── build.gradle
└── proguard-rules.pro
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── installToLocal.sh
├── upload.ps1
├── upload.sh
├── settings.gradle
├── .gitignore
└── gradle.properties
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/annotations/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app-java/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/compiler/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/runtime-kt/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-common/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/sample-common/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app-androidx/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/compiler-ksp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/runtime-androidx/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/runtime/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app-androidx/gradle.properties:
--------------------------------------------------------------------------------
1 | ksp.incremental.log=true
2 | useKsp=true
3 | kapt.use.worker.api=false
--------------------------------------------------------------------------------
/runtime-androidx/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app-java/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ActivityBuilder
3 |
4 |
--------------------------------------------------------------------------------
/runtime-kt/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | runtime-kt
3 |
4 |
--------------------------------------------------------------------------------
/compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | com.bennyhuo.tieguanyin.compiler.BuilderProcessor
--------------------------------------------------------------------------------
/app-androidx/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ActivityBuilder
3 |
4 |
--------------------------------------------------------------------------------
/compiler/src/main/resources/META-INF/gradle/incremental.annotation.processors:
--------------------------------------------------------------------------------
1 | com.bennyhuo.tieguanyin.compiler.BuilderProcessor,isolating
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-java/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/compiler-ksp/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider:
--------------------------------------------------------------------------------
1 | com.bennyhuo.tieguanyin.compiler.ksp.BuilderSymbolProcessorProvider
--------------------------------------------------------------------------------
/runtime-kt/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bennyhuo/TieGuanYin/HEAD/app-androidx/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-java/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | app-java
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/ResultEntity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | public @interface ResultEntity {
4 |
5 | String name();
6 |
7 | Class> type();
8 | }
9 |
--------------------------------------------------------------------------------
/sample-common/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/annotations/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java-library'
3 | }
4 |
5 | dependencies {
6 | implementation fileTree(dir: 'libs', include: ['*.jar'])
7 | }
8 |
9 | targetCompatibility = '1.8'
10 | sourceCompatibility = '1.8'
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app-java/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/SharedElementWithName.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | /**
4 | * Created by benny on 2/13/18.
5 | */
6 |
7 | public @interface SharedElementWithName {
8 | String value();
9 | }
10 |
--------------------------------------------------------------------------------
/runtime/src/test/java/com/bennyhuo/tieguanyin/runtime/core/FinderTestClasses/A$B.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses;
2 |
3 | public class A$B {
4 | public static class C{
5 | public class D$E{
6 |
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/SharedElement.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | /**
4 | * Created by benny on 2/11/18.
5 | */
6 | public @interface SharedElement {
7 | int sourceId();
8 | String targetName();
9 | }
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Aug 29 07:55:18 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
7 |
--------------------------------------------------------------------------------
/runtime-androidx/src/test/java/com/bennyhuo/tieguanyin/runtime/core/FinderTestClasses/A$B.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses;
2 |
3 | public class A$B {
4 | public static class C{
5 | public class D$E{
6 |
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/SharedElementByNames.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | /**
4 | * Created by benny on 2/13/18.
5 | */
6 |
7 | public @interface SharedElementByNames {
8 | String source();
9 | String target();
10 | }
11 |
--------------------------------------------------------------------------------
/installToLocal.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | clear
3 | ./gradlew :annotations:publishToMavenLocal
4 | ./gradlew :runtime:publishToMavenLocal
5 | ./gradlew :runtime-androidx:publishToMavenLocal
6 | ./gradlew :runtime-kt:publishToMavenLocal
7 | ./gradlew :compiler:publishToMavenLocal
8 | ./gradlew :compiler-ksp:publishToMavenLocal
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/utils/Extensions.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.utils
2 |
3 | import com.bennyhuo.tieguanyin.annotations.PendingTransition
4 |
5 | fun PendingTransition.isDefault(): Boolean {
6 | return enterAnim == PendingTransition.DEFAULT && exitAnim == PendingTransition.DEFAULT
7 | }
8 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/core/OnFragmentCreateListener.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 |
6 | public interface OnFragmentCreateListener {
7 | void onFragmentCreated(Fragment fragment, Bundle savedInstanceState);
8 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/utils/Extensions.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.utils
2 |
3 | import com.bennyhuo.tieguanyin.annotations.PendingTransition
4 |
5 | fun PendingTransition.isDefault(): Boolean {
6 | return enterAnim == PendingTransition.DEFAULT && exitAnim == PendingTransition.DEFAULT
7 | }
8 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/core/OnFragmentCreateListener.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.fragment.app.Fragment;
6 |
7 | public interface OnFragmentCreateListener {
8 | void onFragmentCreated(Fragment fragment, Bundle savedInstanceState);
9 | }
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/PendingTransition.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | /**
4 | * Created by benny on 18/04/2018.
5 | */
6 | public @interface PendingTransition {
7 | int DEFAULT = -1;
8 |
9 | int enterAnim() default DEFAULT;
10 | int exitAnim() default DEFAULT;
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/utils/ActivityUtils.kt:
--------------------------------------------------------------------------------
1 | @file:JvmName("ActivityUtils")
2 | package com.bennyhuo.tieguanyin.utils
3 |
4 | import android.app.Activity
5 | import android.widget.Toast
6 |
7 | /**
8 | * Created by benny on 2/3/18.
9 | */
10 |
11 | fun Activity.toast(message: String) = Toast.makeText(this, message, Toast.LENGTH_LONG).show()
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/utils/ActivityUtils.kt:
--------------------------------------------------------------------------------
1 | @file:JvmName("ActivityUtils")
2 | package com.bennyhuo.tieguanyin.utils
3 |
4 | import android.app.Activity
5 | import android.widget.Toast
6 |
7 | /**
8 | * Created by benny on 2/3/18.
9 | */
10 |
11 | fun Activity.toast(message: String) = Toast.makeText(this, message, Toast.LENGTH_LONG).show()
--------------------------------------------------------------------------------
/app-java/src/main/java/com/bennyhuo/tieguanyin/javademo/App.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.javademo;
2 |
3 | import android.app.Application;
4 |
5 | import com.bennyhuo.tieguanyin.runtime.Tieguanyin;
6 |
7 | public class App extends Application {
8 | @Override
9 | public void onCreate() {
10 | super.onCreate();
11 | Tieguanyin.init(this);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/fragment/builder/ConstantBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.fragment.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.basic.builder.BasicConstantBuilder
4 | import com.bennyhuo.tieguanyin.compiler.fragment.FragmentClass
5 |
6 | class ConstantBuilder(fragmentClass: FragmentClass)
7 | :BasicConstantBuilder(fragmentClass)
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/core/OnActivityCreateListener.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | /**
7 | * Created by benny on 1/30/18.
8 | */
9 | public interface OnActivityCreateListener {
10 | void onActivityCreated(Activity activity, Bundle savedInstanceState);
11 | }
12 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/core/OnActivityCreateListener.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | /**
7 | * Created by benny on 1/30/18.
8 | */
9 | public interface OnActivityCreateListener {
10 | void onActivityCreated(Activity activity, Bundle savedInstanceState);
11 | }
12 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/ActivityBuilderCallback.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | /**
7 | * Created by benny at 2021/11/30 11:45 AM.
8 | */
9 | public interface ActivityBuilderCallback {
10 |
11 | void beforeStartActivity(Context context, Intent intent);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/fragment/builder/ConstantBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.builder.BasicConstantBuilder
4 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.FragmentClass
5 |
6 | class ConstantBuilder(fragmentClass: FragmentClass)
7 | : BasicConstantBuilder(fragmentClass)
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/ActivityBuilderCallback.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | /**
7 | * Created by benny at 2021/11/30 11:45 AM.
8 | */
9 | public interface ActivityBuilderCallback {
10 |
11 | void beforeStartActivity(Context context, Intent intent);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/Generated.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target(ElementType.TYPE)
9 | @Retention(RetentionPolicy.CLASS)
10 | public @interface Generated {
11 | }
12 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/ActivityField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | /**
6 | * Created by benny on 2/6/18.
7 | */
8 |
9 | public class ActivityField extends ListenerField {
10 |
11 | public ActivityField(Object receiver, Field field) {
12 | super(receiver, field);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/ActivityField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | /**
6 | * Created by benny on 2/6/18.
7 | */
8 |
9 | public class ActivityField extends ListenerField {
10 |
11 | public ActivityField(Object receiver, Field field) {
12 | super(receiver, field);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/upload.ps1:
--------------------------------------------------------------------------------
1 | ./gradlew :annotations:publishAllPublicationsToMavenCentralRepository
2 | ./gradlew :runtime:publishAllPublicationsToMavenCentralRepository
3 | ./gradlew :runtime-androidx:publishAllPublicationsToMavenCentralRepository
4 | ./gradlew :runtime-kt:publishAllPublicationsToMavenCentralRepository
5 | ./gradlew :compiler:publishAllPublicationsToMavenCentralRepository
6 | ./gradlew :compiler-ksp:publishAllPublicationsToMavenCentralRepository
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/upload.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | clear
3 | ./gradlew :annotations:publishAllPublicationsToMavenCentralRepository
4 | ./gradlew :runtime:publishAllPublicationsToMavenCentralRepository
5 | ./gradlew :runtime-androidx:publishAllPublicationsToMavenCentralRepository
6 | ./gradlew :runtime-kt:publishAllPublicationsToMavenCentralRepository
7 | ./gradlew :compiler:publishAllPublicationsToMavenCentralRepository
8 | ./gradlew :compiler-ksp:publishAllPublicationsToMavenCentralRepository
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/ViewField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | /**
6 | * Created by benny on 2/6/18.
7 | */
8 |
9 | public class ViewField extends ListenerField {
10 | public final int id;
11 |
12 | public ViewField(Object receiver, Field field, int id) {
13 | super(receiver, field);
14 | this.id = id;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/bennyhuo/tieguanyin/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/ViewField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | /**
6 | * Created by benny on 2/6/18.
7 | */
8 |
9 | public class ViewField extends ListenerField {
10 | public final int id;
11 |
12 | public ViewField(Object receiver, Field field, int id) {
13 | super(receiver, field);
14 | this.id = id;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app-androidx/src/test/java/com/bennyhuo/tieguanyin/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app-java/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/Required.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by benny on 1/29/18.
10 | */
11 | @Target(ElementType.FIELD)
12 | @Retention(RetentionPolicy.CLASS)
13 | public @interface Required {
14 | String key() default "";
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
--------------------------------------------------------------------------------
/sample-common/src/test/java/com/bennyhuo/tieguanyin/sample/common/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.common
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/res/layout/activity_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/layout/activity_parcelable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/App.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.app.Application
4 | import android.util.Log
5 | import com.bennyhuo.tieguanyin.runtime.Tieguanyin
6 |
7 | /**
8 | * Created by benny at 2021/11/30 11:57 AM.
9 | */
10 | class App : Application() {
11 |
12 | override fun onCreate() {
13 | super.onCreate()
14 | Tieguanyin.init(this) { context, intent ->
15 | Log.d("tieguanyin", intent.toString())
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/core/OnActivityResultListener.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import android.os.Bundle;
4 |
5 | /**
6 | * Created by benny on 1/31/18.
7 | */
8 |
9 | public abstract class OnActivityResultListener {
10 |
11 | public final Object realListener;
12 |
13 | public OnActivityResultListener(Object realListener) {
14 | this.realListener = realListener;
15 | }
16 |
17 | public abstract void onResult(Bundle bundle);
18 | }
19 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/App.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.app.Application
4 | import android.util.Log
5 | import com.bennyhuo.tieguanyin.runtime.Tieguanyin
6 |
7 | /**
8 | * Created by benny at 2021/11/30 11:57 AM.
9 | */
10 | class App : Application() {
11 |
12 | override fun onCreate() {
13 | super.onCreate()
14 | Tieguanyin.init(this) { context, intent ->
15 | Log.d("tieguanyin", intent.toString())
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/app-java/src/test/java/com/bennyhuo/tieguanyin/javademo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.javademo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/core/OnActivityResultListener.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import android.os.Bundle;
4 |
5 | /**
6 | * Created by benny on 1/31/18.
7 | */
8 |
9 | public abstract class OnActivityResultListener {
10 |
11 | public final Object realListener;
12 |
13 | public OnActivityResultListener(Object realListener) {
14 | this.realListener = realListener;
15 | }
16 |
17 | public abstract void onResult(Bundle bundle);
18 | }
19 |
--------------------------------------------------------------------------------
/runtime-kt/src/test/java/com/bennyhuo/tieguanyin/runtime/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/sample-common/src/main/java/com/bennyhuo/tieguanyin/sample/common/BaseActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.common
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import com.bennyhuo.tieguanyin.annotations.Builder
5 | import com.bennyhuo.tieguanyin.annotations.Optional
6 | import com.bennyhuo.tieguanyin.annotations.Required
7 |
8 | @Builder
9 | open class BaseActivity: AppCompatActivity() {
10 |
11 | @Required
12 | var id: Long = 0
13 |
14 | @Optional
15 | var name: String? = null
16 |
17 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/SubActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.os.Bundle
4 | import com.bennyhuo.tieguanyin.annotations.Builder
5 | import com.bennyhuo.tieguanyin.annotations.Required
6 | import com.bennyhuo.tieguanyin.sample.common.BaseActivity
7 |
8 | @Builder
9 | class SubActivity: BaseActivity() {
10 |
11 | @Required
12 | var age: Int = 0
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/Tieguanyin.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime;
2 |
3 | import android.content.Context;
4 |
5 | import com.bennyhuo.tieguanyin.runtime.core.ActivityBuilder;
6 |
7 | public class Tieguanyin {
8 | public static void init(Context context){
9 | ActivityBuilder.INSTANCE.init(context);
10 | }
11 |
12 | public static void init(Context context, ActivityBuilderCallback callback){
13 | ActivityBuilder.INSTANCE.init(context);
14 | ActivityBuilder.INSTANCE.setBuilderCallback(callback);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/compiler/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'kotlin'
4 | }
5 |
6 | dependencies {
7 | implementation fileTree(dir: 'libs', include: ['*.jar'])
8 | implementation project(':annotations')
9 | implementation 'com.bennyhuo:aptutils:1.8'
10 | implementation 'com.google.auto:auto-common:0.8'
11 | implementation 'com.squareup:javapoet:1.9.0'
12 | implementation 'com.squareup:kotlinpoet:1.0.0-RC1'
13 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
14 | }
15 |
16 | sourceCompatibility = "1.8"
17 | targetCompatibility = "1.8"
18 |
19 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/Tieguanyin.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime;
2 |
3 | import android.content.Context;
4 |
5 | import com.bennyhuo.tieguanyin.runtime.core.ActivityBuilder;
6 |
7 | public class Tieguanyin {
8 | public static void init(Context context){
9 | ActivityBuilder.INSTANCE.init(context);
10 | }
11 |
12 | public static void init(Context context, ActivityBuilderCallback callback){
13 | ActivityBuilder.INSTANCE.init(context);
14 | ActivityBuilder.INSTANCE.setBuilderCallback(callback);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/utils/BundleUtils.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.utils;
2 |
3 | import android.os.Bundle;
4 |
5 | /**
6 | * Created by benny on 1/30/18.
7 | */
8 |
9 | public class BundleUtils {
10 | public static T get(Bundle bundle, String key){
11 | return (T) bundle.get(key);
12 | }
13 |
14 | public static T get(Bundle bundle, String key, Object defaultValue){
15 | Object obj = bundle.get(key);
16 | if(obj == null){
17 | obj = defaultValue;
18 | }
19 | return (T) obj;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/builder/SaveStateMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.basic.builder.BasicSaveStateMethodBuilder
5 | import com.bennyhuo.tieguanyin.compiler.basic.types.ACTIVITY
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 | class SaveStateMethodBuilder(activityClass: ActivityClass)
11 | : BasicSaveStateMethodBuilder(activityClass) {
12 |
13 | override val instanceType = ACTIVITY.java
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/fragment/builder/SaveStateMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.fragment.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.basic.builder.BasicSaveStateMethodBuilder
4 | import com.bennyhuo.tieguanyin.compiler.basic.types.FRAGMENT
5 | import com.bennyhuo.tieguanyin.compiler.fragment.FragmentClass
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 | class SaveStateMethodBuilder(fragmentClass: FragmentClass)
11 | : BasicSaveStateMethodBuilder(fragmentClass) {
12 |
13 | override val instanceType = FRAGMENT.java
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/utils/BundleUtils.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.utils;
2 |
3 | import android.os.Bundle;
4 |
5 | /**
6 | * Created by benny on 1/30/18.
7 | */
8 |
9 | public class BundleUtils {
10 | public static T get(Bundle bundle, String key){
11 | return (T) bundle.get(key);
12 | }
13 |
14 | public static T get(Bundle bundle, String key, Object defaultValue){
15 | Object obj = bundle.get(key);
16 | if(obj == null){
17 | obj = defaultValue;
18 | }
19 | return (T) obj;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':app-java', ':app-androidx', ':sample-common'
2 | include ':compiler', ':compiler-ksp'
3 | include ':annotations', ':runtime', ':runtime-androidx', ':runtime-kt'
4 |
5 | //includeBuild(file("../ksp")) {
6 | // dependencySubstitution {
7 | // substitute(module("com.google.devtools.ksp:symbol-processing-api")).using(project(":api"))
8 | // substitute(module("com.google.devtools.ksp:symbol-processing")).using(project(":symbol-processing"))
9 | // substitute(module("com.google.devtools.ksp:symbol-processing-gradle-plugin")).using(project(":gradle-plugin"))
10 | // }
11 | //}
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/InjectMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.builder.BasicInjectMethodBuilder
5 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.ACTIVITY
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 |
11 | class InjectMethodBuilder(activityClass: ActivityClass): BasicInjectMethodBuilder(activityClass) {
12 |
13 | override val instanceType = ACTIVITY.kotlin
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/fragment/builder/InjectMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.builder.BasicInjectMethodBuilder
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.FRAGMENT
5 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.FragmentClass
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 |
11 | class InjectMethodBuilder(fragmentClass: FragmentClass): BasicInjectMethodBuilder(fragmentClass) {
12 |
13 | override val instanceType = FRAGMENT.kotlin
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/SaveStateMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.builder.BasicSaveStateMethodBuilder
5 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.ACTIVITY
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 | class SaveStateMethodBuilder(activityClass: ActivityClass)
11 | : BasicSaveStateMethodBuilder(activityClass) {
12 |
13 | override val instanceType = ACTIVITY.kotlin
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/fragment/builder/SaveStateMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.builder.BasicSaveStateMethodBuilder
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.FRAGMENT
5 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.FragmentClass
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 | class SaveStateMethodBuilder(fragmentClass: FragmentClass)
11 | : BasicSaveStateMethodBuilder(fragmentClass) {
12 |
13 | override val instanceType = FRAGMENT.kotlin
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/app-java/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/inherited/SubActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.inherited
2 |
3 | import android.os.Bundle
4 | import com.bennyhuo.tieguanyin.annotations.Builder
5 | import com.bennyhuo.tieguanyin.annotations.Required
6 | import com.bennyhuo.tieguanyin.sample.common.BaseActivity
7 |
8 | @Builder
9 | class SubActivity: AbsActivity() {
10 |
11 | @Required
12 | var age: Int = 0
13 |
14 | // @Required
15 | // var age2: Int = 0
16 | //
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | println("He")
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/core/KspContext.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.core
2 |
3 | import com.google.devtools.ksp.processing.KSBuiltIns
4 | import com.google.devtools.ksp.processing.KSPLogger
5 | import com.google.devtools.ksp.processing.Resolver
6 | import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
7 |
8 | object KspContext {
9 |
10 | lateinit var environment: SymbolProcessorEnvironment
11 | lateinit var resolver: Resolver
12 |
13 | val builtIns: KSBuiltIns
14 | get() = resolver.builtIns
15 |
16 | }
17 |
18 | val logger: KSPLogger
19 | get() = KspContext.environment.logger
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/GenerateMode.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | /**
4 | * Created by benny on 2/3/18.
5 | */
6 |
7 | public enum GenerateMode {
8 | /**
9 | * Generate Java utility method for Java developers only.
10 | */
11 | JavaOnly,
12 |
13 | /**
14 | * Generate Kotlin utility functions for Kotlin developers only.
15 | */
16 | KotlinOnly,
17 |
18 | Both,
19 |
20 | /**
21 | * Generate methods according to the source file.
22 | *
23 | * When source is Java file, generate java method, while source is Kotlin file, generate both.
24 | */
25 | Auto
26 | }
27 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/utils/CamelUtils.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.utils
2 |
3 | /**
4 | * Created by benny on 1/30/18.
5 | */
6 | fun String.camelToUnderline(): String {
7 | return fold(StringBuilder()) { acc, c ->
8 | if (c.isUpperCase()) {
9 | acc.append("_").append(c.toLowerCase())
10 | } else acc.append(c)
11 | }.toString()
12 | }
13 |
14 | fun String.underlineToCamel(): String {
15 | var upperNext = false
16 | return fold(StringBuilder()) { acc, c ->
17 | if (c == '_') upperNext = true
18 | else acc.append(if (upperNext) c.toUpperCase() else c)
19 | acc
20 | }.toString()
21 | }
22 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/builder/InjectMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.basic.builder.BasicInjectMethodBuilder
5 | import com.bennyhuo.tieguanyin.compiler.basic.types.ACTIVITY
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 |
11 | class InjectMethodBuilder(activityClass: ActivityClass): BasicInjectMethodBuilder(activityClass) {
12 |
13 | override val instanceType = ACTIVITY.java
14 |
15 | override val snippetToRetrieveState = "typedInstance.getIntent().getExtras() : savedInstanceState"
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/utils/Logger.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by benny on 2/9/18.
7 | */
8 |
9 | public class Logger {
10 | public static final String TAG = "TieGuanYin";
11 |
12 | public static boolean isDebug = false;
13 |
14 | public static void debug(Object log){
15 | if(isDebug) Log.d(TAG, String.valueOf(log));
16 | }
17 |
18 | public static void error(Object log){
19 | if(isDebug) Log.e(TAG, String.valueOf(log));
20 | }
21 |
22 | public static void warn(Object log){
23 | if(isDebug) Log.w(TAG, String.valueOf(log));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/utils/CamelUtils.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.utils
2 |
3 | /**
4 | * Created by benny on 1/30/18.
5 | */
6 | fun String.camelToUnderline(): String {
7 | return fold(StringBuilder()) { acc, c ->
8 | if (c.isUpperCase()) {
9 | acc.append("_").append(c.toLowerCase())
10 | } else acc.append(c)
11 | }.toString()
12 | }
13 |
14 | fun String.underlineToCamel(): String {
15 | var upperNext = false
16 | return fold(StringBuilder()) { acc, c ->
17 | if (c == '_') upperNext = true
18 | else acc.append(if (upperNext) c.toUpperCase() else c)
19 | acc
20 | }.toString()
21 | }
22 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/fragment/builder/InjectMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.fragment.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.basic.builder.BasicInjectMethodBuilder
4 | import com.bennyhuo.tieguanyin.compiler.basic.types.FRAGMENT
5 | import com.bennyhuo.tieguanyin.compiler.fragment.FragmentClass
6 |
7 | /**
8 | * Created by benny on 1/31/18.
9 | */
10 |
11 | class InjectMethodBuilder(private val fragmentClass: FragmentClass): BasicInjectMethodBuilder(fragmentClass) {
12 |
13 | override val instanceType = FRAGMENT.java
14 |
15 | override val snippetToRetrieveState = "typedInstance.getArguments() : savedInstanceState"
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/utils/Logger.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by benny on 2/9/18.
7 | */
8 |
9 | public class Logger {
10 | public static final String TAG = "TieGuanYin";
11 |
12 | public static boolean isDebug = false;
13 |
14 | public static void debug(Object log){
15 | if (isDebug) Log.d(TAG, String.valueOf(log));
16 | }
17 |
18 | public static void error(Object log){
19 | if (isDebug) Log.e(TAG, String.valueOf(log));
20 | }
21 |
22 | public static void warn(Object log){
23 | if (isDebug) Log.w(TAG, String.valueOf(log));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/FragmentField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import com.bennyhuo.tieguanyin.runtime.utils.Logger;
4 |
5 | import java.lang.reflect.Field;
6 |
7 | /**
8 | * Created by benny on 2/6/18.
9 | */
10 |
11 | public class FragmentField extends ListenerField {
12 | public final String who;
13 |
14 | public FragmentField(Object object, Field field, String who) {
15 | super(object, field);
16 | try {
17 | Logger.debug("Setup, Who: " + who + ", fragment=" + field.get(object));
18 | } catch (IllegalAccessException e) {
19 | e.printStackTrace();
20 | }
21 | this.who = who;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/FragmentField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import com.bennyhuo.tieguanyin.runtime.utils.Logger;
4 |
5 | import java.lang.reflect.Field;
6 |
7 | /**
8 | * Created by benny on 2/6/18.
9 | */
10 |
11 | public class FragmentField extends ListenerField {
12 | public final String who;
13 |
14 | public FragmentField(Object object, Field field, String who) {
15 | super(object, field);
16 | try {
17 | Logger.debug("Setup, Who: " + who + ", fragment=" + field.get(object));
18 | } catch (IllegalAccessException e) {
19 | e.printStackTrace();
20 | }
21 | this.who = who;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app-java/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/PrimitiveDefaultTestActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample;
2 |
3 | import android.app.Activity;
4 |
5 | import com.bennyhuo.tieguanyin.annotations.Builder;
6 | import com.bennyhuo.tieguanyin.annotations.Optional;
7 |
8 | @Builder
9 | public class PrimitiveDefaultTestActivity extends Activity{
10 |
11 | @Optional(charValue = '1')
12 | char charValue;
13 |
14 | @Optional(byteValue = 2)
15 | byte byteValue;
16 |
17 | @Optional(shortValue = 3)
18 | short shortValue;
19 |
20 | @Optional(intValue = 4)
21 | int intValue;
22 |
23 | @Optional(longValue = 5)
24 | long longValue;
25 |
26 | @Optional(floatValue = 6f)
27 | float floatValue;
28 |
29 | @Optional(doubleValue = 7)
30 | double doubleValue;
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/bennyhuo/tieguanyin/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.bennyhuo.activitybuilder", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app-androidx/src/androidTest/java/com/bennyhuo/tieguanyin/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.bennyhuo.activitybuilder", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/PrimitiveDefaultTestActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample;
2 |
3 | import android.app.Activity;
4 |
5 | import com.bennyhuo.tieguanyin.annotations.Builder;
6 | import com.bennyhuo.tieguanyin.annotations.Optional;
7 |
8 | @Builder
9 | public class PrimitiveDefaultTestActivity extends Activity{
10 |
11 | @Optional(charValue = '1')
12 | char charValue;
13 |
14 | @Optional(byteValue = 2)
15 | byte byteValue;
16 |
17 | @Optional(shortValue = 3)
18 | short shortValue;
19 |
20 | @Optional(intValue = 4)
21 | int intValue;
22 |
23 | @Optional(longValue = 5)
24 | long longValue;
25 |
26 | @Optional(floatValue = 6)
27 | float floatValue;
28 |
29 | @Optional(doubleValue = 7)
30 | double doubleValue;
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/runtime-kt/src/main/java/com/bennyhuo/tieguanyin/runtime/kotlin/fragment/Fragments.kt:
--------------------------------------------------------------------------------
1 | @file:JvmName("Fragments")
2 | package com.bennyhuo.tieguanyin.runtime.kotlin.fragment
3 |
4 | import android.support.v4.app.Fragment
5 |
6 | fun Fragment.remove(){
7 | activity?.supportFragmentManager?.beginTransaction()?.remove(this)?.commit()
8 | }
9 |
10 | fun Fragment.show(){
11 | activity?.supportFragmentManager?.beginTransaction()?.show(this)?.commit()
12 | }
13 |
14 | fun Fragment.hide(){
15 | activity?.supportFragmentManager?.beginTransaction()?.hide(this)?.commit()
16 | }
17 |
18 | fun Fragment.attach(){
19 | activity?.supportFragmentManager?.beginTransaction()?.attach(this)?.commit()
20 | }
21 |
22 | fun Fragment.detach(){
23 | activity?.supportFragmentManager?.beginTransaction()?.detach(this)?.commit()
24 | }
25 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/ListenerField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import com.bennyhuo.tieguanyin.runtime.utils.Logger;
4 |
5 | import java.lang.reflect.Field;
6 |
7 | /**
8 | * Created by benny on 2/6/18.
9 | */
10 |
11 | public abstract class ListenerField {
12 | public final Field field;
13 | public final Object receiver;
14 |
15 | public ListenerField(Object receiver, Field field) {
16 | this.receiver = receiver;
17 | this.field = field;
18 | this.field.setAccessible(true);
19 | }
20 |
21 | public void update(Object object){
22 | try {
23 | field.set(this.receiver, object);
24 | } catch (Exception e) {
25 | Logger.warn(e);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app-java/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/result/fields/ListenerField.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.result.fields;
2 |
3 | import com.bennyhuo.tieguanyin.runtime.utils.Logger;
4 |
5 | import java.lang.reflect.Field;
6 |
7 | /**
8 | * Created by benny on 2/6/18.
9 | */
10 |
11 | public abstract class ListenerField {
12 | public final Field field;
13 | public final Object receiver;
14 |
15 | public ListenerField(Object receiver, Field field) {
16 | this.receiver = receiver;
17 | this.field = field;
18 | this.field.setAccessible(true);
19 | }
20 |
21 | public void update(Object object){
22 | try {
23 | field.set(this.receiver, object);
24 | } catch (Exception e) {
25 | Logger.warn(e);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/runtime-androidx/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | }
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 16
11 | targetSdkVersion 25
12 | versionCode 1
13 | versionName "1.0"
14 | consumerProguardFiles 'proguard-rules.pro'
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compileOnly("androidx.fragment:fragment:1.3.6")
28 |
29 | api project(":annotations")
30 |
31 | testImplementation 'junit:junit:4.12'
32 | }
--------------------------------------------------------------------------------
/runtime/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | }
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 16
11 | targetSdkVersion 25
12 | versionCode 1
13 | versionName "1.0"
14 | consumerProguardFiles 'proguard-rules.pro'
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compileOnly("com.android.support:support-fragment:28.0.0")
28 |
29 | api project(":annotations")
30 |
31 | testImplementation 'junit:junit:4.12'
32 | }
--------------------------------------------------------------------------------
/sample-common/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app-androidx/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app-java/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/runtime-kt/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/FragmentContainerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import com.bennyhuo.tieguanyin.annotations.Builder
6 | import com.bennyhuo.tieguanyin.sample.fragments.replaceKotlinFragment
7 |
8 | /**
9 | * Created by benny on 1/29/18.
10 | */
11 | @Builder
12 | class FragmentContainerActivity : AppCompatActivity() {
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | setContentView(R.layout.activity_fragment)
17 | title = this.javaClass.simpleName
18 |
19 | if(supportFragmentManager.findFragmentById(R.id.fragmentContainer) == null)
20 | replaceKotlinFragment(R.id.fragmentContainer, "Kotlin Fragment")
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/FragmentContainerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import com.bennyhuo.tieguanyin.annotations.Builder
6 | import com.bennyhuo.tieguanyin.sample.fragments.replaceKotlinFragment
7 |
8 | /**
9 | * Created by benny on 1/29/18.
10 | */
11 | @Builder
12 | class FragmentContainerActivity : AppCompatActivity() {
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | setContentView(R.layout.activity_fragment)
17 | title = this.javaClass.simpleName
18 |
19 | if(supportFragmentManager.findFragmentById(R.id.fragmentContainer) == null)
20 | replaceKotlinFragment(R.id.fragmentContainer, "Kotlin Fragment")
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/compiler-ksp/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'kotlin'
4 | }
5 |
6 | dependencies {
7 | implementation fileTree(dir: 'libs', include: ['*.jar'])
8 | api project(':annotations')
9 |
10 | implementation 'com.squareup:kotlinpoet:1.10.0'
11 | implementation 'com.squareup:kotlinpoet-ksp:1.10.0'
12 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
13 | implementation("com.google.devtools.ksp:symbol-processing-api:$ksp_version")
14 | }
15 |
16 | sourceCompatibility = "1.8"
17 | targetCompatibility = "1.8"
18 |
19 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
20 | kotlinOptions {
21 | freeCompilerArgs += "-Xuse-experimental=com.squareup.kotlinpoet.ksp.KotlinPoetKspPreview"
22 | freeCompilerArgs += "-Xuse-experimental=com.google.devtools.ksp.KspExperimental"
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/inherited/AbsActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.inherited;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 |
5 | import com.bennyhuo.tieguanyin.annotations.Builder;
6 | import com.bennyhuo.tieguanyin.annotations.Optional;
7 | import com.bennyhuo.tieguanyin.annotations.PendingTransition;
8 | import com.bennyhuo.tieguanyin.annotations.Required;
9 | import com.bennyhuo.tieguanyin.annotations.ResultEntity;
10 |
11 | /**
12 | * Created by benny on 2/9/18.
13 | */
14 | @Builder(pendingTransition = @PendingTransition(enterAnim = 0, exitAnim = 0),
15 | resultTypes = @ResultEntity(name = "hello", type = String.class))
16 | public abstract class AbsActivity extends AppCompatActivity {
17 |
18 | @Required
19 | public int fromSuper;
20 |
21 | @Optional
22 | public String fromSuperString;
23 | }
24 |
--------------------------------------------------------------------------------
/sample-common/src/androidTest/java/com/bennyhuo/tieguanyin/sample/common/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.common
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.bennyhuo.tieguanyin.sample.common.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/inherited/AbsActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.inherited;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import com.bennyhuo.tieguanyin.annotations.Builder;
6 | import com.bennyhuo.tieguanyin.annotations.Optional;
7 | import com.bennyhuo.tieguanyin.annotations.PendingTransition;
8 | import com.bennyhuo.tieguanyin.annotations.Required;
9 | import com.bennyhuo.tieguanyin.annotations.ResultEntity;
10 |
11 | /**
12 | * Created by benny on 2/9/18.
13 | */
14 | @Builder(pendingTransition = @PendingTransition(enterAnim = 0, exitAnim = 0),
15 | resultTypes = @ResultEntity(name = "hello", type = String.class))
16 | public abstract class AbsActivity extends AppCompatActivity {
17 |
18 | @Required
19 | public int fromSuper;
20 |
21 | @Optional
22 | public String fromSuperString;
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_transitions.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/runtime-kt/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'kotlin-android'
4 | }
5 |
6 | android {
7 | compileSdkVersion 30
8 |
9 | defaultConfig {
10 | minSdkVersion 16
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
31 | compileOnly 'com.android.support:support-fragment:27.1.1'
32 | testImplementation 'junit:junit:4.12'
33 | }
34 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/basic/builder/BasicConstantBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.basic.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.basic.BasicClass
4 | import com.bennyhuo.tieguanyin.compiler.utils.camelToUnderline
5 | import com.squareup.javapoet.FieldSpec
6 | import com.squareup.javapoet.TypeSpec
7 | import javax.lang.model.element.Modifier
8 |
9 | abstract class BasicConstantBuilder(private val basicClass: BasicClass) {
10 | open fun build(typeBuilder: TypeSpec.Builder) {
11 | basicClass.fields.forEach { field ->
12 | typeBuilder.addField(FieldSpec.builder(String::class.java,
13 | field.prefix + field.name.camelToUnderline(),
14 | Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
15 | .initializer("\$S", field.name)
16 | .build())
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle
18 | build
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 | jcenter.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # Intellij
37 | *.iml
38 | .idea
39 |
40 | # Keystore files
41 | *.jks
42 |
43 | # External native build folder generated in Android Studio 2.2 and later
44 | .externalNativeBuild
45 |
46 | # Google Services (e.g. APIs or Firebase)
47 | google-services.json
48 |
49 | # Freeline
50 | freeline.py
51 | freeline/
52 | freeline_project_description.json
53 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/layout/fragment_transitions.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app-java/src/androidTest/java/com/bennyhuo/tieguanyin/javademo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.javademo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.bennyhuo.tieguanyin.javademo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/runtime-kt/src/androidTest/java/com/bennyhuo/tieguanyin/runtime/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.bennyhuo.tieguanyin.runtime.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/basic/entity/SharedElementEntity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.basic.entity
2 |
3 | import com.bennyhuo.tieguanyin.annotations.SharedElement
4 | import com.bennyhuo.tieguanyin.annotations.SharedElementByNames
5 | import com.bennyhuo.tieguanyin.annotations.SharedElementWithName
6 |
7 | /**
8 | * Created by benny on 2/13/18.
9 | */
10 |
11 | class SharedElementEntity(val targetName: String,
12 | val sourceId: Int = 0,
13 | val sourceName: String? = null) {
14 |
15 | constructor(sharedElement: SharedElement) : this(sharedElement.targetName, sourceId = sharedElement.sourceId)
16 | constructor(sharedElement: SharedElementWithName) : this(sharedElement.value, sourceName = sharedElement.value)
17 | constructor(sharedElement: SharedElementByNames) : this(sharedElement.target, sourceName = sharedElement.source)
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/basic/entity/SharedElementEntity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.basic.entity
2 |
3 | import com.bennyhuo.tieguanyin.annotations.SharedElement
4 | import com.bennyhuo.tieguanyin.annotations.SharedElementByNames
5 | import com.bennyhuo.tieguanyin.annotations.SharedElementWithName
6 |
7 | /**
8 | * Created by benny on 2/13/18.
9 | */
10 |
11 | class SharedElementEntity(val targetName: String,
12 | val sourceId: Int = 0,
13 | val sourceName: String? = null) {
14 |
15 | constructor(sharedElement: SharedElement) : this(sharedElement.targetName, sourceId = sharedElement.sourceId)
16 | constructor(sharedElement: SharedElementWithName) : this(sharedElement.value, sourceName = sharedElement.value)
17 | constructor(sharedElement: SharedElementByNames) : this(sharedElement.target, sourceName = sharedElement.source)
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/runtime/src/test/java/com/bennyhuo/tieguanyin/runtime/core/BuilderClassFinderTest.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$B;
4 |
5 | import junit.framework.Assert;
6 |
7 | import org.junit.Test;
8 |
9 | public class BuilderClassFinderTest {
10 |
11 | @Test
12 | public void testFindBuilderClass(){
13 | A$B a$B = new A$B();
14 | Assert.assertEquals(BuilderClassFinder.findBuilderClassName(a$B), "com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$BBuilder");
15 | A$B.C c = new A$B.C();
16 | Assert.assertEquals(BuilderClassFinder.findBuilderClassName(c), "com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$B_CBuilder");
17 | A$B.C.D$E d$E = c.new D$E();
18 | Assert.assertEquals(BuilderClassFinder.findBuilderClassName(d$E), "com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$B_C_D$EBuilder");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/runtime-androidx/src/test/java/com/bennyhuo/tieguanyin/runtime/core/BuilderClassFinderTest.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$B;
4 |
5 | import junit.framework.Assert;
6 |
7 | import org.junit.Test;
8 |
9 | public class BuilderClassFinderTest {
10 |
11 | @Test
12 | public void testFindBuilderClass(){
13 | A$B a$B = new A$B();
14 | Assert.assertEquals(BuilderClassFinder.findBuilderClassName(a$B), "com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$BBuilder");
15 | A$B.C c = new A$B.C();
16 | Assert.assertEquals(BuilderClassFinder.findBuilderClassName(c), "com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$B_CBuilder");
17 | A$B.C.D$E d$E = c.new D$E();
18 | Assert.assertEquals(BuilderClassFinder.findBuilderClassName(d$E), "com.bennyhuo.tieguanyin.runtime.core.FinderTestClasses.A$B_C_D$EBuilder");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/basic/builder/BasicConstantBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.basic.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.BasicClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.camelToUnderline
5 | import com.squareup.kotlinpoet.KModifier
6 | import com.squareup.kotlinpoet.PropertySpec
7 | import com.squareup.kotlinpoet.TypeSpec
8 | import java.util.*
9 |
10 | abstract class BasicConstantBuilder(private val basicClass: BasicClass) {
11 | open fun build(typeBuilder: TypeSpec.Builder) {
12 | basicClass.fields.forEach { field ->
13 | typeBuilder.addProperty(
14 | PropertySpec.builder(
15 | field.prefix + field.name.camelToUnderline().uppercase(Locale.getDefault()),
16 | String::class, KModifier.CONST
17 | ).initializer("%S", field.key).build()
18 | )
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/app-java/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/basic/entity/Field.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.basic.entity
2 |
3 | import com.bennyhuo.aptutils.types.asKotlinTypeName
4 | import com.squareup.javapoet.ClassName
5 | import javax.lang.model.element.Modifier
6 | import javax.lang.model.element.VariableElement
7 | import javax.lang.model.type.PrimitiveType
8 |
9 | /**
10 | * Created by benny on 1/29/18.
11 | */
12 |
13 | open class Field(private val element: VariableElement) : Comparable {
14 | val name = element.simpleName.toString()
15 |
16 | open val prefix = "REQUIRED_"
17 |
18 | val isPrivate = Modifier.PRIVATE in element.modifiers
19 |
20 | val isPrimitive = element.asType() is PrimitiveType
21 |
22 | fun asTypeName() = ClassName.get(element.asType())
23 |
24 | open fun asKotlinTypeName() = element.asType().asKotlinTypeName()
25 |
26 | override fun compareTo(other: Field): Int {
27 | return name.compareTo(other.name)
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/Optional.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by benny on 1/29/18.
10 | */
11 | @Target(ElementType.FIELD)
12 | @Retention(RetentionPolicy.CLASS)
13 | public @interface Optional {
14 | @Deprecated
15 | String stringValue() default "";
16 | @Deprecated
17 | char charValue() default '0';
18 | @Deprecated
19 | byte byteValue() default 0;
20 | @Deprecated
21 | short shortValue() default 0;
22 | @Deprecated
23 | int intValue() default 0;
24 | @Deprecated
25 | long longValue() default 0;
26 | @Deprecated
27 | float floatValue() default 0f;
28 | @Deprecated
29 | double doubleValue() default 0.0;
30 | @Deprecated
31 | boolean booleanValue() default false;
32 |
33 | String key() default "";
34 | }
35 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/utils/TypeUtils.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.utils
2 |
3 | import com.squareup.kotlinpoet.ClassName
4 | import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
5 |
6 | /**
7 | * Created by benny on 2/3/18.
8 | */
9 |
10 | private val STRING: ClassName = ClassName("kotlin", "String")
11 | private val STRING_ARRAY = ClassName("kotlin", "Array").parameterizedBy(STRING)
12 | private val LONG_ARRAY: ClassName = ClassName("kotlin", "LongArray")
13 | private val INT_ARRAY: ClassName = ClassName("kotlin", "IntArray")
14 | private val SHORT_ARRAY: ClassName = ClassName("kotlin", "ShortArray")
15 | private val BYTE_ARRAY: ClassName = ClassName("kotlin", "ByteArray")
16 | private val CHAR_ARRAY: ClassName = ClassName("kotlin", "CharArray")
17 | private val BOOLEAN_ARRAY: ClassName = ClassName("kotlin", "BooleanArray")
18 | private val FLOAT_ARRAY: ClassName = ClassName("kotlin", "FloatArray")
19 | private val DOUBLE_ARRAY: ClassName = ClassName("kotlin", "DoubleArray")
20 | //endregion
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/inner/OutterClass.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.inner;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.widget.Toast;
7 |
8 | import com.bennyhuo.tieguanyin.annotations.Builder;
9 | import com.bennyhuo.tieguanyin.annotations.GenerateMode;
10 | import com.bennyhuo.tieguanyin.annotations.Optional;
11 | import com.bennyhuo.tieguanyin.annotations.Required;
12 |
13 | public class OutterClass {
14 | @Builder(mode = GenerateMode.Both)
15 | public static class InnerClass extends Activity{
16 |
17 | @Required
18 | int a;
19 |
20 | @Optional
21 | boolean b;
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | Toast.makeText(this, this.getClass().getSimpleName() + "[a=" + a + ", b = " + b + "]", Toast.LENGTH_SHORT).show();
27 | finish();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/inner/OutterClass.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.inner;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.Toast;
6 |
7 | import androidx.annotation.Nullable;
8 |
9 | import com.bennyhuo.tieguanyin.annotations.Builder;
10 | import com.bennyhuo.tieguanyin.annotations.GenerateMode;
11 | import com.bennyhuo.tieguanyin.annotations.Optional;
12 | import com.bennyhuo.tieguanyin.annotations.Required;
13 |
14 | public class OutterClass {
15 | @Builder(mode = GenerateMode.Both)
16 | public static class InnerClass extends Activity{
17 |
18 | @Required
19 | int a;
20 |
21 | @Optional
22 | boolean b;
23 |
24 | @Override
25 | protected void onCreate(@Nullable Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | Toast.makeText(this, this.getClass().getSimpleName() + "[a=" + a + ", b = " + b + "]", Toast.LENGTH_SHORT).show();
28 | finish();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/childfragment/ParentFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.childfragment
2 |
3 | import android.os.Bundle
4 | import android.support.v4.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import com.bennyhuo.tieguanyin.annotations.Builder
9 | import com.bennyhuo.tieguanyin.sample.R
10 | import kotlinx.android.synthetic.main.fragment_main.*
11 |
12 | /**
13 | * Created by benny on 2/6/18.
14 | */
15 | @Builder
16 | class ParentFragment : Fragment() {
17 |
18 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
19 | return inflater.inflate(R.layout.fragment_main, container, false)
20 | }
21 |
22 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
23 | super.onViewCreated(view, savedInstanceState)
24 | textView.text = "show child fragment."
25 | textView.setOnClickListener {
26 | replaceChildFragment("ChildFragment.")
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/utils/ViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.utils;
2 |
3 | import android.support.v4.view.ViewCompat;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * Created by benny on 2/13/18.
11 | */
12 |
13 | public class ViewUtils {
14 | public static void findNamedViews(View view, Map namedViews) {
15 | if (view.getVisibility() == View.VISIBLE) {
16 | String transitionName = ViewCompat.getTransitionName(view);
17 | if (transitionName != null) {
18 | namedViews.put(transitionName, view);
19 | }
20 | if (view instanceof ViewGroup) {
21 | ViewGroup viewGroup = (ViewGroup) view;
22 | int count = viewGroup.getChildCount();
23 | for (int i = 0; i < count; i++) {
24 | View child = viewGroup.getChildAt(i);
25 | findNamedViews(child, namedViews);
26 | }
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/childfragment/ParentFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.childfragment
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import com.bennyhuo.tieguanyin.annotations.Builder
9 | import com.bennyhuo.tieguanyin.sample.R
10 | import kotlinx.android.synthetic.main.fragment_main.*
11 |
12 | /**
13 | * Created by benny on 2/6/18.
14 | */
15 | @Builder
16 | class ParentFragment : Fragment() {
17 |
18 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
19 | return inflater.inflate(R.layout.fragment_main, container, false)
20 | }
21 |
22 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
23 | super.onViewCreated(view, savedInstanceState)
24 | textView.text = "show child fragment."
25 | textView.setOnClickListener {
26 | replaceChildFragment("ChildFragment.")
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/utils/ViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.utils;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 |
6 | import androidx.core.view.ViewCompat;
7 |
8 | import java.util.Map;
9 |
10 | /**
11 | * Created by benny on 2/13/18.
12 | */
13 |
14 | public class ViewUtils {
15 | public static void findNamedViews(View view, Map namedViews) {
16 | if (view.getVisibility() == View.VISIBLE) {
17 | String transitionName = ViewCompat.getTransitionName(view);
18 | if (transitionName != null) {
19 | namedViews.put(transitionName, view);
20 | }
21 | if (view instanceof ViewGroup) {
22 | ViewGroup viewGroup = (ViewGroup) view;
23 | int count = viewGroup.getChildCount();
24 | for (int i = 0; i < count; i++) {
25 | View child = viewGroup.getChildAt(i);
26 | findNamedViews(child, namedViews);
27 | }
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/basic/entity/ResultParameter.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.basic.entity
2 |
3 | import com.bennyhuo.tieguanyin.annotations.ResultEntity
4 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.KsTypeNotPresentException
5 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.toKsType
6 | import com.google.devtools.ksp.symbol.KSType
7 | import com.squareup.kotlinpoet.ksp.toTypeName
8 | import com.squareup.kotlinpoet.TypeName as KotlinTypeName
9 |
10 | class ResultParameter(val name: String, val type: KSType) : Comparable {
11 |
12 | val kotlinTypeName: KotlinTypeName by lazy {
13 | type.toTypeName()
14 | }
15 |
16 | override fun compareTo(other: ResultParameter) = name.compareTo(other.name)
17 |
18 | }
19 |
20 | fun ResultEntity.asResultParameter(): ResultParameter {
21 | return ResultParameter(name, try {
22 | type.toKsType()
23 | } catch (e: Exception) {
24 | if (e is KsTypeNotPresentException) {
25 | e.ksType
26 | } else {
27 | throw e
28 | }
29 | })
30 | }
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/builder/NewIntentKFunctionBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.basic.types.INTENT
5 | import com.squareup.kotlinpoet.FileSpec
6 | import com.squareup.kotlinpoet.FunSpec
7 | import com.squareup.kotlinpoet.ParameterSpec
8 | import com.squareup.kotlinpoet.asClassName
9 |
10 | class NewIntentKFunctionBuilder(private val activityClass: ActivityClass) {
11 |
12 | fun build(builder: FileSpec.Builder) {
13 | val newIntentFunBuilder = FunSpec.builder("processNewIntent")
14 | .receiver(activityClass.typeElement.asClassName())
15 | .addParameter("intent", INTENT.kotlin.asNullable())
16 | .addParameter(ParameterSpec.builder("updateIntent", Boolean::class.java).defaultValue("true").build())
17 |
18 | newIntentFunBuilder.addStatement("%L.processNewIntent(this, intent, updateIntent)", activityClass.builderClassName)
19 | builder.addFunction(newIntentFunBuilder.build())
20 | }
21 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/NewIntentKFunctionBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.INTENT
5 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.toKotlinTypeName
6 | import com.squareup.kotlinpoet.FileSpec
7 | import com.squareup.kotlinpoet.FunSpec
8 | import com.squareup.kotlinpoet.ParameterSpec
9 |
10 | class NewIntentKFunctionBuilder(private val activityClass: ActivityClass) {
11 |
12 | fun build(builder: FileSpec.Builder) {
13 | val newIntentFunBuilder = FunSpec.builder("processNewIntent")
14 | .receiver(activityClass.declaration.toKotlinTypeName())
15 | .addParameter("intent", INTENT.kotlin.copy(nullable = true))
16 | .addParameter(ParameterSpec.builder("updateIntent", Boolean::class.java).defaultValue("true").build())
17 |
18 | newIntentFunBuilder.addStatement("%L.processNewIntent(this, intent, updateIntent)", activityClass.builderClassName)
19 | builder.addFunction(newIntentFunBuilder.build())
20 | }
21 | }
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/basic/entity/ResultParameter.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.basic.entity
2 |
3 | import com.bennyhuo.tieguanyin.annotations.ResultEntity
4 | import com.bennyhuo.aptutils.types.asJavaTypeName
5 | import com.bennyhuo.aptutils.types.asKotlinTypeName
6 | import com.bennyhuo.aptutils.types.asTypeMirror
7 | import javax.lang.model.type.MirroredTypeException
8 | import javax.lang.model.type.TypeMirror
9 |
10 | import com.squareup.javapoet.TypeName as JavaTypeName
11 | import com.squareup.kotlinpoet.TypeName as KotlinTypeName
12 |
13 | class ResultParameter(val name: String, val type: TypeMirror): Comparable{
14 |
15 | val javaTypeName: JavaTypeName by lazy { type.asJavaTypeName() }
16 |
17 | val kotlinTypeName: KotlinTypeName by lazy { type.asKotlinTypeName() }
18 |
19 | override fun compareTo(other: ResultParameter) = name.compareTo(other.name)
20 |
21 | }
22 |
23 | fun ResultEntity.asResultParameter() = ResultParameter(name, resultType)
24 |
25 | val ResultEntity.resultType: TypeMirror
26 | get() = try {
27 | type.asTypeMirror()
28 | } catch (e: MirroredTypeException) {
29 | e.typeMirror
30 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/utils/ClassType.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.utils
2 |
3 | import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
4 | import com.squareup.kotlinpoet.ClassName as KotlinClassName
5 | import com.squareup.kotlinpoet.TypeName as KotlinTypeName
6 |
7 | class ClassType(private val jvmClassName: String, private vararg val typeParameterClassTypes: ClassType) {
8 |
9 | val kotlin: KotlinTypeName by lazy {
10 | val className = KotlinClassName.bestGuess(jvmClassName)
11 | if (typeParameterClassTypes.isNotEmpty()) {
12 | className.parameterizedBy(*(Array(typeParameterClassTypes.size) { i -> typeParameterClassTypes[i].kotlin }))
13 | } else {
14 | className
15 | }
16 | }
17 |
18 | fun parameterized(vararg typeParameterClassTypes: ClassType) =
19 | ClassType(jvmClassName, *typeParameterClassTypes)
20 |
21 | operator fun get(vararg typeParameterClassTypes: ClassType) = ClassType(jvmClassName, *typeParameterClassTypes)
22 |
23 | override fun toString(): String {
24 | return "${jvmClassName}[${typeParameterClassTypes.joinToString()}]"
25 | }
26 | }
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/builder/ConstantBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClassBuilder
5 | import com.bennyhuo.tieguanyin.compiler.basic.builder.BasicConstantBuilder
6 | import com.bennyhuo.tieguanyin.compiler.utils.camelToUnderline
7 | import com.squareup.javapoet.FieldSpec
8 | import com.squareup.javapoet.TypeSpec
9 | import javax.lang.model.element.Modifier
10 |
11 | class ConstantBuilder(private val activityClass: ActivityClass)
12 | : BasicConstantBuilder(activityClass) {
13 |
14 | override fun build(typeBuilder: TypeSpec.Builder) {
15 | super.build(typeBuilder)
16 | activityClass.resultParameters.forEach { resultEntity ->
17 | typeBuilder.addField(FieldSpec.builder(String::class.java,
18 | ActivityClassBuilder.CONSTS_RESULT_PREFIX + resultEntity.name.camelToUnderline(),
19 | Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
20 | .initializer("\$S", resultEntity.name)
21 | .build())
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/ParcelableActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.app.Activity
4 | import android.os.Bundle
5 | import android.os.Parcelable
6 | import com.bennyhuo.tieguanyin.annotations.Builder
7 | import com.bennyhuo.tieguanyin.annotations.Required
8 | import com.bennyhuo.tieguanyin.annotations.ResultEntity
9 | import kotlinx.android.parcel.Parcelize
10 | import kotlinx.android.synthetic.main.activity_main.*
11 | import java.io.Serializable
12 |
13 | @Builder(
14 | resultTypes = [ResultEntity(name = "userInfo", type = UserInfo::class)]
15 | )
16 | class ParcelableActivity : Activity() {
17 | @Required
18 | lateinit var userInfo: UserInfo
19 |
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 | setContentView(R.layout.activity_parcelable)
23 |
24 | textView.text = userInfo.toString()
25 |
26 | textView.setOnClickListener {
27 | smartFinish(userInfo.copy("bennyhuo123"))
28 | }
29 | }
30 |
31 | }
32 |
33 | data class Company(val name: String, val location: String) : Serializable
34 |
35 | @Parcelize
36 | data class UserInfo(val name: String, val age: Int, val company: Company) : Parcelable
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/childfragment/ChildFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.childfragment
2 |
3 | import android.os.Bundle
4 | import android.support.v4.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import com.bennyhuo.tieguanyin.annotations.Builder
9 | import com.bennyhuo.tieguanyin.annotations.Required
10 | import com.bennyhuo.tieguanyin.sample.R
11 | import kotlinx.android.synthetic.main.fragment_main.*
12 |
13 | /**
14 | * Created by benny on 2/6/18.
15 | */
16 | @Builder
17 | class ChildFragment : Fragment() {
18 |
19 | @Required
20 | lateinit var text: String
21 |
22 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
23 | return inflater.inflate(R.layout.fragment_main, container, false)
24 | }
25 |
26 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
27 | super.onViewCreated(view, savedInstanceState)
28 | textView.text = text
29 | textView.setOnClickListener {
30 | //showJavaFragment("Java!!")
31 | text = System.currentTimeMillis().toString()
32 | textView.text = text
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/annotations/src/main/java/com/bennyhuo/tieguanyin/annotations/Builder.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by benny on 1/29/18.
10 | */
11 | @Target(ElementType.TYPE)
12 | @Retention(RetentionPolicy.CLASS)
13 | public @interface Builder {
14 | GenerateMode mode() default GenerateMode.Auto;
15 | SharedElement[] sharedElements() default {};
16 | SharedElementByNames[] sharedElementsByNames() default {};
17 | SharedElementWithName[] sharedElementsWithName() default {};
18 |
19 | /**
20 | * For Activities Only
21 | */
22 | ResultEntity[] resultTypes() default {};
23 |
24 | /**
25 | * For Activities Only
26 | */
27 | PendingTransition pendingTransition() default @PendingTransition;
28 |
29 | /**
30 | * For Activities Only
31 | */
32 | PendingTransition pendingTransitionOnFinish() default @PendingTransition;
33 |
34 | /**
35 | * For Activities Only
36 | */
37 | String[] categories() default {};
38 |
39 | /**
40 | * For Activities Only
41 | */
42 | int[] flags() default {};
43 | }
44 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/ConstantBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClassBuilder
5 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.builder.BasicConstantBuilder
6 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.camelToUnderline
7 | import com.squareup.kotlinpoet.KModifier
8 | import com.squareup.kotlinpoet.PropertySpec
9 | import com.squareup.kotlinpoet.TypeSpec
10 | import java.util.*
11 |
12 | class ConstantBuilder(private val activityClass: ActivityClass)
13 | : BasicConstantBuilder(activityClass) {
14 |
15 | override fun build(typeBuilder: TypeSpec.Builder) {
16 | super.build(typeBuilder)
17 | activityClass.resultParameters.forEach { resultEntity ->
18 | typeBuilder.addProperty(
19 | PropertySpec.builder(
20 | ActivityClassBuilder.CONSTS_RESULT_PREFIX + resultEntity.name.camelToUnderline().uppercase(Locale.getDefault()),
21 | String::class, KModifier.CONST
22 | ).initializer("%S", resultEntity.name).build()
23 | )
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/childfragment/ChildFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.childfragment
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import com.bennyhuo.tieguanyin.annotations.Builder
9 | import com.bennyhuo.tieguanyin.annotations.Required
10 | import com.bennyhuo.tieguanyin.sample.R
11 | import kotlinx.android.synthetic.main.fragment_main.*
12 |
13 | /**
14 | * Created by benny on 2/6/18.
15 | */
16 | @Builder
17 | class ChildFragment : Fragment() {
18 |
19 | @Required
20 | lateinit var text: String
21 |
22 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
23 | return inflater.inflate(R.layout.fragment_main, container, false)
24 | }
25 |
26 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
27 | super.onViewCreated(view, savedInstanceState)
28 | textView.text = text
29 | textView.setOnClickListener {
30 | //showJavaFragment("Java!!")
31 | text = System.currentTimeMillis().toString()
32 | textView.text = text
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_transitions.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
24 |
25 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/layout/activity_transitions.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
24 |
25 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/fragment/FragmentClassBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.fragment
2 |
3 | import com.bennyhuo.tieguanyin.compiler.basic.BasicClassBuilder
4 | import com.bennyhuo.tieguanyin.compiler.basic.builder.FieldBuilder
5 | import com.bennyhuo.tieguanyin.compiler.fragment.builder.*
6 | import com.squareup.javapoet.TypeSpec.Builder
7 | import com.squareup.kotlinpoet.FileSpec
8 |
9 | class FragmentClassBuilder(private val fragmentClass: FragmentClass)
10 | : BasicClassBuilder(fragmentClass) {
11 |
12 | override fun buildCommon(typeBuilder: Builder) {
13 | ConstantBuilder(fragmentClass).build(typeBuilder)
14 | FieldBuilder(fragmentClass).build(typeBuilder)
15 | InjectMethodBuilder(fragmentClass).build(typeBuilder)
16 | SaveStateMethodBuilder(fragmentClass).build(typeBuilder)
17 | }
18 |
19 | override fun buildKotlinBuilders(fileBuilder: FileSpec.Builder) {
20 | ReplaceKFunctionBuilder(fragmentClass).build(fileBuilder)
21 | AddKFunctionBuilder(fragmentClass).build(fileBuilder)
22 | }
23 |
24 | override fun buildJavaBuilders(typeBuilder: Builder) {
25 | ReplaceMethodBuilder(fragmentClass).build(typeBuilder)
26 | AddMethodBuilder(fragmentClass).build(typeBuilder)
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/EditUserActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 |
7 | import com.bennyhuo.tieguanyin.annotations.Builder;
8 | import com.bennyhuo.tieguanyin.annotations.GenerateMode;
9 | import com.bennyhuo.tieguanyin.annotations.Required;
10 | import com.bennyhuo.tieguanyin.annotations.ResultEntity;
11 |
12 | @Builder(mode = GenerateMode.Both,
13 | resultTypes = {@ResultEntity(name = "name", type = String.class),
14 | @ResultEntity(name = "age", type = int.class),
15 | @ResultEntity(name = "title", type = String.class),
16 | @ResultEntity(name = "company", type = String.class)})
17 | public class EditUserActivity extends Activity {
18 |
19 | @Required
20 | String name;
21 |
22 | @Required
23 | int age;
24 |
25 | @Required
26 | String title;
27 |
28 | @Required
29 | String company;
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 |
35 | EditUserActivityBuilder.smartFinish(this,
36 | 36, "Kotliner",
37 | "bennyhuo", "Kotlin Dev");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/sample-common/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'kotlin-android'
4 | }
5 |
6 | android {
7 | compileSdkVersion 30
8 |
9 | defaultConfig {
10 | minSdkVersion 21
11 | targetSdkVersion 30
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles "consumer-rules.pro"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | kotlinOptions {
30 | jvmTarget = '1.8'
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation project(':annotations')
36 |
37 | implementation 'androidx.core:core-ktx:1.6.0'
38 | implementation 'androidx.appcompat:appcompat:1.3.1'
39 | implementation 'com.google.android.material:material:1.4.0'
40 | testImplementation 'junit:junit:4.+'
41 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
42 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
43 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/EditUserActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import androidx.annotation.Nullable;
7 |
8 | import com.bennyhuo.tieguanyin.annotations.Builder;
9 | import com.bennyhuo.tieguanyin.annotations.GenerateMode;
10 | import com.bennyhuo.tieguanyin.annotations.Required;
11 | import com.bennyhuo.tieguanyin.annotations.ResultEntity;
12 |
13 | @Builder(mode = GenerateMode.Both,
14 | resultTypes = {@ResultEntity(name = "name", type = String.class),
15 | @ResultEntity(name = "age", type = Integer.class),
16 | @ResultEntity(name = "title", type = String.class),
17 | @ResultEntity(name = "company", type = String.class)})
18 | public class EditUserActivity extends Activity {
19 |
20 | @Required
21 | String name;
22 |
23 | @Required
24 | int age;
25 |
26 | @Required
27 | String title;
28 |
29 | @Required
30 | String company;
31 |
32 | @Override
33 | protected void onCreate(@Nullable Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 |
36 | EditUserActivityBuilder.smartFinish(this,
37 | 36, "Kotliner",
38 | "bennyhuo", "Kotlin Dev");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app-java/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 30
5 |
6 |
7 |
8 | defaultConfig {
9 | applicationId "com.bennyhuo.tieguanyin.javademo"
10 | minSdkVersion 16
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | implementation 'com.android.support:appcompat-v7:27.1.1'
32 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
33 | implementation 'com.android.support:design:27.1.1'
34 |
35 | implementation project(':runtime')
36 | implementation project(':runtime-kt')
37 | implementation project(':annotations')
38 | annotationProcessor project(':compiler')
39 |
40 | testImplementation 'junit:junit:4.12'
41 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
42 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/fragments/KotlinFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.fragments
2 |
3 | import android.os.Bundle
4 | import android.support.v4.app.Fragment
5 | import android.support.v4.view.ViewCompat
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import com.bennyhuo.tieguanyin.annotations.Builder
10 | import com.bennyhuo.tieguanyin.annotations.Required
11 | import com.bennyhuo.tieguanyin.sample.R
12 | import com.bennyhuo.tieguanyin.sample.transitions.replaceDetailsFragment
13 | import kotlinx.android.synthetic.main.fragment_main.*
14 |
15 | /**
16 | * Created by benny on 2/6/18.
17 | */
18 | @Builder
19 | class KotlinFragment : Fragment() {
20 |
21 | @Required
22 | lateinit var text: String
23 |
24 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
25 | return inflater.inflate(R.layout.fragment_main, container, false)
26 | }
27 |
28 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
29 | super.onViewCreated(view, savedInstanceState)
30 | ViewCompat.setTransitionName(textView, "fragment")
31 | textView.text = text
32 | textView.setOnClickListener {
33 | replaceDetailsFragment("Kotlin Fragment")
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/fragments/KotlinFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.fragments
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.core.view.ViewCompat
8 | import androidx.fragment.app.Fragment
9 | import com.bennyhuo.tieguanyin.annotations.Builder
10 | import com.bennyhuo.tieguanyin.annotations.Required
11 | import com.bennyhuo.tieguanyin.sample.R
12 | import com.bennyhuo.tieguanyin.sample.transitions.replaceDetailsFragment
13 | import kotlinx.android.synthetic.main.fragment_main.*
14 |
15 | /**
16 | * Created by benny on 2/6/18.
17 | */
18 | @Builder
19 | class KotlinFragment : Fragment() {
20 |
21 | @Required
22 | lateinit var text: String
23 |
24 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
25 | return inflater.inflate(R.layout.fragment_main, container, false)
26 | }
27 |
28 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
29 | super.onViewCreated(view, savedInstanceState)
30 | ViewCompat.setTransitionName(textView, "fragment")
31 | textView.text = text
32 | textView.setOnClickListener {
33 | replaceDetailsFragment("Kotlin Fragment")
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/BuilderProcessor.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler
2 |
3 | import com.bennyhuo.aptutils.AptContext
4 | import com.bennyhuo.tieguanyin.annotations.Builder
5 | import com.bennyhuo.tieguanyin.annotations.Optional
6 | import com.bennyhuo.tieguanyin.annotations.Required
7 | import javax.annotation.processing.AbstractProcessor
8 | import javax.annotation.processing.ProcessingEnvironment
9 | import javax.annotation.processing.RoundEnvironment
10 | import javax.lang.model.SourceVersion
11 | import javax.lang.model.element.TypeElement
12 |
13 | /**
14 | * Created by benny on 10/2/16.
15 | */
16 | class BuilderProcessor : AbstractProcessor() {
17 |
18 | private val supportedAnnotations = setOf(Builder::class.java, Required::class.java, Optional::class.java)
19 |
20 | @Synchronized
21 | override fun init(env: ProcessingEnvironment) {
22 | super.init(env)
23 | AptContext.init(env)
24 | }
25 |
26 | override fun getSupportedAnnotationTypes() = supportedAnnotations.map { it.canonicalName }.toSet()
27 |
28 | override fun getSupportedSourceVersion() = SourceVersion.RELEASE_8
29 |
30 | override fun process(annotations: Set, env: RoundEnvironment): Boolean {
31 | if (annotations.isNotEmpty()) {
32 | ClassProcessor(AptContext.filer).process(env)
33 | }
34 | return true
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app-androidx/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app-java/src/main/java/com/bennyhuo/tieguanyin/javademo/fragments/JavaFragment.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.javademo.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.bennyhuo.tieguanyin.annotations.Builder;
12 | import com.bennyhuo.tieguanyin.annotations.Optional;
13 | import com.bennyhuo.tieguanyin.annotations.Required;
14 | import com.bennyhuo.tieguanyin.javademo.R;
15 |
16 | /**
17 | * Created by benny on 2/6/18.
18 | */
19 | @Builder
20 | public class JavaFragment extends Fragment {
21 |
22 | @Required
23 | public String text;
24 |
25 | @Optional
26 | public String text2;
27 |
28 | @Optional
29 | int num;
30 |
31 | @Optional
32 | Double num2;
33 |
34 |
35 | @Nullable
36 | @Override
37 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
38 | return inflater.inflate(R.layout.fragment_main, container, false);
39 | }
40 |
41 | @Override
42 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
43 | super.onViewCreated(view, savedInstanceState);
44 | TextView textView = view.findViewById(R.id.textView);
45 | textView.setText(text);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/transitions/DetailsActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.transitions
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.transition.ChangeBounds
6 | import android.transition.ChangeTransform
7 | import android.transition.TransitionSet
8 | import com.bennyhuo.tieguanyin.annotations.Builder
9 | import com.bennyhuo.tieguanyin.annotations.SharedElement
10 | import com.bennyhuo.tieguanyin.annotations.SharedElementByNames
11 | import com.bennyhuo.tieguanyin.annotations.SharedElementWithName
12 | import com.bennyhuo.tieguanyin.sample.R
13 | import kotlinx.android.synthetic.main.activity_transitions.*
14 |
15 | @Builder(
16 | sharedElements = [SharedElement(sourceId = R.id.openJavaActivity, targetName = "hello")],
17 | sharedElementsWithName = [(SharedElementWithName("button2"))],
18 | sharedElementsByNames = [(SharedElementByNames(source = "button1", target = "button3"))]
19 | )
20 | class DetailsActivity : AppCompatActivity() {
21 |
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | window.sharedElementEnterTransition = TransitionSet().addTransition(ChangeBounds()).addTransition(ChangeTransform())
25 | setContentView(R.layout.activity_transitions)
26 | setTitle(this.javaClass.simpleName)
27 |
28 | openJavaActivity.transitionName = "hello"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/transitions/DetailsActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.transitions
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import android.transition.ChangeBounds
6 | import android.transition.ChangeTransform
7 | import android.transition.TransitionSet
8 | import com.bennyhuo.tieguanyin.annotations.Builder
9 | import com.bennyhuo.tieguanyin.annotations.SharedElement
10 | import com.bennyhuo.tieguanyin.annotations.SharedElementByNames
11 | import com.bennyhuo.tieguanyin.annotations.SharedElementWithName
12 | import com.bennyhuo.tieguanyin.sample.R
13 | import kotlinx.android.synthetic.main.activity_transitions.*
14 |
15 | @Builder(
16 | sharedElements = [SharedElement(sourceId = R.id.openJavaActivity, targetName = "hello")],
17 | sharedElementsWithName = [(SharedElementWithName("button2"))],
18 | sharedElementsByNames = [(SharedElementByNames(source = "button1", target = "button3"))]
19 | )
20 | class DetailsActivity : AppCompatActivity() {
21 |
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | window.sharedElementEnterTransition = TransitionSet().addTransition(ChangeBounds()).addTransition(ChangeTransform())
25 | setContentView(R.layout.activity_transitions)
26 | setTitle(this.javaClass.simpleName)
27 |
28 | openJavaActivity.transitionName = "hello"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app-java/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/BuilderSymbolProcessorProvider.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.useAndroidx
4 | import com.bennyhuo.tieguanyin.compiler.ksp.core.KspContext
5 | import com.bennyhuo.tieguanyin.compiler.ksp.core.logger
6 | import com.google.devtools.ksp.processing.Resolver
7 | import com.google.devtools.ksp.processing.SymbolProcessor
8 | import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
9 | import com.google.devtools.ksp.processing.SymbolProcessorProvider
10 | import com.google.devtools.ksp.symbol.KSAnnotated
11 |
12 | /**
13 | * Created by benny at 2021/6/20 19:03.
14 | */
15 | class BuilderSymbolProcessorProvider: SymbolProcessorProvider {
16 | override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
17 | return BuilderSymbolProcessor(environment)
18 | }
19 | }
20 |
21 | class BuilderSymbolProcessor(private val environment: SymbolProcessorEnvironment): SymbolProcessor {
22 |
23 | override fun process(resolver: Resolver): List {
24 | KspContext.environment = environment
25 | KspContext.resolver = resolver
26 |
27 | useAndroidx = environment.options["useSupportLibrary"]?.toBooleanStrictOrNull() ?: true
28 | logger.info("Generate source files with Androidx Library: $useAndroidx")
29 |
30 | ClassProcessor().process(resolver)
31 |
32 | return emptyList()
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/runtime-androidx/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
23 | -keep class com.bennyhuo.tieguanyin.annotations.*
24 |
25 | -keep @com.bennyhuo.tieguanyin.annotations.Generated public class ** {
26 | public static void inject(android.app.Activity, android.os.Bundle);
27 | public static void saveState(android.app.Activity, android.os.Bundle);
28 | }
29 |
30 | -keep @com.bennyhuo.tieguanyin.annotations.Generated public class ** {
31 | public static void inject(androidx.fragment.app.Fragment, android.os.Bundle);
32 | public static void saveState(androidx.fragment.app.Fragment, android.os.Bundle);
33 | }
34 |
35 | -keep public class androidx.fragment.app.Fragment {
36 | java.lang.String mWho;
37 | }
--------------------------------------------------------------------------------
/runtime/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
23 | -keep class com.bennyhuo.tieguanyin.annotations.*
24 |
25 | -keep @com.bennyhuo.tieguanyin.annotations.Generated public class ** {
26 | public static void inject(android.app.Activity, android.os.Bundle);
27 | public static void saveState(android.app.Activity, android.os.Bundle);
28 | }
29 |
30 | -keep @com.bennyhuo.tieguanyin.annotations.Generated public class ** {
31 | public static void inject(android.support.v4.app.Fragment, android.os.Bundle);
32 | public static void saveState(android.support.v4.app.Fragment, android.os.Bundle);
33 | }
34 |
35 | -keep public class android.support.v4.app.Fragment {
36 | java.lang.String mWho;
37 | }
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/fragment/FragmentClass.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.fragment
2 |
3 | import com.bennyhuo.tieguanyin.annotations.Builder
4 | import com.bennyhuo.tieguanyin.compiler.basic.BasicClass
5 | import java.util.*
6 | import javax.lang.model.element.TypeElement
7 |
8 | /**
9 | * Created by benny on 1/29/18.
10 | */
11 | class FragmentClass
12 | private constructor(type: TypeElement, builder: Builder)
13 | : BasicClass(type, builder) {
14 |
15 | companion object {
16 | private val fragmentClassCache = WeakHashMap()
17 |
18 | fun getOrNull(typeElement: TypeElement): FragmentClass? {
19 | var fragmentClass = fragmentClassCache[typeElement]
20 | if (fragmentClass == null) {
21 | val builder = typeElement.getAnnotation(Builder::class.java) ?: return null
22 | fragmentClass = FragmentClass(typeElement, builder)
23 | fragmentClassCache[typeElement] = fragmentClass
24 | }
25 | return fragmentClass
26 | }
27 |
28 | fun create(typeElement: TypeElement): FragmentClass {
29 | return fragmentClassCache.getOrPut(typeElement){
30 | FragmentClass(typeElement, typeElement.getAnnotation(Builder::class.java))
31 | }
32 | }
33 | }
34 |
35 | val builder = FragmentClassBuilder(this)
36 |
37 | override fun createSuperClass(superClassElement: TypeElement) = getOrNull(superClassElement)
38 | }
39 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 |
13 | # When configured, Gradle will run in incubating parallel mode.
14 | # This option should only be used with decoupled projects. More details, visit
15 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
16 | # org.gradle.parallel=true
17 | org.gradle.jvmargs=-Xmx4096m
18 | android.useAndroidX=true
19 |
20 | GROUP=com.bennyhuo.tieguanyin
21 | VERSION_NAME=2.1.0
22 |
23 | POM_NAME=tieguanyin
24 |
25 | POM_URL=https://github.com/bennyhuo/TieGuanYin
26 | POM_DESCRIPTION=An Activity & Fragment builder to make it easier and safer to start a new page.
27 |
28 | POM_SCM_URL=https://github.com/bennyhuo/TieGuanYin
29 | POM_SCM_CONNECTION=scm:git:git://github.com/bennyhuo/TieGuanYin.git
30 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com:bennyhuo/TieGuanYin.git
31 |
32 | POM_LICENCE_NAME=MIT License
33 | POM_LICENCE_URL=https://github.com/bennyhuo/TieGuanYin/blob/master/LICENSE
34 | POM_LICENCE_DIST=repo
35 |
36 | POM_DEVELOPER_ID=bennyhuo
37 | POM_DEVELOPER_NAME=Benny Huo
38 | POM_DEVELOPER_URL=https://github.com/bennyhuo/
39 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/basic/entity/Field.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.basic.entity
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.core.logger
4 | import com.google.devtools.ksp.symbol.KSPropertyDeclaration
5 | import com.google.devtools.ksp.symbol.Modifier
6 | import com.squareup.kotlinpoet.ksp.toTypeName
7 |
8 | /**
9 | * Created by benny on 1/29/18.
10 | */
11 |
12 | open class Field(
13 | key: String,
14 | private val declaration: KSPropertyDeclaration
15 | ) : Comparable {
16 |
17 | val name = declaration.simpleName.asString()
18 |
19 | val key = key.takeIf { it.isNotBlank() } ?: name
20 |
21 | val docString = declaration.docString?.replace("\n", "") ?: ""
22 |
23 | open val prefix = "REQUIRED_"
24 |
25 | init {
26 | checkValidation()
27 | }
28 |
29 | fun asTypeName() = asKotlinTypeName()
30 |
31 | open fun asKotlinTypeName() = declaration.type.resolve().toTypeName()
32 |
33 | override fun compareTo(other: Field): Int {
34 | return name.compareTo(other.name)
35 | }
36 |
37 | private fun isProtectedOrPrivate(): Boolean {
38 | return Modifier.PRIVATE in declaration.modifiers || Modifier.PROTECTED in declaration.modifiers
39 | }
40 |
41 | private fun checkValidation() {
42 | if(isProtectedOrPrivate()) {
43 | logger.error("""Field '$name' in '${declaration.parentDeclaration?.qualifiedName?.asString()}'
44 | | should not be private or protected.""".trimMargin())
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/ActivityClassBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity
2 |
3 | import com.bennyhuo.tieguanyin.compiler.activity.builder.*
4 | import com.bennyhuo.tieguanyin.compiler.basic.BasicClassBuilder
5 | import com.bennyhuo.tieguanyin.compiler.basic.builder.FieldBuilder
6 | import com.squareup.javapoet.TypeSpec.Builder
7 | import com.squareup.kotlinpoet.FileSpec
8 |
9 | class ActivityClassBuilder(private val activityClass: ActivityClass)
10 | : BasicClassBuilder(activityClass) {
11 |
12 | override fun buildCommon(typeBuilder: Builder) {
13 | ConstantBuilder(activityClass).build(typeBuilder)
14 | FieldBuilder(activityClass).build(typeBuilder)
15 | InjectMethodBuilder(activityClass).build(typeBuilder)
16 | SaveStateMethodBuilder(activityClass).build(typeBuilder)
17 | NewIntentMethodBuilder(activityClass).build(typeBuilder)
18 | }
19 |
20 | override fun buildKotlinBuilders(fileBuilder: FileSpec.Builder) {
21 | StartKFunctionBuilder(activityClass).build(fileBuilder)
22 | FinishKFunctionBuilder(activityClass).build(fileBuilder)
23 | NewIntentKFunctionBuilder(activityClass).build(fileBuilder)
24 | }
25 |
26 | override fun buildJavaBuilders(typeBuilder: Builder) {
27 | StartMethodBuilder(activityClass, METHOD_NAME).build(typeBuilder)
28 | FinishMethodBuilder(activityClass).build(typeBuilder)
29 | }
30 |
31 | companion object {
32 | const val METHOD_NAME = "start"
33 | const val CONSTS_RESULT_PREFIX = "RESULT_"
34 | }
35 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/basic/builder/BasicSaveStateMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.basic.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.BasicClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.BUNDLE
5 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.INTENT
6 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.toKotlinTypeName
7 | import com.squareup.kotlinpoet.FunSpec
8 | import com.squareup.kotlinpoet.TypeName
9 | import com.squareup.kotlinpoet.TypeSpec
10 | import com.squareup.kotlinpoet.UNIT
11 |
12 | abstract class BasicSaveStateMethodBuilder(val basicClass: BasicClass) {
13 |
14 | abstract val instanceType: TypeName
15 |
16 | fun build(typeBuilder: TypeSpec.Builder) {
17 | val methodBuilder = FunSpec.builder("saveState")
18 | .addAnnotation(JvmStatic::class)
19 | .returns(UNIT)
20 | .addParameter("instance", instanceType)
21 | .addParameter("outState", BUNDLE.kotlin)
22 | .beginControlFlow(
23 | "if(instance is %T)",
24 | basicClass.declaration.toKotlinTypeName()
25 | )
26 |
27 | methodBuilder.addStatement("val intent = %T()", INTENT.kotlin)
28 |
29 | for (requiredField in basicClass.fields) {
30 | methodBuilder.addStatement("intent.putExtra(%S, instance.%L)",
31 | requiredField.key, requiredField.name
32 | )
33 | }
34 |
35 | methodBuilder.addStatement("outState.putAll(intent.getExtras())").endControlFlow()
36 |
37 | typeBuilder.addFunction(methodBuilder.build())
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/transitions/DetailsFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.transitions
2 |
3 | import android.os.Bundle
4 | import android.support.v4.app.Fragment
5 | import android.support.v4.view.ViewCompat
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import com.bennyhuo.tieguanyin.annotations.Builder
10 | import com.bennyhuo.tieguanyin.annotations.Required
11 | import com.bennyhuo.tieguanyin.annotations.SharedElementWithName
12 | import com.bennyhuo.tieguanyin.sample.R
13 | import com.bennyhuo.tieguanyin.sample.fragments.JavaFragmentBuilder
14 | import kotlinx.android.synthetic.main.fragment_transitions.*
15 |
16 | /**
17 | * Created by benny on 2/6/18.
18 | */
19 | @Builder(
20 | //sharedElements = [SharedElement(sourceId = R.id.textView, targetName = "fragment")]
21 | sharedElementsWithName = [SharedElementWithName("fragment")]
22 | )
23 | class DetailsFragment : Fragment() {
24 |
25 | @Required
26 | lateinit var text: String
27 |
28 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
29 | return inflater.inflate(R.layout.fragment_transitions, container, false)
30 | }
31 |
32 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
33 | super.onViewCreated(view, savedInstanceState)
34 | ViewCompat.setTransitionName(textView, "fragment")
35 | textView.text = text
36 | textView.setOnClickListener {
37 | JavaFragmentBuilder.builder("Hello").num(1).num2(2.0).replace(this.activity, R.id.fragmentContainer)
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/transitions/DetailsFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.transitions
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.core.view.ViewCompat
8 | import androidx.fragment.app.Fragment
9 | import com.bennyhuo.tieguanyin.annotations.Builder
10 | import com.bennyhuo.tieguanyin.annotations.Required
11 | import com.bennyhuo.tieguanyin.annotations.SharedElementWithName
12 | import com.bennyhuo.tieguanyin.sample.R
13 | import com.bennyhuo.tieguanyin.sample.fragments.JavaFragmentBuilder
14 | import kotlinx.android.synthetic.main.fragment_transitions.*
15 |
16 | /**
17 | * Created by benny on 2/6/18.
18 | */
19 | @Builder(
20 | //sharedElements = [SharedElement(sourceId = R.id.textView, targetName = "fragment")]
21 | sharedElementsWithName = [SharedElementWithName("fragment")]
22 | )
23 | class DetailsFragment : Fragment() {
24 |
25 | @Required
26 | lateinit var text: String
27 |
28 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
29 | return inflater.inflate(R.layout.fragment_transitions, container, false)
30 | }
31 |
32 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
33 | super.onViewCreated(view, savedInstanceState)
34 | ViewCompat.setTransitionName(textView, "fragment")
35 | textView.text = text
36 | textView.setOnClickListener {
37 | JavaFragmentBuilder.builder("Hello").num(1).num2(2.0).replace(requireActivity(), R.id.fragmentContainer)
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/utils/TypeExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.utils
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.core.KspContext
4 | import com.google.devtools.ksp.getClassDeclarationByName
5 | import com.google.devtools.ksp.symbol.ClassKind
6 | import com.google.devtools.ksp.symbol.KSClassDeclaration
7 | import com.google.devtools.ksp.symbol.KSType
8 | import com.google.devtools.ksp.symbol.Nullability
9 | import com.squareup.kotlinpoet.ksp.toTypeName
10 | import kotlin.reflect.KClass
11 |
12 | inline fun Any?.safeCastAs() = this as? T
13 | inline fun Any.castAs() = this as T
14 |
15 | fun KClass<*>.toKsType(): KSType {
16 | return KspContext.resolver
17 | .getClassDeclarationByName(qualifiedName!!)!!
18 | .asType(emptyList())
19 | }
20 |
21 | val KSType.isNonNull: Boolean
22 | get() = nullability == Nullability.NOT_NULL
23 |
24 | val KSType.isNullable: Boolean
25 | get() = nullability == Nullability.NULLABLE || nullability == Nullability.PLATFORM
26 |
27 | fun KSType.isSubTypeOf(typeName: String): Boolean {
28 | return KspContext.resolver.getClassDeclarationByName(typeName)
29 | ?.asStarProjectedType()
30 | ?.isAssignableFrom(this) == true
31 | }
32 |
33 | fun KSClassDeclaration.asType() = asStarProjectedType()
34 |
35 | fun KSClassDeclaration.superType(): KSClassDeclaration? {
36 | return superTypes.map { it.resolve().declaration }
37 | .filterIsInstance()
38 | .filter { it.classKind == ClassKind.CLASS }
39 | .firstOrNull()
40 | }
41 |
42 | fun KSClassDeclaration.toKotlinTypeName() = asStarProjectedType().toTypeName()
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/fragments/JavaFragment.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.bennyhuo.tieguanyin.annotations.Builder;
12 | import com.bennyhuo.tieguanyin.annotations.Optional;
13 | import com.bennyhuo.tieguanyin.annotations.Required;
14 | import com.bennyhuo.tieguanyin.sample.R;
15 |
16 | /**
17 | * Created by benny on 2/6/18.
18 | */
19 | @Builder
20 | public class JavaFragment extends Fragment {
21 |
22 | @Required
23 | public String text;
24 |
25 | @Optional
26 | public String text2;
27 |
28 | @Optional
29 | int num;
30 |
31 | @Optional
32 | Double num2;
33 |
34 |
35 | @Nullable
36 | @Override
37 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
38 | return inflater.inflate(R.layout.fragment_main, container, false);
39 | }
40 |
41 | @Override
42 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
43 | super.onViewCreated(view, savedInstanceState);
44 | TextView textView = view.findViewById(R.id.textView);
45 | textView.setText(text);
46 | textView.setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | KotlinFragmentBuilder.builder("From Java").replace(getActivity(), getId());
50 | }
51 | });
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/fragments/JavaFragment.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.annotation.Nullable;
10 | import androidx.fragment.app.Fragment;
11 |
12 | import com.bennyhuo.tieguanyin.annotations.Builder;
13 | import com.bennyhuo.tieguanyin.annotations.Optional;
14 | import com.bennyhuo.tieguanyin.annotations.Required;
15 | import com.bennyhuo.tieguanyin.sample.R;
16 |
17 | /**
18 | * Created by benny on 2/6/18.
19 | */
20 | @Builder
21 | public class JavaFragment extends Fragment {
22 |
23 | @Required
24 | public String text;
25 |
26 | @Optional
27 | public String text2;
28 |
29 | @Optional
30 | int num;
31 |
32 | @Optional
33 | Double num2;
34 |
35 |
36 | @Nullable
37 | @Override
38 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
39 | return inflater.inflate(R.layout.fragment_main, container, false);
40 | }
41 |
42 | @Override
43 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
44 | super.onViewCreated(view, savedInstanceState);
45 | TextView textView = view.findViewById(R.id.textView);
46 | textView.setText(text);
47 | textView.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | KotlinFragmentBuilder.builder("From Java").replace(getActivity(), getId());
51 | }
52 | });
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/fragment/FragmentClass.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.fragment
2 |
3 | import com.bennyhuo.tieguanyin.annotations.Builder
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.BasicClass
5 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.getFirstAnnotationByType
6 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.getFirstAnnotationByTypeOrNull
7 | import com.google.devtools.ksp.symbol.KSClassDeclaration
8 | import java.util.*
9 |
10 | /**
11 | * Created by benny on 1/29/18.
12 | */
13 | class FragmentClass
14 | private constructor(type: KSClassDeclaration, builder: Builder) : BasicClass(type, builder) {
15 |
16 | companion object {
17 | private val fragmentClassCache = WeakHashMap()
18 |
19 | fun getOrNull(declaration: KSClassDeclaration): FragmentClass? {
20 | var fragmentClass = fragmentClassCache[declaration]
21 | if (fragmentClass == null) {
22 | val builder = declaration.getFirstAnnotationByTypeOrNull(Builder::class) ?: return null
23 | fragmentClass = FragmentClass(declaration, builder)
24 | fragmentClassCache[declaration] = fragmentClass
25 | }
26 | return fragmentClass
27 | }
28 |
29 | fun create(declaration: KSClassDeclaration): FragmentClass {
30 | return fragmentClassCache.getOrPut(declaration){
31 | FragmentClass(declaration, declaration.getFirstAnnotationByType(Builder::class))
32 | }
33 | }
34 | }
35 |
36 |
37 | val builder = FragmentClassBuilder(this)
38 |
39 | override fun createSuperClass(superClassDeclaration: KSClassDeclaration) = getOrNull(superClassDeclaration)
40 | }
41 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/basic/entity/OptionalField.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.basic.entity
2 |
3 | import com.bennyhuo.aptutils.types.isSameTypeWith
4 | import com.bennyhuo.tieguanyin.annotations.Optional
5 | import javax.lang.model.element.VariableElement
6 | import javax.lang.model.type.TypeKind
7 |
8 | /**
9 | * Created by benny on 1/31/18.
10 | */
11 | class OptionalField(element: VariableElement, optional: Optional) : Field(element) {
12 |
13 | var defaultValue: Any? = null
14 | private set
15 |
16 | override val prefix = "OPTIONAL_"
17 |
18 | init {
19 | val fieldType = element.asType()
20 | defaultValue = when (fieldType.kind) {
21 | TypeKind.BOOLEAN -> optional.booleanValue
22 | TypeKind.CHAR -> "'${optional.charValue}'"
23 | TypeKind.BYTE -> "(byte) ${optional.byteValue}"
24 | TypeKind.SHORT -> "(short) ${optional.shortValue}"
25 | TypeKind.INT -> optional.intValue
26 | TypeKind.LONG -> "${optional.longValue}L"
27 | TypeKind.FLOAT -> "${optional.floatValue}f"
28 | TypeKind.DOUBLE -> optional.doubleValue
29 | else -> if (fieldType.isSameTypeWith(String::class)) {
30 | //注意字面量的引号
31 | """"${optional.stringValue}""""
32 | } else {
33 | null
34 | }
35 | }
36 | }
37 |
38 | override fun asKotlinTypeName() = super.asKotlinTypeName().asNullable()
39 |
40 | override fun compareTo(other: Field): Int {
41 | return if (other is OptionalField) {
42 | super.compareTo(other)
43 | } else {
44 | //如果与 RequiredField 比较,Optional 永远排在后面
45 | 1
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/runtime/src/main/java/com/bennyhuo/tieguanyin/runtime/core/BuilderClassFinder.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | public class BuilderClassFinder {
7 | private static final String BUILDER_NAME_POSIX = "Builder";
8 |
9 | private static final HashMap builderClassCache = new HashMap<>();
10 |
11 | public static Class> findBuilderClass(Object object) throws ClassNotFoundException {
12 | Class> cls = object.getClass();
13 | Class builderClass = builderClassCache.get(cls.getCanonicalName());
14 | if (builderClass == null) {
15 | builderClass = Class.forName(findBuilderClassName(object));
16 | builderClassCache.put(cls.getCanonicalName(), builderClass);
17 | }
18 | return builderClass;
19 | }
20 |
21 | static String findBuilderClassName(Object object) {
22 | Class> cls = object.getClass();
23 | Class> enclosingClass = cls.getEnclosingClass();
24 | ArrayList names = new ArrayList<>();
25 | names.add(cls.getSimpleName());
26 | while (enclosingClass != null) {
27 | names.add(enclosingClass.getSimpleName());
28 | enclosingClass = enclosingClass.getEnclosingClass();
29 | }
30 | StringBuilder stringBuilder = new StringBuilder();
31 | stringBuilder.append(cls.getPackage().getName()).append(".");
32 | for (int i = names.size() - 1; i >= 0; i--) {
33 | stringBuilder.append(names.get(i));
34 | if (i != 0) {
35 | stringBuilder.append("_");
36 | }
37 | }
38 | stringBuilder.append(BUILDER_NAME_POSIX);
39 | return stringBuilder.toString();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/com/bennyhuo/tieguanyin/runtime/core/BuilderClassFinder.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.runtime.core;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | public class BuilderClassFinder {
7 | private static final String BUILDER_NAME_POSIX = "Builder";
8 |
9 | private static final HashMap builderClassCache = new HashMap<>();
10 |
11 | public static Class> findBuilderClass(Object object) throws ClassNotFoundException {
12 | Class> cls = object.getClass();
13 | Class builderClass = builderClassCache.get(cls.getCanonicalName());
14 | if (builderClass == null) {
15 | builderClass = Class.forName(findBuilderClassName(object));
16 | builderClassCache.put(cls.getCanonicalName(), builderClass);
17 | }
18 | return builderClass;
19 | }
20 |
21 | static String findBuilderClassName(Object object) {
22 | Class> cls = object.getClass();
23 | Class> enclosingClass = cls.getEnclosingClass();
24 | ArrayList names = new ArrayList<>();
25 | names.add(cls.getSimpleName());
26 | while (enclosingClass != null) {
27 | names.add(enclosingClass.getSimpleName());
28 | enclosingClass = enclosingClass.getEnclosingClass();
29 | }
30 | StringBuilder stringBuilder = new StringBuilder();
31 | stringBuilder.append(cls.getPackage().getName()).append(".");
32 | for (int i = names.size() - 1; i >= 0; i--) {
33 | stringBuilder.append(names.get(i));
34 | if (i != 0) {
35 | stringBuilder.append("_");
36 | }
37 | }
38 | stringBuilder.append(BUILDER_NAME_POSIX);
39 | return stringBuilder.toString();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/builder/FinishKFunctionBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity.builder
2 |
3 | import com.bennyhuo.aptutils.types.asKotlinTypeName
4 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClass
5 | import com.bennyhuo.tieguanyin.compiler.basic.types.ACTIVITY_COMPAT
6 | import com.bennyhuo.tieguanyin.compiler.basic.types.INTENT
7 | import com.bennyhuo.tieguanyin.compiler.utils.isDefault
8 | import com.squareup.kotlinpoet.FileSpec
9 | import com.squareup.kotlinpoet.FunSpec
10 |
11 | class FinishKFunctionBuilder(private val activityClass: ActivityClass) {
12 |
13 | fun build(fileSpecBuilder: FileSpec.Builder) {
14 | val funBuilder = FunSpec.builder("smartFinish")
15 | .receiver(activityClass.typeElement.asType().asKotlinTypeName())
16 |
17 | activityClass.resultParameters.also {
18 | if (it.isNotEmpty()) {
19 | funBuilder.addStatement("val intent = %T()", INTENT.kotlin)
20 | .addStatement("setResult(1, intent)")
21 | }
22 | }.forEach { resultParameter ->
23 | funBuilder.addParameter(resultParameter.name, resultParameter.kotlinTypeName)
24 | .addStatement("intent.putExtra(%S, %L)", resultParameter.name, resultParameter.name)
25 | }
26 |
27 | funBuilder.addStatement("%T.finishAfterTransition(this)", ACTIVITY_COMPAT.kotlin)
28 |
29 | val pendingTransitionOnFinish = activityClass.pendingTransitionOnFinish
30 | if (!pendingTransitionOnFinish.isDefault()) {
31 | funBuilder.addStatement("overridePendingTransition(%L, %L)", pendingTransitionOnFinish.enterAnim, pendingTransitionOnFinish.exitAnim)
32 | }
33 |
34 | fileSpecBuilder.addFunction(funBuilder.build())
35 | }
36 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/OnIntentKFunctionBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.INTENT
5 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.toKotlinTypeName
6 | import com.squareup.kotlinpoet.ClassName
7 | import com.squareup.kotlinpoet.FileSpec
8 | import com.squareup.kotlinpoet.FunSpec
9 | import com.squareup.kotlinpoet.LambdaTypeName
10 | import com.squareup.kotlinpoet.ParameterSpec
11 | import com.squareup.kotlinpoet.PropertySpec
12 | import com.squareup.kotlinpoet.TypeName
13 | import com.squareup.kotlinpoet.TypeSpec
14 | import com.squareup.kotlinpoet.UNIT
15 |
16 | class OnIntentKFunctionBuilder(private val activityClass: ActivityClass) {
17 |
18 | fun build(typeBuilder: TypeSpec.Builder) {
19 |
20 | val type = LambdaTypeName.get(
21 | receiver = INTENT.kotlin,
22 | returnType = UNIT
23 | ).copy(nullable = true)
24 |
25 | val builderClassTypeName = ClassName(activityClass.packageName, activityClass.builderClassName)
26 |
27 |
28 | val onIntentFunBuilder = FunSpec.builder("onIntent")
29 | .addParameter(
30 | ParameterSpec.builder(
31 | "onIntent", type
32 | ).defaultValue("null").build()
33 | ).addStatement("this.onIntent = onIntent")
34 | .addStatement("return this")
35 | .returns(builderClassTypeName)
36 |
37 | typeBuilder.addFunction(onIntentFunBuilder.build())
38 | typeBuilder.addProperty(
39 | PropertySpec.builder(
40 | "onIntent",
41 | type
42 | ).mutable(true).initializer("null").build()
43 | )
44 | }
45 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: "kotlin-kapt"
8 |
9 | android {
10 | compileSdkVersion 30
11 | buildToolsVersion "30.0.3"
12 |
13 | defaultConfig {
14 | applicationId "com.bennyhuo.tieguanyin.sample"
15 | minSdkVersion 21
16 | targetSdkVersion 26
17 | versionCode 1
18 | versionName "1.0"
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 | }
21 | buildTypes {
22 | debug {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | alpha {
27 | initWith(debug)
28 | minifyEnabled true
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 |
31 | matchingFallbacks = ["debug"]
32 | }
33 | release {
34 | minifyEnabled true
35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
36 | }
37 | }
38 | }
39 |
40 | dependencies {
41 | implementation fileTree(dir: 'libs', include: ['*.jar'])
42 | implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
43 | implementation 'com.android.support:appcompat-v7:27.1.1'
44 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
45 |
46 | implementation project(':runtime')
47 | implementation project(':runtime-kt')
48 | implementation project(':annotations')
49 | kapt project(':compiler')
50 |
51 | testImplementation 'junit:junit:4.12'
52 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
53 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
54 | }
55 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/basic/BasicClassBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.basic
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.GENERATED_ANNOTATION
4 | import com.bennyhuo.tieguanyin.compiler.ksp.core.KspContext
5 | import com.bennyhuo.tieguanyin.compiler.ksp.core.logger
6 | import com.squareup.kotlinpoet.ClassName
7 | import com.squareup.kotlinpoet.FileSpec
8 | import com.squareup.kotlinpoet.KModifier
9 | import com.squareup.kotlinpoet.TypeSpec
10 | import com.squareup.kotlinpoet.ksp.writeTo
11 |
12 | abstract class BasicClassBuilder(private val basicClass: BasicClass) {
13 |
14 | private fun writeKotlinToFile(fileSpec: FileSpec) {
15 | fileSpec.writeTo(KspContext.environment.codeGenerator, false, listOf(basicClass.declaration.containingFile!!))
16 | }
17 |
18 | fun build() {
19 | try {
20 | if (basicClass.isAbstract) return
21 |
22 | val fileSpecBuilder = FileSpec.builder(basicClass.packageName, basicClass.builderClassName)
23 | .addAnnotation(GENERATED_ANNOTATION.kotlin as ClassName)
24 |
25 | val typeBuilder = TypeSpec.classBuilder(basicClass.builderClassName)
26 | .addModifiers(KModifier.PUBLIC, KModifier.FINAL)
27 | .addAnnotation(GENERATED_ANNOTATION.kotlin as ClassName)
28 |
29 | buildBuilderClass(typeBuilder)
30 | buildKotlinExtensions(fileSpecBuilder)
31 |
32 | fileSpecBuilder.addType(typeBuilder.build())
33 | writeKotlinToFile(fileSpecBuilder.build())
34 | } catch (e: Exception) {
35 | logger.error(e.toString(), basicClass.declaration)
36 | throw e
37 | }
38 | }
39 |
40 | abstract fun buildBuilderClass(typeBuilder: TypeSpec.Builder)
41 | abstract fun buildKotlinExtensions(fileBuilder: FileSpec.Builder)
42 |
43 | }
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/basic/builder/BasicSaveStateMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.basic.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.basic.BasicClass
4 | import com.bennyhuo.tieguanyin.compiler.basic.types.BUNDLE
5 | import com.bennyhuo.tieguanyin.compiler.basic.types.INTENT
6 | import com.squareup.javapoet.MethodSpec
7 | import com.squareup.javapoet.TypeName
8 | import com.squareup.javapoet.TypeSpec
9 | import javax.lang.model.element.Modifier
10 |
11 | abstract class BasicSaveStateMethodBuilder(val basicClass: BasicClass) {
12 |
13 | abstract val instanceType: TypeName
14 |
15 | fun build(typeBuilder: TypeSpec.Builder) {
16 | val methodBuilder = MethodSpec.methodBuilder("saveState")
17 | .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
18 | .returns(TypeName.VOID)
19 | .addParameter(instanceType, "instance")
20 | .addParameter(BUNDLE.java, "outState")
21 | .beginControlFlow("if(instance instanceof \$T)", basicClass.typeElement)
22 | .addStatement("\$T typedInstance = (\$T) instance", basicClass.typeElement, basicClass.typeElement)
23 |
24 | methodBuilder.addStatement("\$T intent = new \$T()", INTENT.java, INTENT.java)
25 |
26 | for (requiredField in basicClass.fields) {
27 | val name = requiredField.name
28 | if (requiredField.isPrivate) {
29 | methodBuilder.addStatement("intent.putExtra(\$S, typedInstance.get\$L())", name, name.capitalize())
30 | } else {
31 | methodBuilder.addStatement("intent.putExtra(\$S, typedInstance.\$L)", name, name)
32 | }
33 | }
34 |
35 | methodBuilder.addStatement("outState.putAll(intent.getExtras())").endControlFlow()
36 |
37 | typeBuilder.addMethod(methodBuilder.build())
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/FinishKFunctionBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.ACTIVITY_COMPAT
5 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.INTENT
6 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.asType
7 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.isDefault
8 | import com.squareup.kotlinpoet.FileSpec
9 | import com.squareup.kotlinpoet.FunSpec
10 | import com.squareup.kotlinpoet.ksp.toTypeName
11 |
12 | class FinishKFunctionBuilder(private val activityClass: ActivityClass) {
13 |
14 | fun build(fileSpecBuilder: FileSpec.Builder) {
15 | val funBuilder = FunSpec.builder("smartFinish")
16 | .receiver(activityClass.declaration.asType().toTypeName())
17 |
18 | activityClass.resultParameters.also {
19 | if (it.isNotEmpty()) {
20 | funBuilder.addStatement("val intent = %T()", INTENT.kotlin)
21 | .addStatement("setResult(1, intent)")
22 | }
23 | }.forEach { resultParameter ->
24 | funBuilder.addParameter(resultParameter.name, resultParameter.kotlinTypeName)
25 | .addStatement("intent.putExtra(%S, %L)", resultParameter.name, resultParameter.name)
26 | }
27 |
28 | funBuilder.addStatement("%T.finishAfterTransition(this)", ACTIVITY_COMPAT.kotlin)
29 |
30 | val pendingTransitionOnFinish = activityClass.pendingTransitionOnFinish
31 | if (!pendingTransitionOnFinish.isDefault()) {
32 | funBuilder.addStatement("overridePendingTransition(%L, %L)", pendingTransitionOnFinish.enterAnim, pendingTransitionOnFinish.exitAnim)
33 | }
34 |
35 | fileSpecBuilder.addFunction(funBuilder.build())
36 | }
37 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/fragment/FragmentClassBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.fragment
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.BasicClassBuilder
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.builder.FieldBuilder
5 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder.AddKFunctionBuilder
6 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder.AddMethodBuilder
7 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder.ConstantBuilder
8 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder.InjectMethodBuilder
9 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder.ReplaceKFunctionBuilder
10 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder.ReplaceMethodBuilder
11 | import com.bennyhuo.tieguanyin.compiler.ksp.fragment.builder.SaveStateMethodBuilder
12 | import com.squareup.kotlinpoet.FileSpec
13 | import com.squareup.kotlinpoet.TypeSpec
14 |
15 | class FragmentClassBuilder(private val fragmentClass: FragmentClass): BasicClassBuilder(fragmentClass) {
16 |
17 | override fun buildBuilderClass(typeBuilder: TypeSpec.Builder) {
18 | val companionObject = TypeSpec.companionObjectBuilder()
19 | ConstantBuilder(fragmentClass).build(companionObject)
20 | FieldBuilder(fragmentClass).build(typeBuilder, companionObject)
21 | InjectMethodBuilder(fragmentClass).build(companionObject)
22 | SaveStateMethodBuilder(fragmentClass).build(companionObject)
23 |
24 | ReplaceMethodBuilder(fragmentClass).build(typeBuilder)
25 | AddMethodBuilder(fragmentClass).build(typeBuilder)
26 |
27 | typeBuilder.addType(companionObject.build())
28 | }
29 |
30 | override fun buildKotlinExtensions(fileBuilder: FileSpec.Builder) {
31 | ReplaceKFunctionBuilder(fragmentClass).build(fileBuilder)
32 | AddKFunctionBuilder(fragmentClass).build(fileBuilder)
33 | }
34 | }
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/NewIntentMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.INTENT
5 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.toKotlinTypeName
6 | import com.squareup.kotlinpoet.FunSpec
7 | import com.squareup.kotlinpoet.TypeSpec
8 | import com.squareup.kotlinpoet.UNIT
9 |
10 | class NewIntentMethodBuilder(private val activityClass: ActivityClass) {
11 |
12 | fun build(typeBuilder: TypeSpec.Builder) {
13 | val newIntentMethodBuilder = FunSpec.builder("processNewIntent")
14 | .addAnnotation(JvmStatic::class)
15 | .returns(UNIT)
16 | .addParameter("activity", activityClass.declaration.toKotlinTypeName())
17 | .addParameter("intent", INTENT.kotlin.copy(nullable = true))
18 |
19 | newIntentMethodBuilder.addStatement("processNewIntent(activity, intent, true)")
20 | typeBuilder.addFunction(newIntentMethodBuilder.build())
21 |
22 | val newIntentWithUpdateIntentMethodBuilder = FunSpec.builder("processNewIntent")
23 | .addAnnotation(JvmStatic::class)
24 | .returns(UNIT)
25 | .addParameter("activity", activityClass.declaration.toKotlinTypeName())
26 | .addParameter("intent", INTENT.kotlin.copy(nullable = true))
27 | .addParameter("updateIntent", Boolean::class)
28 |
29 | //update intent.
30 | newIntentWithUpdateIntentMethodBuilder.beginControlFlow("if(updateIntent)")
31 | .addStatement("activity.setIntent(intent)")
32 | .endControlFlow()
33 |
34 | newIntentWithUpdateIntentMethodBuilder.beginControlFlow("if(intent != null)")
35 | .addStatement("inject(activity, intent.getExtras())")
36 | .endControlFlow()
37 |
38 | typeBuilder.addFunction(newIntentWithUpdateIntentMethodBuilder.build())
39 | }
40 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app-androidx/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app-java/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/builder/NewIntentMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity.builder
2 |
3 | import com.bennyhuo.aptutils.types.asJavaTypeName
4 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClass
5 | import com.bennyhuo.tieguanyin.compiler.basic.types.INTENT
6 | import com.squareup.javapoet.MethodSpec
7 | import com.squareup.javapoet.TypeName
8 | import com.squareup.javapoet.TypeSpec
9 | import javax.lang.model.element.Modifier
10 |
11 | class NewIntentMethodBuilder(private val activityClass: ActivityClass) {
12 |
13 | fun build(typeBuilder: TypeSpec.Builder) {
14 | val newIntentMethodBuilder = MethodSpec.methodBuilder("processNewIntent")
15 | .addModifiers(Modifier.STATIC, Modifier.PUBLIC)
16 | .returns(TypeName.VOID)
17 | .addParameter(activityClass.typeElement.asType().asJavaTypeName(), "activity")
18 | .addParameter(INTENT.java, "intent")
19 |
20 | newIntentMethodBuilder.addStatement("processNewIntent(activity, intent, true)")
21 | typeBuilder.addMethod(newIntentMethodBuilder.build())
22 |
23 | val newIntentWithUpdateIntentMethodBuilder = MethodSpec.methodBuilder("processNewIntent")
24 | .addModifiers(Modifier.STATIC, Modifier.PUBLIC)
25 | .returns(TypeName.VOID)
26 | .addParameter(activityClass.typeElement.asType().asJavaTypeName(), "activity")
27 | .addParameter(INTENT.java, "intent")
28 | .addParameter(Boolean::class.java, "updateIntent")
29 |
30 | //update intent.
31 | newIntentWithUpdateIntentMethodBuilder.beginControlFlow("if(updateIntent)")
32 | .addStatement("activity.setIntent(intent)")
33 | .endControlFlow()
34 |
35 | newIntentWithUpdateIntentMethodBuilder.beginControlFlow("if(intent != null)")
36 | .addStatement("inject(activity, intent.getExtras())")
37 | .endControlFlow()
38 |
39 | typeBuilder.addMethod(newIntentWithUpdateIntentMethodBuilder.build())
40 | }
41 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/UserActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 |
8 | import androidx.annotation.Nullable;
9 |
10 | import com.bennyhuo.tieguanyin.annotations.Builder;
11 | import com.bennyhuo.tieguanyin.annotations.GenerateMode;
12 | import com.bennyhuo.tieguanyin.annotations.Optional;
13 | import com.bennyhuo.tieguanyin.annotations.Required;
14 |
15 | @Builder(mode = GenerateMode.Both)
16 | public class UserActivity extends Activity {
17 |
18 | @Required
19 | String name;
20 |
21 | @Required
22 | int age;
23 |
24 | @Optional
25 | String title;
26 |
27 | @Optional
28 | String company;
29 |
30 | @Override
31 | protected void onCreate(@Nullable Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 |
34 | EditUserActivityBuilder.builder(30, "Kotlin", "bennyhuo", "Kotlin Developer")
35 | .start(this, (age, company, name, title) -> {
36 |
37 | });
38 |
39 | }
40 |
41 | public static void startUserActivity(Context context, String name, int age, String title, String company) {
42 | Intent intent = new Intent(context, UserActivity.class);
43 | intent.putExtra("age", age);
44 | intent.putExtra("name", name);
45 | intent.putExtra("company", company);
46 | intent.putExtra("title", title);
47 | context.startActivity(intent);
48 |
49 |
50 | }
51 |
52 | public void inject(Bundle savedInstanceState) {
53 | this.age = savedInstanceState.getInt( "age");
54 | this.name = savedInstanceState.getString("name");
55 | this.company = savedInstanceState.getString("company" );
56 | this.title = savedInstanceState.getString("title");
57 |
58 | Intent intent = getIntent();
59 | this.age = intent.getIntExtra( "age", 0);
60 | this.name = intent.getStringExtra("name");
61 | this.company = intent.getStringExtra("company" );
62 | this.title = intent.getStringExtra("title");
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/KotlinActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import com.bennyhuo.tieguanyin.annotations.*
7 | import com.bennyhuo.tieguanyin.annotations.GenerateMode.Both
8 | import com.bennyhuo.tieguanyin.utils.toast
9 | import kotlinx.android.synthetic.main.activity_main.*
10 |
11 | /**
12 | * Created by benny on 1/29/18.
13 | */
14 | @Builder(mode = Both,
15 | pendingTransition = PendingTransition(enterAnim = 0, exitAnim = 0),
16 | pendingTransitionOnFinish = PendingTransition(enterAnim = 0, exitAnim = 0),
17 | resultTypes = [(ResultEntity(name = "java", type = Array::class)), (ResultEntity(name = "kotlin", type = IntArray::class))],
18 | flags = [Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT, Intent.FLAG_ACTIVITY_CLEAR_TOP],
19 | categories = [Intent.CATEGORY_APP_BROWSER, Intent.CATEGORY_APP_CALENDAR]
20 | )
21 | class KotlinActivity : AppCompatActivity() {
22 |
23 | @Required
24 | var num: Int = 0
25 |
26 | @Optional
27 | var java: Boolean = false
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | setContentView(R.layout.activity_main)
32 | setTitle(this.javaClass.simpleName)
33 | openJavaActivity.setOnClickListener {
34 | JavaActivityBuilder.builder(1234, 5678)
35 | .start(this@KotlinActivity) { javaMethod, java, kotlin ->
36 | toast("Result From JavaActivity: javaMethod=$javaMethod, java=$java, kotlin=$kotlin")
37 | }
38 | }
39 |
40 | openKotlinActivity.text = "Finish With java='I'm Kotlin!' & kotlin=12"
41 | openKotlinActivity.setOnClickListener {
42 | smartFinish(arrayOf("I'm Java!", "You're Kotlin!"), intArrayOf(12))
43 | }
44 |
45 | openGenerateBothActivity.setOnClickListener {
46 | // openGenerateBothActivity(30, "bennyhuo", num = 1234)
47 | num++
48 | }
49 |
50 | textView.text = "num=$num, java=$java"
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/GenerateBothActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import com.bennyhuo.tieguanyin.annotations.Builder
6 | import com.bennyhuo.tieguanyin.annotations.Optional
7 | import com.bennyhuo.tieguanyin.annotations.PendingTransition
8 | import com.bennyhuo.tieguanyin.annotations.Required
9 | import com.bennyhuo.tieguanyin.utils.toast
10 | import kotlinx.android.synthetic.main.activity_main.*
11 | import java.io.Serializable
12 |
13 | /**
14 | * Created by benny on 1/29/18.
15 | */
16 | @Builder(pendingTransition = PendingTransition(enterAnim = 0, exitAnim = 0))
17 | class GenerateBothActivity : AppCompatActivity() {
18 |
19 | @Required()
20 | lateinit var userName: String
21 |
22 | @Required()
23 | var age: Int = 0
24 |
25 | @Optional(intValue = 123)
26 | var num: Int = 0
27 |
28 | @Optional(stringValue = "I'm title!!")
29 | lateinit var title: String
30 |
31 | @Optional()
32 | lateinit var subTitle: String
33 |
34 | @Optional
35 | lateinit var details: Serializable
36 |
37 | override fun onCreate(savedInstanceState: Bundle?) {
38 | super.onCreate(savedInstanceState)
39 | setContentView(R.layout.activity_main)
40 | setTitle(this.javaClass.simpleName)
41 | openJavaActivity.setOnClickListener {
42 | // JavaActivityBuilder.start(this@GenerateBothActivity, 1234, true){
43 | // java, kotlin ->
44 | // toast("Result From JavaActivity: java=$java, kotlin=$kotlin")
45 | // }
46 | }
47 |
48 | openKotlinActivity.setOnClickListener {
49 | startKotlinActivity(1234){
50 | java, kotlin ->
51 | toast("Result From KotlinActivity: java=$java, kotlin=$kotlin")
52 | }
53 | }
54 |
55 | openGenerateBothActivity.text = "Finish Me!"
56 | openGenerateBothActivity.setOnClickListener {
57 | smartFinish()
58 | }
59 | }
60 |
61 | override fun finish() {
62 | super.finish()
63 | }
64 |
65 | companion object {
66 |
67 | }
68 | }
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/GenerateBothActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import com.bennyhuo.tieguanyin.annotations.Builder
6 | import com.bennyhuo.tieguanyin.annotations.Optional
7 | import com.bennyhuo.tieguanyin.annotations.PendingTransition
8 | import com.bennyhuo.tieguanyin.annotations.Required
9 | import com.bennyhuo.tieguanyin.utils.toast
10 | import kotlinx.android.synthetic.main.activity_main.*
11 | import java.io.Serializable
12 |
13 | /**
14 | * Created by benny on 1/29/18.
15 | */
16 | @Builder(pendingTransition = PendingTransition(enterAnim = 0, exitAnim = 0))
17 | class GenerateBothActivity : AppCompatActivity() {
18 |
19 | @Required()
20 | lateinit var userName: String
21 |
22 | @Required()
23 | var age: Int = 0
24 |
25 | @Optional(intValue = 123)
26 | var num: Int = 0
27 |
28 | @Optional(stringValue = "I'm title!!")
29 | lateinit var title: String
30 |
31 | @Optional()
32 | lateinit var subTitle: String
33 |
34 | @Optional
35 | lateinit var details: Serializable
36 |
37 | override fun onCreate(savedInstanceState: Bundle?) {
38 | super.onCreate(savedInstanceState)
39 | setContentView(R.layout.activity_main)
40 | setTitle(this.javaClass.simpleName)
41 | openJavaActivity.setOnClickListener {
42 | // JavaActivityBuilder.start(this@GenerateBothActivity, 1234, true){
43 | // java, kotlin ->
44 | // toast("Result From JavaActivity: java=$java, kotlin=$kotlin")
45 | // }
46 | }
47 |
48 | openKotlinActivity.setOnClickListener {
49 | startKotlinActivity(1234){
50 | java, kotlin ->
51 | toast("Result From KotlinActivity: java=$java, kotlin=$kotlin")
52 | }
53 | }
54 |
55 | openGenerateBothActivity.text = "Finish Me!"
56 | openGenerateBothActivity.setOnClickListener {
57 | smartFinish()
58 | }
59 | }
60 |
61 | override fun finish() {
62 | super.finish()
63 | }
64 |
65 | companion object {
66 |
67 | }
68 | }
--------------------------------------------------------------------------------
/runtime/src/main/java/android/support/v4/app/SupportFragmentUtils.java:
--------------------------------------------------------------------------------
1 | package android.support.v4.app;
2 |
3 | import android.os.Build;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Created by benny on 2/13/18.
9 | */
10 |
11 | public class SupportFragmentUtils {
12 |
13 | public static String getWhoFromFragment(Fragment fragment){
14 | return fragment.mWho;
15 | }
16 |
17 | public static Fragment findFragmentByWho(FragmentManager fragmentManager, String who){
18 | return ((FragmentManagerImpl)fragmentManager).findFragmentByWho(who);
19 | }
20 |
21 | public static void addSharedElement(FragmentTransaction fragmentTransaction, String sourceName, String targetName) {
22 | if (fragmentTransaction instanceof BackStackRecord) {
23 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
24 | BackStackRecord backStackRecord = (BackStackRecord) fragmentTransaction;
25 | if (sourceName == null) {
26 | throw new IllegalArgumentException("Unique transitionNames are required for all" +
27 | " sharedElements");
28 | }
29 | if (backStackRecord.mSharedElementSourceNames == null) {
30 | backStackRecord.mSharedElementSourceNames = new ArrayList<>();
31 | backStackRecord.mSharedElementTargetNames = new ArrayList<>();
32 | } else if (backStackRecord.mSharedElementTargetNames.contains(targetName)) {
33 | throw new IllegalArgumentException("A shared element with the target name '"
34 | + targetName + "' has already been added to the transaction.");
35 | } else if (backStackRecord.mSharedElementSourceNames.contains(sourceName)) {
36 | throw new IllegalArgumentException("A shared element with the source name '"
37 | + sourceName + " has already been added to the transaction.");
38 | }
39 |
40 | backStackRecord.mSharedElementSourceNames.add(sourceName);
41 | backStackRecord.mSharedElementTargetNames.add(targetName);
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/bennyhuo/tieguanyin/compiler/activity/builder/FinishMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.activity.builder
2 |
3 | import com.bennyhuo.aptutils.types.asJavaTypeName
4 | import com.bennyhuo.tieguanyin.compiler.activity.ActivityClass
5 | import com.bennyhuo.tieguanyin.compiler.basic.types.ACTIVITY_COMPAT
6 | import com.bennyhuo.tieguanyin.compiler.basic.types.INTENT
7 | import com.bennyhuo.tieguanyin.compiler.utils.isDefault
8 | import com.squareup.javapoet.MethodSpec
9 | import com.squareup.javapoet.TypeName
10 | import com.squareup.javapoet.TypeSpec
11 | import javax.lang.model.element.Modifier
12 |
13 | class FinishMethodBuilder(private val activityClass: ActivityClass) {
14 |
15 | fun build(typeBuilder: TypeSpec.Builder) {
16 | val finishMethodBuilder = MethodSpec.methodBuilder("smartFinish")
17 | .addModifiers(Modifier.STATIC, Modifier.PUBLIC)
18 | .returns(TypeName.VOID)
19 | .addParameter(activityClass.typeElement.asType().asJavaTypeName(), "activity")
20 |
21 | //handle result parameters.
22 | activityClass.resultParameters.also{
23 | if(it.isNotEmpty()){
24 | finishMethodBuilder.addStatement("\$T intent = new \$T()", INTENT.java, INTENT.java)
25 | .addStatement("activity.setResult(1, intent)")
26 | }
27 | }.forEach {
28 | resultParameter ->
29 | finishMethodBuilder.addParameter(resultParameter.javaTypeName, resultParameter.name)
30 | finishMethodBuilder.addStatement("intent.putExtra(\$S, \$L)", resultParameter.name, resultParameter.name)
31 | }
32 |
33 | finishMethodBuilder.addStatement("\$T.finishAfterTransition(activity)", ACTIVITY_COMPAT.java)
34 |
35 | //handle pending transitions.
36 | val pendingTransitionOnFinish = activityClass.pendingTransitionOnFinish
37 | if (!pendingTransitionOnFinish.isDefault()) {
38 | finishMethodBuilder.addStatement("activity.overridePendingTransition(\$L, \$L)", pendingTransitionOnFinish.enterAnim, pendingTransitionOnFinish.exitAnim)
39 | }
40 | typeBuilder.addMethod(finishMethodBuilder.build())
41 | }
42 | }
--------------------------------------------------------------------------------
/runtime-androidx/src/main/java/androidx/fragment/app/SupportFragmentUtils.java:
--------------------------------------------------------------------------------
1 | package androidx.fragment.app;
2 |
3 | import android.os.Build;
4 |
5 | import androidx.fragment.app.Fragment;
6 |
7 | import java.util.ArrayList;
8 |
9 | /**
10 | * Created by benny on 2/13/18.
11 | */
12 |
13 | public class SupportFragmentUtils {
14 |
15 | public static String getWhoFromFragment(Fragment fragment){
16 | return fragment.mWho;
17 | }
18 |
19 | public static Fragment findFragmentByWho(FragmentManager fragmentManager, String who){
20 | return ((FragmentManagerImpl)fragmentManager).findFragmentByWho(who);
21 | }
22 |
23 | public static void addSharedElement(FragmentTransaction fragmentTransaction, String sourceName, String targetName) {
24 | if (fragmentTransaction instanceof BackStackRecord) {
25 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
26 | BackStackRecord backStackRecord = (BackStackRecord) fragmentTransaction;
27 | if (sourceName == null) {
28 | throw new IllegalArgumentException("Unique transitionNames are required for all" +
29 | " sharedElements");
30 | }
31 | if (backStackRecord.mSharedElementSourceNames == null) {
32 | backStackRecord.mSharedElementSourceNames = new ArrayList<>();
33 | backStackRecord.mSharedElementTargetNames = new ArrayList<>();
34 | } else if (backStackRecord.mSharedElementTargetNames.contains(targetName)) {
35 | throw new IllegalArgumentException("A shared element with the target name '"
36 | + targetName + "' has already been added to the transaction.");
37 | } else if (backStackRecord.mSharedElementSourceNames.contains(sourceName)) {
38 | throw new IllegalArgumentException("A shared element with the source name '"
39 | + sourceName + " has already been added to the transaction.");
40 | }
41 |
42 | backStackRecord.mSharedElementSourceNames.add(sourceName);
43 | backStackRecord.mSharedElementTargetNames.add(targetName);
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app-androidx/src/main/java/com/bennyhuo/tieguanyin/sample/KotlinActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import androidx.appcompat.app.AppCompatActivity
6 | import com.bennyhuo.tieguanyin.annotations.*
7 | import com.bennyhuo.tieguanyin.annotations.GenerateMode.Both
8 | import com.bennyhuo.tieguanyin.utils.toast
9 | import kotlinx.android.synthetic.main.activity_main.*
10 |
11 | /**
12 | * Created by benny on 1/29/18.
13 | */
14 | @Builder(mode = Both,
15 | pendingTransition = PendingTransition(enterAnim = 0, exitAnim = 0),
16 | pendingTransitionOnFinish = PendingTransition(enterAnim = 0, exitAnim = 0),
17 | resultTypes = [(ResultEntity(name = "java", type = Array::class)), (ResultEntity(name = "kotlin", type = IntArray::class))],
18 | flags = [Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT, Intent.FLAG_ACTIVITY_CLEAR_TOP],
19 | categories = [Intent.CATEGORY_APP_BROWSER, Intent.CATEGORY_APP_CALENDAR]
20 | )
21 | class KotlinActivity : AppCompatActivity() {
22 |
23 | /**
24 | * This is a number.
25 | */
26 | @Required
27 | var num: Int = 0
28 |
29 | /**
30 | * This is a boolean.
31 | */
32 | @Optional
33 | var java: Boolean = false
34 |
35 | override fun onCreate(savedInstanceState: Bundle?) {
36 | super.onCreate(savedInstanceState)
37 | setContentView(R.layout.activity_main)
38 | setTitle(this.javaClass.simpleName)
39 | openJavaActivity.setOnClickListener {
40 | JavaActivityBuilder.builder(1234, 222)
41 | .start(this@KotlinActivity) { javaMethod, java, kotlin ->
42 | toast("Result From JavaActivity: javaMethod=$javaMethod, java=$java, kotlin=$kotlin")
43 | }
44 | }
45 |
46 | openKotlinActivity.text = "Finish With java='I'm Kotlin!' & kotlin=12"
47 | openKotlinActivity.setOnClickListener {
48 | smartFinish(arrayOf("I'm Java!", "You're Kotlin!"), intArrayOf(12))
49 | }
50 |
51 | openGenerateBothActivity.setOnClickListener {
52 | // openGenerateBothActivity(30, "bennyhuo", num = 1234)
53 | num++
54 | }
55 |
56 | textView.text = "num=$num, java=$java"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/compiler-ksp/src/main/java/com/bennyhuo/tieguanyin/compiler/ksp/activity/builder/FinishMethodBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.compiler.ksp.activity.builder
2 |
3 | import com.bennyhuo.tieguanyin.compiler.ksp.activity.ActivityClass
4 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.ACTIVITY_COMPAT
5 | import com.bennyhuo.tieguanyin.compiler.ksp.basic.types.INTENT
6 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.isDefault
7 | import com.bennyhuo.tieguanyin.compiler.ksp.utils.toKotlinTypeName
8 | import com.squareup.kotlinpoet.FunSpec
9 | import com.squareup.kotlinpoet.TypeSpec
10 | import com.squareup.kotlinpoet.UNIT
11 |
12 | class FinishMethodBuilder(private val activityClass: ActivityClass) {
13 |
14 | fun build(typeBuilder: TypeSpec.Builder) {
15 | val finishMethodBuilder = FunSpec.builder("smartFinish")
16 | .addAnnotation(JvmStatic::class)
17 | .returns(UNIT)
18 | .addParameter("activity", activityClass.declaration.toKotlinTypeName())
19 |
20 | //handle result parameters.
21 | activityClass.resultParameters.also {
22 | if (it.isNotEmpty()) {
23 | finishMethodBuilder.addStatement("val intent = %T()", INTENT.kotlin)
24 | .addStatement("activity.setResult(1, intent)")
25 | }
26 | }.forEach { resultParameter ->
27 | finishMethodBuilder.addParameter(resultParameter.name, resultParameter.kotlinTypeName)
28 | finishMethodBuilder.addStatement(
29 | "intent.putExtra(%S, %L)",
30 | resultParameter.name,
31 | resultParameter.name
32 | )
33 | }
34 |
35 | finishMethodBuilder.addStatement(
36 | "%T.finishAfterTransition(activity)",
37 | ACTIVITY_COMPAT.kotlin
38 | )
39 |
40 | //handle pending transitions.
41 | val pendingTransitionOnFinish = activityClass.pendingTransitionOnFinish
42 | if (!pendingTransitionOnFinish.isDefault()) {
43 | finishMethodBuilder.addStatement(
44 | "activity.overridePendingTransition(%L, %L)",
45 | pendingTransitionOnFinish.enterAnim,
46 | pendingTransitionOnFinish.exitAnim
47 | )
48 | }
49 | typeBuilder.addFunction(finishMethodBuilder.build())
50 | }
51 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bennyhuo/tieguanyin/sample/UserActivity.java:
--------------------------------------------------------------------------------
1 | package com.bennyhuo.tieguanyin.sample;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.bennyhuo.tieguanyin.annotations.Builder;
10 | import com.bennyhuo.tieguanyin.annotations.GenerateMode;
11 | import com.bennyhuo.tieguanyin.annotations.Optional;
12 | import com.bennyhuo.tieguanyin.annotations.Required;
13 |
14 | @Builder(mode = GenerateMode.Both)
15 | public class UserActivity extends Activity {
16 |
17 | @Required
18 | String name;
19 |
20 | @Required
21 | int age;
22 |
23 | @Optional
24 | String title;
25 |
26 | @Optional
27 | String company;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 |
33 | EditUserActivityBuilder.builder(30, "Kotlin", "bennyhuo", "Kotlin Developer")
34 | .start(this, new EditUserActivityBuilder.OnEditUserActivityResultListener() {
35 | @Override
36 | public void onResult(int age, String company, String name, String title) {
37 |
38 | }
39 | });
40 |
41 | }
42 |
43 | public static void startUserActivity(Context context, String name, int age, String title, String company) {
44 | Intent intent = new Intent(context, UserActivity.class);
45 | intent.putExtra("age", age);
46 | intent.putExtra("name", name);
47 | intent.putExtra("company", company);
48 | intent.putExtra("title", title);
49 | context.startActivity(intent);
50 |
51 |
52 | }
53 |
54 | public void inject(Bundle savedInstanceState) {
55 | this.age = savedInstanceState.getInt( "age");
56 | this.name = savedInstanceState.getString("name");
57 | this.company = savedInstanceState.getString("company" );
58 | this.title = savedInstanceState.getString("title");
59 |
60 | Intent intent = getIntent();
61 | this.age = intent.getIntExtra( "age", 0);
62 | this.name = intent.getStringExtra("name");
63 | this.company = intent.getStringExtra("company" );
64 | this.title = intent.getStringExtra("title");
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------