-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FormatLanguage annotation to JSON (#2234)
Resolves #2166 Co-authored-by: Leonid Startsev <sandwwraith@gmail.com>
- Loading branch information
1 parent
40eb277
commit 5a8795a
Showing
7 changed files
with
157 additions
and
2 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
45 changes: 45 additions & 0 deletions
45
formats/json/commonMain/src/kotlinx/serialization/json/internal/FormatLanguage.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,45 @@ | ||
package kotlinx.serialization.json.internal; | ||
|
||
import kotlinx.serialization.InternalSerializationApi | ||
|
||
/** | ||
* Multiplatform analogue of `org.intellij.lang.annotations.Language` annotation. | ||
* | ||
* An alias is used instead of class, because the actual class in the JVM will conflict with the class from the stdlib - | ||
* we want to avoid the situation with different classes having the same fully-qualified name. | ||
* [see](https://github.com/JetBrains/java-annotations/issues/34) | ||
* | ||
* Specifies that an element of the program represents a string that is a source code on a specified language. | ||
* Code editors may use this annotation to enable syntax highlighting, code completion and other features | ||
* inside the literals that assigned to the annotated variables, passed as arguments to the annotated parameters, | ||
* or returned from the annotated methods. | ||
* <p> | ||
* This annotation also could be used as a meta-annotation, to define derived annotations for convenience. | ||
* E.g. the following annotation could be defined to annotate the strings that represent Java methods: | ||
* | ||
* <pre> | ||
* @Language(value = "JAVA", prefix = "class X{", suffix = "}") | ||
* @interface JavaMethod {} | ||
* </pre> | ||
* <p> | ||
* Note that using the derived annotation as meta-annotation is not supported. | ||
* Meta-annotation works only one level deep. | ||
*/ | ||
|
||
@InternalSerializationApi | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.PROPERTY_GETTER, | ||
AnnotationTarget.PROPERTY_SETTER, | ||
AnnotationTarget.FIELD, | ||
AnnotationTarget.VALUE_PARAMETER, | ||
AnnotationTarget.LOCAL_VARIABLE, | ||
AnnotationTarget.ANNOTATION_CLASS | ||
) | ||
public expect annotation class FormatLanguage( | ||
public val value: String, | ||
// default parameters are not used due to https://youtrack.jetbrains.com/issue/KT-25946/ | ||
public val prefix: String, | ||
public val suffix: String, | ||
) |
10 changes: 10 additions & 0 deletions
10
formats/json/jsMain/src/kotlinx/serialization/json/internal/FormatLanguage.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,10 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.serialization.json.internal; | ||
|
||
import kotlinx.serialization.InternalSerializationApi | ||
|
||
@InternalSerializationApi | ||
public actual typealias FormatLanguage = org.intellij.lang.annotations.Language |
35 changes: 35 additions & 0 deletions
35
formats/json/jsMain/src/kotlinx/serialization/json/internal/IntelliJAnnotation.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,35 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
@file:Suppress("PackageDirectoryMismatch") | ||
|
||
package org.intellij.lang.annotations | ||
|
||
import kotlinx.serialization.InternalSerializationApi | ||
|
||
/** | ||
* JS implementation of JVM-only `org.intellij.lang.annotations.Language` class, adds syntax support by IDE. | ||
* | ||
* This class is missing from the Kotlin/JS targets, so it needs to be distributed along with the serialization runtime. | ||
* | ||
* Copy-paste from [https://github.com/JetBrains/java-annotations](https://github.com/JetBrains/java-annotations). | ||
* | ||
* @see [kotlinx.serialization.json.internal.FormatLanguage] | ||
*/ | ||
@InternalSerializationApi | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.PROPERTY_GETTER, | ||
AnnotationTarget.PROPERTY_SETTER, | ||
AnnotationTarget.FIELD, | ||
AnnotationTarget.VALUE_PARAMETER, | ||
AnnotationTarget.LOCAL_VARIABLE, | ||
AnnotationTarget.ANNOTATION_CLASS, | ||
) | ||
public annotation class Language( | ||
val value: String, | ||
val prefix: String = "", | ||
val suffix: String = "", | ||
) |
10 changes: 10 additions & 0 deletions
10
formats/json/jvmMain/src/kotlinx/serialization/json/internal/FormatLanguage.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,10 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.serialization.json.internal; | ||
|
||
import kotlinx.serialization.InternalSerializationApi | ||
|
||
@InternalSerializationApi | ||
public actual typealias FormatLanguage = org.intellij.lang.annotations.Language |
10 changes: 10 additions & 0 deletions
10
formats/json/nativeMain/src/kotlinx/serialization/json/internal/FormatLanguage.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,10 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.serialization.json.internal; | ||
|
||
import kotlinx.serialization.InternalSerializationApi | ||
|
||
@InternalSerializationApi | ||
public actual typealias FormatLanguage = org.intellij.lang.annotations.Language |
35 changes: 35 additions & 0 deletions
35
formats/json/nativeMain/src/kotlinx/serialization/json/internal/IntelliJAnnotation.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,35 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
@file:Suppress("PackageDirectoryMismatch") | ||
|
||
package org.intellij.lang.annotations | ||
|
||
import kotlinx.serialization.InternalSerializationApi | ||
|
||
/** | ||
* Native implementation of JVM-only `org.intellij.lang.annotations.Language` class, adds syntax support by IDE. | ||
* | ||
* This class is missing from the Kotlin/Native targets, so it needs to be distributed along with the serialization runtime. | ||
* | ||
* Copy-paste from [https://github.com/JetBrains/java-annotations](https://github.com/JetBrains/java-annotations). | ||
* | ||
* @see [kotlinx.serialization.json.internal.FormatLanguage] | ||
*/ | ||
@InternalSerializationApi | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.PROPERTY_GETTER, | ||
AnnotationTarget.PROPERTY_SETTER, | ||
AnnotationTarget.FIELD, | ||
AnnotationTarget.VALUE_PARAMETER, | ||
AnnotationTarget.LOCAL_VARIABLE, | ||
AnnotationTarget.ANNOTATION_CLASS, | ||
) | ||
public annotation class Language( | ||
val value: String, | ||
val prefix: String = "", | ||
val suffix: String = "", | ||
) |