-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
38 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/org/levi/coffee/annotations/BindAllMethods.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.levi.coffee.annotations | ||
|
||
/** | ||
* Use on a class instead of @BindMethod on all functions separately. | ||
*/ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.CLASS) | ||
annotation class BindAllMethods |
10 changes: 0 additions & 10 deletions
10
src/main/kotlin/org/levi/coffee/annotations/BindMethod.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.levi.coffee.annotations | ||
|
||
/** | ||
* Specify to bind a certain function to the frontend. | ||
*/ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target( | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.PROPERTY_GETTER, | ||
AnnotationTarget.PROPERTY_SETTER | ||
) | ||
annotation class BindMethod |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.levi.coffee.annotations | ||
|
||
/** | ||
* Specify a class to convert to a typescript type on the frontend. | ||
*/ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.CLASS) | ||
annotation class BindType( | ||
/** | ||
* Specifies which fields to pick for the typescript type. | ||
* If empty of not provided at all, it will be ignored. | ||
* If provided, will override the exclude tag. | ||
* @return the exclusively included fields' names. | ||
*/ | ||
val only: Array<String> = [], | ||
/** | ||
* Specifies which fields to ignore when building the typescript type. | ||
* If empty or not provided, the type will include all fields. | ||
* @return the ignored fields' names | ||
*/ | ||
val ignore: Array<String> = [], // TODO: optionally, ignore some fields. | ||
) |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/org/levi/coffee/annotations/IgnoreMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.levi.coffee.annotations | ||
|
||
/** | ||
* When using @BindAllMethods on a class, use @IgnoreMethod to mark methods | ||
* to be ignored and not bind to the frontend. | ||
*/ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target( | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.PROPERTY_GETTER, | ||
AnnotationTarget.PROPERTY_SETTER | ||
) | ||
annotation class IgnoreMethod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.levi.coffee.internal | ||
|
||
import org.levi.coffee.annotations.BindAllMethods | ||
import org.levi.coffee.annotations.BindMethod | ||
import org.levi.coffee.annotations.BindType | ||
import org.levi.coffee.annotations.IgnoreMethod | ||
import java.lang.reflect.Field | ||
import java.lang.reflect.Method | ||
|
||
object BindFilter { | ||
fun methodsOf(c: Class<*>): List<Method> { | ||
if (c.isAnnotationPresent(BindAllMethods::class.java)) { | ||
return c.declaredMethods.filter { !it.isAnnotationPresent(IgnoreMethod::class.java) } | ||
} | ||
return c.declaredMethods.filter { it.isAnnotationPresent(BindMethod::class.java) } | ||
} | ||
|
||
fun fieldsOf(c: Class<*>): List<Field> { | ||
// Assuming "@BindType()" present on class "c" | ||
|
||
val annotation = c.getAnnotation(BindType::class.java) | ||
if (annotation.only.isNotEmpty()) { | ||
return c.declaredFields.filter { annotation.only.contains(it.name) } | ||
} | ||
return c.declaredFields.filter { !annotation.ignore.contains(it.name) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters