commit 7333b885fd39bdfb7564dd7c710ba4d33bd548c5 Author: fankesyooni Date: Thu Jan 26 01:06:50 2023 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..cbc6c98 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/icon.png b/.idea/icon.png new file mode 100644 index 0000000..36848de Binary files /dev/null and b/.idea/icon.png differ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..465605c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..bdd9278 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..836c52e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 HighCapable + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README-zh-CN.md b/README-zh-CN.md new file mode 100644 index 0000000..59d573b --- /dev/null +++ b/README-zh-CN.md @@ -0,0 +1,80 @@ +# Yuki Reflection + +![Blank](https://img.shields.io/badge/license-MIT-blue) +![Blank](https://img.shields.io/badge/version-v1.0.0-green) +[![Telegram](https://img.shields.io/badge/Follow-Telegram-blue.svg?logo=telegram)](https://t.me/YukiReflection) +

+ +
+
+🌴️ 一个使用 Kotlin 构建的 Android 平台高效反射 API。 +
+ +[English](https://github.com/fankes/YukiReflection/blob/master/README.md) | 简体中文 + +## 这是什么 + +- 这是一个使用 Kotlin 基于 Java 原生反射 API 重新打造的一套简洁、高效的反射 API,同时也是 [YukiHookAPI](https://github.com/fankes/YukiHookAPI) 正在使用的核心功能 +- 名称取自 [《ももくり》女主 栗原 雪(Yuki)](https://www.bilibili.com/bangumi/play/ss5016) + +## 它能做什么 + +- 取代 Java 原生的反射 API,使用更加人性化的语言实现一套更加完善的反射方案 +- 使用注解的方式声明需要反射的类或方法、变量,构造一个 `stub`,直接调用即可实现与反射 API 相同的功能,更加优雅高效 (正在开发,预计在后期逐渐实现此功能) + +## 开始使用 + +- [点击这里](https://fankes.github.io/YukiReflection/zh-cn/) 前往文档页面查看更多详细教程和内容。 + +## 联系我们 + +- [点击加入 Telegram 群组](https://t.me/YukiReflection) + +## 展望未来 + +如果你喜欢 `YukiReflection` 项目,欢迎为此项目贡献你的代码 **PR**,可以是任何改进的建议以及新增的功能。 + +## 合作项目 + +以下是经过合作并稳定使用 `YukiReflection` 的项目。 + +| Repository | Developer | +|------------------------------------------------------|------------------------------------------| +| [YukiHookAPI](https://github.com/fankes/YukiHookAPI) | [fankesyooni](https://github.com/fankes) | + +你也在使用 `YukiReflection` 吗?快来 **PR** 将你的存储仓库添加到上方的列表 (私有仓库可以不需要注明网页链接)。 + +## 捐赠支持 + +- 工作不易,无意外情况此项目将继续维护下去,提供更多可能,欢迎打赏。

+ + +## 许可证 + +- [MIT](https://choosealicense.com/licenses/mit) + +``` +MIT License + +Copyright (C) 2019-2023 HighCapable + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` + +版权所有 © 2019-2023 HighCapable \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..77f90eb --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# Yuki Reflection + +![Blank](https://img.shields.io/badge/license-MIT-blue) +![Blank](https://img.shields.io/badge/version-v1.0.0-green) +[![Telegram](https://img.shields.io/badge/Follow-Telegram-blue.svg?logo=telegram)](https://t.me/YukiReflection) +

+ +
+
+🌴️ An efficient Reflection API for the Android platform built in Kotlin. +
+ +English | [简体中文](https://github.com/fankes/YukiReflection/blob/master/README-zh-CN.md) + +## What's this + +- This is a concise and efficient Reflection API rebuilt based on Java's native Reflection API using Kotlin, and it is also the core function + being used by [YukiHookAPI](https://github.com/fankes/YukiHookAPI) +- The name is taken from ["ももくり" heroine Yuki Kurihara](https://www.bilibili.com/bangumi/play/ss5016) + +## What it can do + +- Instead of Java's native Reflection API, use a more user-friendly language to implement a more complete set of reflection solutions +- Use annotations to declare classes, methods, and fields that need reflection, construct a `stub`, and call directly to achieve the same + function as the Reflection API, which is more elegant and efficient (under development, and it is expected to gradually implement this function + later) + +## Get Started + +- [Click here](https://fankes.github.io/YukiReflection/en/) go to the documentation page for more detailed tutorials and content. + +## Contacts + +- [Follow us on Telegram](https://t.me/YukiReflection) + +## Features + +If you like the `YukiReflection` project, we welcome you to make a **PR** in this project, any suggestions for improvement and new features. + +## Cooperations + +The following are projects that have collaborated and are using `YukiReflection`. + +| Repository | Developer | +|------------------------------------------------------|------------------------------------------| +| [YukiHookAPI](https://github.com/fankes/YukiHookAPI) | [fankesyooni](https://github.com/fankes) | + +Are you also using `YukiReflection`? Come and **PR** to add your repository to the list above (private repositories do not need to indicate web +links). + +## License + +- [MIT](https://choosealicense.com/licenses/mit) + +``` +MIT License + +Copyright (C) 2019-2023 HighCapable + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` + +Copyright © 2019-2023 HighCapable \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..c2f83c6 --- /dev/null +++ b/build.gradle @@ -0,0 +1,45 @@ +//file:noinspection unused +plugins { + id 'com.android.application' version '7.4.0' apply false + id 'com.android.library' version '7.4.0' apply false + id 'org.jetbrains.kotlin.android' version '1.7.22' apply false + id 'org.jetbrains.kotlin.jvm' version '1.7.22' apply false +} + +ext { + devId = "0" + devUser = "fankesyooni" + userEmail = "qzmmcn@163.com" + groupId = "com.highcapable.yukireflection" + apiVersion = "1.0.0" + repoName = "YukiReflection" + repoDescription = "An efficient Reflection API for the Android platform built in Kotlin." + licenceName = "MIT License" + licenceUrl = "https://github.com/fankes/YukiReflection/blob/master/LICENSE" + website = "https://github.com/fankes/YukiReflection" + githubConnection = "scm:git:git://github.com/path/to/repo.git" + githubDeveloperConnection = "scm:git:ssh://github.com/path/to/repo.git" + githubUrl = "https://github.com/path/to/repo" + ossName = "OSSRH" + ossUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" +} + +/** + * 获取授权文件内容 - 用于 Maven 的提交 + * + * 若编译失败请将路径替换为自己的或置空 + * @param name + * @return [String] + */ +static String getFileContent(String name) { + String result = "" + try { + FileReader reader = new FileReader("/Users/fankes/Project/Android/Library/YukiReflection/.gradle/" + name) + BufferedReader buff = new BufferedReader(reader) + result = buff.readLine() + buff.close() + reader.close() + } catch (Throwable ignored) { + } + return result +} \ No newline at end of file diff --git a/demo-app/.gitignore b/demo-app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/demo-app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/demo-app/build.gradle b/demo-app/build.gradle new file mode 100644 index 0000000..64854ef --- /dev/null +++ b/demo-app/build.gradle @@ -0,0 +1,55 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.highcapable.yukireflection.demo_app' + compileSdk 33 + + defaultConfig { + applicationId "com.highcapable.yukireflection.demo_app" + minSdk 21 + targetSdk 33 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = '11' + freeCompilerArgs = [ + '-Xno-param-assertions', + '-Xno-call-assertions', + '-Xno-receiver-assertions' + ] + } + lintOptions { + checkReleaseBuilds false + } + buildFeatures { + viewBinding true + } +} + +dependencies { + implementation project(':yukireflection') + implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.appcompat:appcompat:1.6.0' + implementation 'com.google.android.material:material:1.7.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' +} \ No newline at end of file diff --git a/demo-app/proguard-rules.pro b/demo-app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/demo-app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/demo-app/src/androidTest/java/com/highcapable/yukireflection/ExampleInstrumentedTest.kt b/demo-app/src/androidTest/java/com/highcapable/yukireflection/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..5763fc2 --- /dev/null +++ b/demo-app/src/androidTest/java/com/highcapable/yukireflection/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.highcapable.yukireflection + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.highcapable.yukireflection", appContext.packageName) + } +} \ No newline at end of file diff --git a/demo-app/src/main/AndroidManifest.xml b/demo-app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..08289c1 --- /dev/null +++ b/demo-app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo-app/src/main/ic_launcher-playstore.png b/demo-app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..58eb61e Binary files /dev/null and b/demo-app/src/main/ic_launcher-playstore.png differ diff --git a/demo-app/src/main/java/com/highcapable/yukireflection/demo_app/test/Main.java b/demo-app/src/main/java/com/highcapable/yukireflection/demo_app/test/Main.java new file mode 100644 index 0000000..8aff653 --- /dev/null +++ b/demo-app/src/main/java/com/highcapable/yukireflection/demo_app/test/Main.java @@ -0,0 +1,21 @@ +package com.highcapable.yukireflection.demo_app.test; + +@SuppressWarnings("FieldMayBeFinal") +public class Main { + + private static String staticContent = "I am static!"; + + private final String content; + + public Main(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public static String getStaticContent() { + return staticContent; + } +} \ No newline at end of file diff --git a/demo-app/src/main/java/com/highcapable/yukireflection/demo_app/ui/MainActivity.kt b/demo-app/src/main/java/com/highcapable/yukireflection/demo_app/ui/MainActivity.kt new file mode 100644 index 0000000..e8b7184 --- /dev/null +++ b/demo-app/src/main/java/com/highcapable/yukireflection/demo_app/ui/MainActivity.kt @@ -0,0 +1,75 @@ +/* + * YukiReflection - An efficient Reflection API for the Android platform built in Kotlin. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/fankes/YukiReflection + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This file is Created by fankes on 2023/1/21. + */ +@file:Suppress("SetTextI18n", "UsePropertyAccessSyntax") + +package com.highcapable.yukireflection.demo_app.ui + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.highcapable.yukireflection.demo_app.databinding.ActivityMainBinding +import com.highcapable.yukireflection.demo_app.test.Main +import com.highcapable.yukireflection.factory.* +import com.highcapable.yukireflection.type.java.StringClass + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + ActivityMainBinding.inflate(layoutInflater).apply { + setContentView(root) + testObjectDirectlyButton.setOnClickListener { + tipText.text = Main("I am directly call of new object").getContent() + } + testObjectReflectionButton.setOnClickListener { + tipText.text = + classOf
().buildOf("I am reflection call of new object") { param(StringClass) } + ?.current() + ?.method { + name = "getContent" + emptyParam() + }?.string() ?: "" + } + testStaticDirectlyButton.setOnClickListener { + tipText.text = Main.getStaticContent() + } + testStaticReflectionButton.setOnClickListener { + tipText.text = classOf
().method { + name = "getStaticContent" + modifiers { isStatic } + }.get().string() + } + testModifyStaticReflectionButton.setOnClickListener { + classOf
().field { + name = "staticContent" + modifiers { isStatic } + }.get().set("I am static! Modified by reflection") + tipText.text = "Field is modified success" + } + } + } +} \ No newline at end of file diff --git a/demo-app/src/main/res/layout/activity_main.xml b/demo-app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..69d7595 --- /dev/null +++ b/demo-app/src/main/res/layout/activity_main.xml @@ -0,0 +1,59 @@ + + + + + + + +