-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Optimized the logic for adding modules and commands in the project. - Integrated Kotlin to enhance code readability and maintainability. - Reduced boilerplate code and improved expressiveness in the codebase.
- Loading branch information
1 parent
63da778
commit b5ad781
Showing
82 changed files
with
412 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
plugins { | ||
kotlin("jvm") | ||
id("com.google.devtools.ksp") | ||
} | ||
|
||
group = "com.github.shu" | ||
version = "0.0.1" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("com.google.devtools.ksp:symbol-processing-api:2.0.21-1.0.25") | ||
} |
46 changes: 46 additions & 0 deletions
46
processor/src/main/kotlin/com/github/shu/AutoRegisterProcessor.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,46 @@ | ||
package com.github.shu | ||
|
||
import com.google.devtools.ksp.getConstructors | ||
import com.google.devtools.ksp.processing.* | ||
import com.google.devtools.ksp.symbol.KSAnnotated | ||
import com.google.devtools.ksp.symbol.KSClassDeclaration | ||
|
||
/** | ||
* A KSP (Kotlin Symbol Processing) processor that processes class annotated with `@AutoRegister`. | ||
* This processor checks if the annotated classes have a no-argument constructor or if all their | ||
* constructor parameters hava default values. If neither condition is met, an error is logged. | ||
* | ||
* @param logger The KSP logger used for logging errors during processing. | ||
*/ | ||
class AutoRegisterProcessor(private val logger: KSPLogger) : SymbolProcessor { | ||
|
||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
val autoRegisterClasses = resolver.getSymbolsWithAnnotation("anticope.rejects.annotation.AutoRegister") | ||
autoRegisterClasses.forEach { classSymbol -> | ||
if (classSymbol is KSClassDeclaration) { | ||
validateClass(classSymbol) | ||
} | ||
} | ||
return emptyList() | ||
} | ||
|
||
private fun validateClass(classSymbol: KSClassDeclaration) { | ||
val constructors = classSymbol.getConstructors() | ||
val hasDefaultConstructor = constructors.any { constructor -> | ||
constructor.parameters.isEmpty() || constructor.parameters.all { it.hasDefault } | ||
} | ||
if (!hasDefaultConstructor) { | ||
val message = | ||
"${classSymbol.simpleName.asString()} must have a no-arg constructor or " + | ||
"all parameters must have default values" | ||
logger.error(message) | ||
} | ||
} | ||
} | ||
|
||
class AutoRegisterProcessorProvider : SymbolProcessorProvider { | ||
|
||
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { | ||
return AutoRegisterProcessor(environment.logger) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider
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 @@ | ||
com.github.shu.AutoRegisterProcessorProvider |
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 |
---|---|---|
|
@@ -4,5 +4,7 @@ pluginManagement { | |
name = "Fabric" | ||
} | ||
gradlePluginPortal() | ||
google() | ||
} | ||
} | ||
include("processor") |
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
2 changes: 2 additions & 0 deletions
2
src/main/java/anticope/rejects/commands/ClearChatCommand.java
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
Oops, something went wrong.