-
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
16 changed files
with
421 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public final class org/erwinkok/kik/compiler/KikCommandLineProcessor : org/jetbrains/kotlin/compiler/plugin/CommandLineProcessor { | ||
public fun <init> ()V | ||
public fun getPluginId ()Ljava/lang/String; | ||
public synthetic fun getPluginOptions ()Ljava/util/Collection; | ||
public fun getPluginOptions ()Ljava/util/List; | ||
public fun processOption (Lorg/jetbrains/kotlin/compiler/plugin/AbstractCliOption;Ljava/lang/String;Lorg/jetbrains/kotlin/config/CompilerConfiguration;)V | ||
} | ||
|
||
public final class org/erwinkok/kik/compiler/SerializationComponentRegistrar : org/jetbrains/kotlin/compiler/plugin/CompilerPluginRegistrar { | ||
public fun <init> ()V | ||
public fun getSupportsK2 ()Z | ||
public fun registerExtensions (Lorg/jetbrains/kotlin/compiler/plugin/CompilerPluginRegistrar$ExtensionStorage;Lorg/jetbrains/kotlin/config/CompilerConfiguration;)V | ||
} | ||
|
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
21 changes: 21 additions & 0 deletions
21
kik-compiler-plugin/src/main/kotlin/org/erwinkok/kik/compiler/k2/FirClassSymbolUtils.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,21 @@ | ||
// Copyright (c) 2024. Erwin Kok. Apache License. See LICENSE file for more details. | ||
package org.erwinkok.kik.compiler.k2 | ||
|
||
import org.erwinkok.kik.compiler.resolve.KikAnnotations | ||
import org.jetbrains.kotlin.fir.FirSession | ||
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId | ||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation | ||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol | ||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol | ||
|
||
internal fun FirClassSymbol<*>.hasKikAnnotation(session: FirSession): Boolean { | ||
return serializableAnnotationWithoutArgs(session) != null | ||
} | ||
|
||
internal fun FirBasedSymbol<*>.serializableAnnotationWithoutArgs(session: FirSession): FirAnnotation? { | ||
return resolvedCompilerAnnotationsWithClassIds.serializableAnnotation(session) | ||
} | ||
|
||
internal fun List<FirAnnotation>.serializableAnnotation(session: FirSession): FirAnnotation? { | ||
return getAnnotationByClassId(KikAnnotations.kikTypeAnnotationClassId, session) | ||
} |
11 changes: 11 additions & 0 deletions
11
kik-compiler-plugin/src/main/kotlin/org/erwinkok/kik/compiler/k2/FirKikExtensionRegistrar.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,11 @@ | ||
// Copyright (c) 2024. Erwin Kok. Apache License. See LICENSE file for more details. | ||
package org.erwinkok.kik.compiler.k2 | ||
|
||
import org.erwinkok.kik.compiler.k2.checkers.FirKikCheckersComponent | ||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar | ||
|
||
internal class FirKikExtensionRegistrar : FirExtensionRegistrar() { | ||
override fun ExtensionRegistrarContext.configurePlugin() { | ||
+::FirKikCheckersComponent | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...r-plugin/src/main/kotlin/org/erwinkok/kik/compiler/k2/checkers/FirKikCheckersComponent.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,11 @@ | ||
package org.erwinkok.kik.compiler.k2.checkers | ||
|
||
import org.jetbrains.kotlin.fir.FirSession | ||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.DeclarationCheckers | ||
import org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension | ||
|
||
internal class FirKikCheckersComponent(session: FirSession) : FirAdditionalCheckersExtension(session) { | ||
override val declarationCheckers = object : DeclarationCheckers() { | ||
override val classCheckers = setOf(FirKikPluginClassChecker) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
kik-compiler-plugin/src/main/kotlin/org/erwinkok/kik/compiler/k2/checkers/FirKikErrors.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,48 @@ | ||
// Copyright (c) 2024. Erwin Kok. Apache License. See LICENSE file for more details. | ||
package org.erwinkok.kik.compiler.k2.checkers | ||
|
||
import org.jetbrains.kotlin.com.intellij.psi.PsiElement | ||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap | ||
import org.jetbrains.kotlin.diagnostics.error0 | ||
import org.jetbrains.kotlin.diagnostics.error1 | ||
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory | ||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers | ||
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory | ||
import org.jetbrains.kotlin.psi.KtAnnotationEntry | ||
|
||
internal object FirKikErrors : BaseDiagnosticRendererFactory() { | ||
val SUPERCLASS_NOT_SUPPORTED by error1<KtAnnotationEntry, String>() | ||
val OBJECTS_NOT_SUPPORTED by error0<PsiElement>() | ||
val ANONYMOUS_OBJECTS_NOT_SUPPORTED by error0<PsiElement>() | ||
val INNER_CLASSES_NOT_SUPPORTED by error0<PsiElement>() | ||
val TYPE_PARAMETERS_NOT_SUPPORTED by error1<KtAnnotationEntry, String>() | ||
|
||
override val MAP = KtDiagnosticFactoryToRendererMap("KikTypeSystem").apply { | ||
put( | ||
SUPERCLASS_NOT_SUPPORTED, | ||
"Class tagged with @KikType has one or more super classes/interfaces ''{0}'', which is not supported", | ||
CommonRenderers.STRING | ||
) | ||
put( | ||
OBJECTS_NOT_SUPPORTED, | ||
"Objects can not be annotated with @KikType." | ||
) | ||
put( | ||
ANONYMOUS_OBJECTS_NOT_SUPPORTED, | ||
"Anonymous classes or contained in its classes can not be annotation with @KikType." | ||
) | ||
put( | ||
INNER_CLASSES_NOT_SUPPORTED, | ||
"Inner (with reference to outer this) classes cannot be annotated with @KikType. Remove 'inner' keyword." | ||
) | ||
put( | ||
TYPE_PARAMETERS_NOT_SUPPORTED, | ||
"Class annotated with @KikType has one or more type parameters ''{0}'', which is not supported", | ||
CommonRenderers.STRING | ||
) | ||
} | ||
|
||
init { | ||
RootDiagnosticRendererFactory.registerFactory(this) | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...-plugin/src/main/kotlin/org/erwinkok/kik/compiler/k2/checkers/FirKikPluginClassChecker.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,89 @@ | ||
// Copyright (c) 2024. Erwin Kok. Apache License. See LICENSE file for more details. | ||
package org.erwinkok.kik.compiler.k2.checkers | ||
|
||
import org.erwinkok.kik.compiler.k2.hasKikAnnotation | ||
import org.jetbrains.kotlin.descriptors.isObject | ||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter | ||
import org.jetbrains.kotlin.diagnostics.reportOn | ||
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind | ||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext | ||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirClassChecker | ||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject | ||
import org.jetbrains.kotlin.fir.declarations.FirClass | ||
import org.jetbrains.kotlin.fir.declarations.utils.isInner | ||
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol | ||
import org.jetbrains.kotlin.fir.types.classId | ||
import org.jetbrains.kotlin.name.StandardClassIds | ||
|
||
internal object FirKikPluginClassChecker : FirClassChecker(MppCheckerKind.Common) { | ||
override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) { | ||
if (!declaration.symbol.hasKikAnnotation(context.session)) { | ||
return | ||
} | ||
val checkers = listOf( | ||
::checkSuperClass, | ||
::checkObject, | ||
::checkAnonymousClass, | ||
::checkInnerClass, | ||
::checkTypeParameters, | ||
) | ||
checkers.forEach { checker -> | ||
if (checker(declaration, context, reporter)) { | ||
return | ||
} | ||
} | ||
} | ||
|
||
private fun checkSuperClass(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter): Boolean { | ||
val classSymbol = declaration.symbol | ||
val superClasses = classSymbol.resolvedSuperTypes | ||
.mapNotNull { | ||
it.classId | ||
} | ||
.filter { | ||
it != StandardClassIds.Any && it != StandardClassIds.Enum | ||
} | ||
if (superClasses.isNotEmpty()) { | ||
val identifiers = superClasses.joinToString(", ") { it.asFqNameString() } | ||
reporter.reportOn(classSymbol.source, FirKikErrors.SUPERCLASS_NOT_SUPPORTED, identifiers, context) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
private fun checkObject(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter): Boolean { | ||
val classSymbol = declaration.symbol | ||
if (classSymbol.classKind.isObject) { | ||
reporter.reportOn(declaration.source, FirKikErrors.OBJECTS_NOT_SUPPORTED, context) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
private fun checkAnonymousClass(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter): Boolean { | ||
val classSymbol = declaration.symbol | ||
if (classSymbol is FirAnonymousObjectSymbol || context.containingDeclarations.any { it is FirAnonymousObject }) { | ||
reporter.reportOn(declaration.source, FirKikErrors.ANONYMOUS_OBJECTS_NOT_SUPPORTED, context) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
private fun checkInnerClass(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter): Boolean { | ||
val classSymbol = declaration.symbol | ||
if (classSymbol.isInner) { | ||
reporter.reportOn(declaration.source, FirKikErrors.INNER_CLASSES_NOT_SUPPORTED, context) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
private fun checkTypeParameters(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter): Boolean { | ||
if (declaration.typeParameters.isNotEmpty()) { | ||
val identifiers = declaration.typeParameters.joinToString(", ") { it.symbol.name.identifier } | ||
reporter.reportOn(declaration.source, FirKikErrors.TYPE_PARAMETERS_NOT_SUPPORTED, identifiers, context) | ||
return true | ||
} | ||
return false | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
kik-compiler-plugin/src/main/kotlin/org/erwinkok/kik/compiler/resolve/NamingConventions.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,17 @@ | ||
// Copyright (c) 2024. Erwin Kok. Apache License. See LICENSE file for more details. | ||
package org.erwinkok.kik.compiler.resolve | ||
|
||
import org.jetbrains.kotlin.name.ClassId | ||
import org.jetbrains.kotlin.name.FqName | ||
|
||
internal object KikAnnotations { | ||
val kikTypeAnnotationFqName = FqName("org.erwinkok.kik.typesystem.KikType") | ||
val kikTypePartAnnotationFqName = FqName("org.erwinkok.kik.typesystem.KikTypePart") | ||
val kikPropertyAnnotationFqName = FqName("org.erwinkok.kik.typesystem.KikProperty") | ||
val kikInlineAnnotationFqName = FqName("org.erwinkok.kik.typesystem.KikInline") | ||
|
||
val kikTypeAnnotationClassId = ClassId.topLevel(kikTypeAnnotationFqName) | ||
val kikTypePartAnnotationClassId = ClassId.topLevel(kikTypePartAnnotationFqName) | ||
val kikPropertyAnnotationClassId = ClassId.topLevel(kikPropertyAnnotationFqName) | ||
val kikInlineAnnotationClassId = ClassId.topLevel(kikInlineAnnotationFqName) | ||
} |
Oops, something went wrong.