Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shalaga44 committed Oct 13, 2024
1 parent 1f9c127 commit 10ae8e7
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 348 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Change Log
==========
## Version 0.1.0

_2024-07-15_
_2024-10-13_

* Initial release
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ configure<MissingAnnotationsTherapistGradleExtension> {
Annotate(
annotationsToAdd = listOf(Annotation(fqName = "kotlin.js.JsExport")),
packageTarget = listOf(PackageTarget(pattern = "com.project.common.dto")),
annotationsTarget = listOf(AnnotationTarget.CLASS),
classTargets = listOf(ClassTypeTarget.REGULAR_CLASS),
sourceSets = listOf("commonMain", "jsMain"),
),
)
Expand Down Expand Up @@ -76,14 +76,14 @@ Configure the plugin in your `build.gradle.kts` file:
```kotlin
import dev.shalaga44.mat.*

configure<MissingAnnotationsTherapistGradleExtension> {
configure<MissingAnnotationsTherapist> {
annotations = listOf(
Annotate(
annotationsToAdd = listOf(Annotation("kotlin.js.JsExport")),
annotationsTarget = listOf(AnnotationTarget.CLASS),
packageTarget = listOf(PackageTarget("com.project.common.dto")),
annotationsToAdd = listOf(Annotation(fqName = "kotlin.js.JsExport")),
classTargets = listOf(ClassTypeTarget.REGULAR_CLASS),
packageTarget = listOf(PackageTarget(pattern = "com.project.common.dto")),
sourceSets = listOf("commonMain", "jsMain"),
),
)
)
}
```
Expand All @@ -95,7 +95,7 @@ kotlinMissingAnnotationsTherapist {
annotations = [
Annotate(
annotationsToAdd = [Annotation("kotlin.js.JsExport")],
annotationsTarget = [AnnotationTarget.CLASS],
classTargets = [ClassTypeTarget.REGULAR_CLASS],
packageTarget = [PackageTarget("com.project.common.dto")],
sourceSets = ["commonMain", "jsMain"]
)
Expand All @@ -110,7 +110,7 @@ using the correct version of this plugin for your version of Kotlin. Check the t

| Kotlin Version | Plugin Version |
|----------------|----------------|
| 2.0.21 | 0.0.1 |
| 2.0.21 | 0.1.0 |
| 2.1.0 | soon |

## Kotlin IR
Expand All @@ -125,7 +125,7 @@ target {
}
```

A working example is will be provided soon
Read the tests for use cases.

A working example is [[available]](https://github.com/shalaga44/missing-annotations-therapist/tree/main/sample) in this repository in the
sample directory.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

allprojects {
group = "io.github.shalaga44"
version = "0.0.2"
version = "0.1.0"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
* limitations under the License.
*/

package dev.shalaga44.mat
package dev.shalaga44.mat.utils

/**
* Represents an annotation to be added.
*
* @property fqName Fully qualified name of the annotation.
* @property parameters Key-value pairs for annotation parameters. Supports dynamic templates.
*/
data class Annotation(
val fqName: String,
val parameters: Map<String, String> = emptyMap(),
) {
val shortName: String = fqName.substringAfterLast(".")
}
Expand All @@ -40,9 +38,7 @@ data class PackageTarget(
val pattern: String,
val matchType: MatchType = MatchType.EXACT,
val regex: String? = null,
) {
val shortName: String = pattern.substringAfterLast(".")
}
)

/**
* Specifies conditions under which annotations should be applied.
Expand Down Expand Up @@ -104,7 +100,7 @@ data class ModuleTarget(
enum class MatchType {
EXACT,
WILDCARD,
REGEX,
REGEX
}

/**
Expand All @@ -114,7 +110,7 @@ enum class Visibility {
PUBLIC,
PRIVATE,
PROTECTED,
INTERNAL,
INTERNAL
}

/**
Expand All @@ -125,34 +121,91 @@ enum class Modifier {
FINAL,
ABSTRACT,
SUSPEND,
PRIVATE,
}

/**
* Defines different types of class targets for annotations.
*/
enum class ClassTypeTarget {
REGULAR_CLASS,
ENUM_CLASS,
SEALED_CLASS,
DATA_CLASS,
OBJECT_CLASS,
ANNOTATION_CLASS,
}

/**
* Defines different function types for annotations.
*/
enum class FunctionTypeTarget {
FUNCTION,
SUSPEND_FUNCTION,
LAMBDA,
CONSTRUCTOR,
}

/**
* Defines different property targets for annotations.
*/
enum class PropertyTypeTarget {
PROPERTY,
FIELD,
LOCAL_VARIABLE,
VALUE_PARAMETER,
GETTER,
SETTER,
}

/**
* Defines type alias targets for annotations.
*/
enum class TypeAliasTarget {
TYPE_ALIAS,
}

/**
* Defines file-level targets for annotations.
*/
enum class FileTarget {
FILE,
}

/**
* Represents an annotation addition rule.
*
* @property annotationsToAdd List of annotations to add.
* @property annotationsTarget List of Kotlin annotation targets (CLASS, FUNCTION, PROPERTY, etc.).
* @property classTargets List of class types to apply annotations to.
* @property functionTargets List of function types to apply annotations to.
* @property propertyTargets List of property types to apply annotations to.
* @property typeAliasTargets List of type alias targets.
* @property fileTargets List of file targets.
* @property packageTarget List of package targets where annotations should be applied.
* @property moduleTarget List of module targets to include or exclude.
* @property sourceSets List of source sets to apply the annotations to.
* @property conditions List of conditions that must be met to apply the annotations.
* @property annotateNestedClasses Should annotate nested classes.
* @property annotateFieldClasses shouldAnnotateFieldClasses.
* @property annotateNestedClasses If true, nested classes will also be annotated.
* @property annotateFieldClasses If true, field-referenced classes will also be annotated.
*/
data class Annotate(
var annotationsToAdd: List<Annotation>,
var annotationsTarget: List<AnnotationTarget> = listOf(),
var classTargets: List<ClassTypeTarget> = listOf(),
var functionTargets: List<FunctionTypeTarget> = listOf(),
var propertyTargets: List<PropertyTypeTarget> = listOf(),
var typeAliasTargets: List<TypeAliasTarget> = listOf(),
var fileTargets: List<FileTarget> = listOf(),
var packageTarget: List<PackageTarget>,
var moduleTarget: List<ModuleTarget> = listOf(),
var sourceSets: List<String> = listOf(),
var conditions: List<Condition> = listOf(),
var annotateNestedClasses: Boolean = true,
var annotateFieldClasses: Boolean = true,
val annotateNestedClasses: Boolean = false,
val annotateFieldClasses: Boolean = false,
)

/**
* Gradle extension for configuring the MissingAnnotationsTherapist compiler plugin.
*/
open class MissingAnnotationsTherapistGradleExtension {
open class MissingAnnotationsTherapist {
var annotations: List<Annotate> = listOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package dev.shalaga44.mat

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import dev.shalaga44.mat.utils.MissingAnnotationsTherapist
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
Expand All @@ -18,16 +19,16 @@ class MissingAnnotationsTherapistGradlePlugin : KotlinCompilerPluginSupportPlugi
const val COMPILER_PLUGIN_ID = "io.github.shalaga44.missing-annotations-therapist"
const val PLUGIN_GROUP_ID = "io.github.shalaga44"
const val PLUGIN_ARTIFACT_ID = "missing-annotations-therapist-plugin"
const val PLUGIN_VERSION = "0.0.2"
const val PLUGIN_VERSION = "0.1.0"
}

override fun apply(target: Project): Unit = with(target) {
extensions.create("kotlinMissingAnnotationsTherapist", MissingAnnotationsTherapistGradleExtension::class.java)
extensions.create("kotlinMissingAnnotationsTherapist", MissingAnnotationsTherapist::class.java)
}

override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
val project = kotlinCompilation.target.project
val extension = project.extensions.findByName("kotlinMissingAnnotationsTherapist") as? MissingAnnotationsTherapistGradleExtension ?: return false
val extension = project.extensions.findByName("kotlinMissingAnnotationsTherapist") as? MissingAnnotationsTherapist ?: return false
val currentSourceSet = kotlinCompilation.defaultSourceSet.name
return extension.annotations.any { it.sourceSets.contains(currentSourceSet) }
}
Expand All @@ -43,7 +44,7 @@ class MissingAnnotationsTherapistGradlePlugin : KotlinCompilerPluginSupportPlugi
override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project
val extension =
project.extensions.findByName("kotlinMissingAnnotationsTherapist") as? MissingAnnotationsTherapistGradleExtension
project.extensions.findByName("kotlinMissingAnnotationsTherapist") as? MissingAnnotationsTherapist
?: return project.provider { emptyList() }

val gson = GsonBuilder()
Expand Down
Loading

0 comments on commit 10ae8e7

Please sign in to comment.