feat: lots of changes

- move demo-app to samples and rename demo-android
- rename yukireflection to yukireflection-core
- add demo-jvm in samples
- convert yukireflection-core from android to java-library
- optimize code
- other small changes
This commit is contained in:
2023-09-22 17:00:54 +08:00
parent d02a5f8282
commit 1c205afd37
83 changed files with 337 additions and 96 deletions

1
samples/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

1
samples/demo-android/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

40
samples/demo-android/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,40 @@
# 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
-ignorewarnings
-optimizationpasses 10
-dontusemixedcaseclassnames
-dontoptimize
-verbose
-overloadaggressively
-allowaccessmodification
-adaptclassstrings
-adaptresourcefilenames
-adaptresourcefilecontents
-renamesourcefileattribute P
-keepattributes SourceFile,LineNumberTable
-keep class com.highcapable.yukireflection.demo_app.test.Main {*;}

View File

@@ -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)
}
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Default"
tools:targetApi="31">
<activity
android:name=".ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,48 @@
/*
* YukiReflection - An efficient Reflection API for Java and Android 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 2022/8/7.
*/
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;
}
}

View File

@@ -0,0 +1,81 @@
/*
* YukiReflection - An efficient Reflection API for Java and Android 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.YukiReflection
import com.highcapable.yukireflection.demo_app.databinding.ActivityMainBinding
import com.highcapable.yukireflection.demo_app.test.Main
import com.highcapable.yukireflection.factory.buildOf
import com.highcapable.yukireflection.factory.classOf
import com.highcapable.yukireflection.factory.current
import com.highcapable.yukireflection.factory.field
import com.highcapable.yukireflection.factory.method
import com.highcapable.yukireflection.type.java.StringClass
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ActivityMainBinding.inflate(layoutInflater).apply {
setContentView(root)
yukiReflectionVersionText.text = "YukiReflection Version: ${YukiReflection.API_VERSION_NAME}(${YukiReflection.API_VERSION_CODE})"
testObjectDirectlyButton.setOnClickListener {
tipText.text = Main("I am directly call of new object").getContent()
}
testObjectReflectionButton.setOnClickListener {
tipText.text =
classOf<Main>().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<Main>().method {
name = "getStaticContent"
modifiers { isStatic }
}.get().string()
}
testModifyStaticReflectionButton.setOnClickListener {
classOf<Main>().field {
name = "staticContent"
modifiers { isStatic }
}.get().set("I am static! Modified by reflection")
tipText.text = "Field is modified success"
}
}
}
}

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".ui.MainActivity"
tools:ignore="HardcodedText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Using functions below to test"
android:textSize="18sp" />
<TextView
android:id="@+id/tip_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="35dp"
android:text="Waiting for your operation"
android:textSize="18sp" />
<Button
android:id="@+id/test_object_directly_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Create an Object and Call Directly" />
<Button
android:id="@+id/test_object_reflection_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Create an Object and Call Reflection" />
<Button
android:id="@+id/test_static_directly_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Get Static and Call Directly" />
<Button
android:id="@+id/test_static_reflection_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Get Static and Call Reflection" />
<Button
android:id="@+id/test_modify_static_reflection_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Modified Static Field Using Reflection" />
<TextView
android:id="@+id/yuki_reflection_version_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:alpha="0.55"
android:ellipsize="end"
android:gravity="center|start"
android:singleLine="true"
android:textSize="15sp" />
</LinearLayout>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,19 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Default" parent="Theme.Material3.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/yuki_theme_color</item>
<item name="colorPrimaryVariant">@color/yuki_theme_color</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/yuki_accent_color</item>
<item name="colorSecondaryVariant">@color/yuki_accent_color</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">@color/yuki_dark_color</item>
<item name="android:navigationBarColor">@android:color/background_dark</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<!-- Customize your theme here. -->
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@mipmap/ic_launcher</item>
</style>
</resources>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="yuki_theme_color">#FF31A4FF</color>
<color name="yuki_accent_color">#FF777777</color>
<color name="yuki_light_color">#FFF0F5FF</color>
<color name="yuki_dark_color">#FF2D2726</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#31A4FF</color>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">YukiReflection</string>
</resources>

View File

@@ -0,0 +1,19 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Default" parent="Theme.Material3.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/yuki_theme_color</item>
<item name="colorPrimaryVariant">@color/yuki_theme_color</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/yuki_accent_color</item>
<item name="colorSecondaryVariant">@color/yuki_accent_color</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">@color/yuki_light_color</item>
<item name="android:navigationBarColor">@android:color/background_light</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<!-- Customize your theme here. -->
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@mipmap/ic_launcher</item>
</style>
</resources>

View File

@@ -0,0 +1,17 @@
package com.highcapable.yukireflection
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

1
samples/demo-jvm/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,23 @@
plugins {
autowire(libs.plugins.kotlin.jvm)
autowire(libs.plugins.kotlin.compose)
}
group = property.project.samples.demo.jvm.groupName
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
compose.desktop {
application {
mainClass = "$group.MainKt"
}
}
dependencies {
implementation(projects.yukireflectionCore)
implementation(compose.desktop.currentOs)
implementation(org.jetbrains.compose.material3.material3.desktop)
}

View File

@@ -0,0 +1,142 @@
/*
* YukiReflection - An efficient Reflection API for Java and Android 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/9/22.
*/
@file:Suppress("UsePropertyAccessSyntax")
package com.highcapable.yukireflection.demo_jvm
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import com.highcapable.yukireflection.YukiReflection
import com.highcapable.yukireflection.demo_jvm.test.Main
import com.highcapable.yukireflection.factory.buildOf
import com.highcapable.yukireflection.factory.classOf
import com.highcapable.yukireflection.factory.current
import com.highcapable.yukireflection.factory.field
import com.highcapable.yukireflection.factory.method
import com.highcapable.yukireflection.type.java.StringClass
@Composable
fun MainLayout() {
val currentVersion = "YukiReflection Version: ${YukiReflection.API_VERSION_NAME}(${YukiReflection.API_VERSION_CODE})"
val operationState = remember { mutableStateOf("Waiting for your operation") }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Using functions below to test",
fontSize = 18.sp,
modifier = Modifier.padding(bottom = 15.dp)
)
Text(
text = operationState.value,
fontSize = 18.sp,
modifier = Modifier.padding(bottom = 35.dp)
)
Button(
onClick = { operationState.value = Main("I am directly call of new object").getContent() },
modifier = Modifier.padding(bottom = 15.dp)
) {
Text(text = "Create an Object and Call Directly")
}
Button(
onClick = {
operationState.value =
classOf<Main>().buildOf("I am reflection call of new object") { param(StringClass) }
?.current()
?.method {
name = "getContent"
emptyParam()
}?.string() ?: ""
},
modifier = Modifier.padding(bottom = 15.dp)
) {
Text(text = "Create an Object and Call Reflection")
}
Button(
onClick = { operationState.value = Main.getStaticContent() },
modifier = Modifier.padding(bottom = 15.dp)
) {
Text(text = "Get Static and Call Directly")
}
Button(
onClick = {
operationState.value = classOf<Main>().method {
name = "getStaticContent"
modifiers { isStatic }
}.get().string()
},
modifier = Modifier.padding(bottom = 15.dp)
) {
Text(text = "Get Static and Call Reflection")
}
Button(
onClick = {
classOf<Main>().field {
name = "staticContent"
modifiers { isStatic }
}.get().set("I am static! Modified by reflection")
operationState.value = "Field is modified success"
}
) {
Text(text = "Modified Static Field Using Reflection")
}
Text(
text = currentVersion,
fontSize = 15.sp,
modifier = Modifier.padding(top = 35.dp).alpha(0.55f)
)
}
}
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "YukiReflection",
resizable = false,
state = rememberWindowState(width = 450.dp, height = 600.dp)
) { MaterialTheme(colorScheme = MaterialTheme.colorScheme.copy(primary = Color(0xFF31A4FF.toInt()))) { MainLayout() } }
}

View File

@@ -0,0 +1,48 @@
/*
* YukiReflection - An efficient Reflection API for Java and Android 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 2022/8/7.
*/
package com.highcapable.yukireflection.demo_jvm.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;
}
}