-
-
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.
Merge pull request #8 from teogor/feature/raw-operation-annotation
Introduce Fine-grained Control over Generated Operations
- Loading branch information
Showing
19 changed files
with
252 additions
and
48 deletions.
There are no files selected for viewing
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
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
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
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,38 @@ | ||
/* | ||
* Copyright 2024 teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.stitch | ||
|
||
/** | ||
* An annotation for marking DAO methods that should be generated as raw | ||
* operations. | ||
* | ||
* This annotation instructs the Stitch plugin to generate separate operation | ||
* classes for annotated methods in your DAOs. These operation classes provide | ||
* a convenient way to invoke and manage the corresponding database queries | ||
* directly. | ||
* | ||
* @param generate [Boolean] (default: `true`) Whether to generate the operation | ||
* class for this method. | ||
* | ||
* @see Operation | ||
* @see OperationSignature | ||
*/ | ||
@Target(AnnotationTarget.FUNCTION) | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class RawOperation( | ||
val generate: Boolean = true, | ||
) |
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 |
---|---|---|
@@ -1,9 +1,25 @@ | ||
public final class dev/teogor/stitch/api/OperationGenerationLevel : java/lang/Enum { | ||
public static final field ALL Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
public static final field AUTOMATIC Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
public static final field Companion Ldev/teogor/stitch/api/OperationGenerationLevel$Companion; | ||
public static final field DISABLED Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
public static final field EXPLICIT Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
public static fun valueOf (Ljava/lang/String;)Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
public static fun values ()[Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
} | ||
|
||
public final class dev/teogor/stitch/api/OperationGenerationLevel$Companion { | ||
public final fun from (Ljava/lang/String;)Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
} | ||
|
||
public abstract interface class dev/teogor/stitch/api/StitchExtension { | ||
public abstract fun getAddDocumentation ()Z | ||
public abstract fun getGenerateOperations ()Z | ||
public abstract fun getEnableOperationGeneration ()Z | ||
public abstract fun getGeneratedPackageName ()Ljava/lang/String; | ||
public abstract fun getOperationGenerationLevel ()Ldev/teogor/stitch/api/OperationGenerationLevel; | ||
public abstract fun setAddDocumentation (Z)V | ||
public abstract fun setGenerateOperations (Z)V | ||
public abstract fun setEnableOperationGeneration (Z)V | ||
public abstract fun setGeneratedPackageName (Ljava/lang/String;)V | ||
public abstract fun setOperationGenerationLevel (Ldev/teogor/stitch/api/OperationGenerationLevel;)V | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
gradle-plugin-api/src/main/kotlin/dev/teogor/stitch/api/OperationGenerationLevel.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,58 @@ | ||
/* | ||
* Copyright 2024 teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.stitch.api | ||
|
||
/** | ||
* Defines the level of generation for Stitch operation classes. | ||
* | ||
* This enum controls how the plugin generates operation classes from DAO | ||
* methods. | ||
* You can configure the desired level through plugin options or environment | ||
* variables. | ||
* | ||
* @see dev.teogor.stitch.RawOperation | ||
* | ||
* @property ALL Generate operations for all methods in DAOs. | ||
* @property EXPLICIT Generate operations only for methods annotated with | ||
* [dev.teogor.stitch.RawOperation]. | ||
* @property AUTOMATIC Automatically choose whether to generate based on heuristics | ||
* or rules. | ||
* @property DISABLED Do not generate any operation classes, even for annotated | ||
* methods. | ||
*/ | ||
enum class OperationGenerationLevel { | ||
ALL, | ||
EXPLICIT, | ||
AUTOMATIC, | ||
DISABLED, | ||
; | ||
|
||
companion object { | ||
/** | ||
* Converts a string representation to the corresponding [OperationGenerationLevel]. | ||
* | ||
* This function supports case-insensitive matching and throws an exception for invalid input. | ||
* | ||
* @param string The string to convert. | ||
* @return The corresponding [OperationGenerationLevel] or throws an [IllegalArgumentException]. | ||
*/ | ||
fun from(string: String): OperationGenerationLevel { | ||
return values().firstOrNull { it.name.lowercase() == string.lowercase() } | ||
?: throw IllegalArgumentException("Invalid OperationGenerationLevel: $string") | ||
} | ||
} | ||
} |
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
Oops, something went wrong.