Skip to content

Commit 78fd8f2

Browse files
committed
depend on jitpack version of kotlinpoet and fix generation
1 parent 74226ac commit 78fd8f2

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ repositories {
2323
jcenter()
2424
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
2525
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
26+
maven { url 'https://jitpack.io' }
2627
}
2728

2829
dependencies {
2930
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
3031
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
31-
implementation 'com.squareup:kotlinpoet:1.0.0-RC1'
32+
// implementation 'com.squareup:kotlinpoet:1.0.0-RC1'
33+
implementation 'com.github.emrul:kotlinpoet:42556e2e67'
3234
implementation 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
3335
implementation 'com.google.code.gson:gson:2.8.2'
3436
implementation 'com.beust:jcommander:1.72'

src/main/kotlin/de/rakhman/webextensions/Generator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Generator(val dir: File) {
3333
.addFunction(
3434
FunSpec
3535
.builder("addListener")
36+
.addModifiers(KModifier.EXTERNAL)
3637
.addParameter(
3738
ParameterSpec.builder(
3839
"listener",
@@ -44,6 +45,7 @@ class Generator(val dir: File) {
4445
.addFunction(
4546
FunSpec
4647
.builder("removeListener")
48+
.addModifiers(KModifier.EXTERNAL)
4749
.addParameter(
4850
ParameterSpec.builder(
4951
"listener",
@@ -55,6 +57,7 @@ class Generator(val dir: File) {
5557
.addFunction(
5658
FunSpec
5759
.builder("hasListener")
60+
.addModifiers(KModifier.EXTERNAL)
5861
.addParameter(
5962
ParameterSpec.builder(
6063
"listener",
@@ -181,7 +184,7 @@ class Generator(val dir: File) {
181184
PropertySpec
182185
.varBuilder(it.key, parameterType(it.key, it.value))
183186
.apply { it.value.description?.let { addKdoc(it.cleanupDescription()) } }
184-
.initializer(it.key)
187+
.initializer(it.key.escapeIfKeyword())
185188
.build()
186189
})
187190
.primaryConstructor(FunSpec.constructorBuilder()
@@ -277,7 +280,7 @@ class Generator(val dir: File) {
277280
}
278281

279282
private fun generateFunction(f: Function, parameters: List<Parameter>): FunSpec {
280-
val builder = FunSpec.builder(f.name)
283+
val builder = FunSpec.builder(f.name).addModifiers(KModifier.EXTERNAL)
281284

282285
f.description?.let { builder.addKdoc(it + "\n") }
283286

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package de.rakhman.webextensions
2+
3+
internal fun String.escapeIfKeyword() = if (isKeyword) "`${this}`" else this
4+
5+
internal val String.isKeyword get() = KEYWORDS.contains(this)
6+
7+
// https://github.com/JetBrains/kotlin/blob/master/core/descriptors/src/org/jetbrains/kotlin/renderer/KeywordStringsGenerated.java
8+
private val KEYWORDS = setOf(
9+
"package",
10+
"as",
11+
"typealias",
12+
"class",
13+
"this",
14+
"super",
15+
"val",
16+
"var",
17+
"fun",
18+
"for",
19+
"null",
20+
"true",
21+
"false",
22+
"is",
23+
"in",
24+
"throw",
25+
"return",
26+
"break",
27+
"continue",
28+
"object",
29+
"if",
30+
"try",
31+
"else",
32+
"while",
33+
"do",
34+
"when",
35+
"interface",
36+
"typeof"
37+
)

0 commit comments

Comments
 (0)