Skip to content

Commit 0234fb1

Browse files
authored
Merge pull request #2 from Toxa2033/fix_release_bugs
Fix generate synth method
2 parents 181ff60 + c8320bb commit 0234fb1

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

compiler-plugin/src/main/kotlin/io/github/toxa2033/saved/state/compiler/extensions/IrGenerationSavedStateExtension.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ import org.jetbrains.kotlin.backend.common.ClassLoweringPass
44
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
55
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
66
import org.jetbrains.kotlin.backend.common.lower
7+
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
78
import org.jetbrains.kotlin.ir.declarations.IrClass
9+
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
810
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
11+
import org.jetbrains.kotlin.ir.symbols.IrSymbol
912

1013
open class IrGenerationSavedStateExtension : IrGenerationExtension {
1114

1215
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
1316
IrGenerationSavedStateExtensionPass(pluginContext).lower(moduleFragment)
1417
}
18+
19+
override fun resolveSymbol(symbol: IrSymbol, context: TranslationPluginContext): IrDeclaration? {
20+
return super.resolveSymbol(symbol, context)
21+
}
1522
}
1623

1724
private class IrGenerationSavedStateExtensionPass(

compiler-plugin/src/main/kotlin/io/github/toxa2033/saved/state/compiler/extensions/SavedStateIrGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class SavedStateIrGenerator(
125125

126126
val valueParam = valueParameters.firstOrNull() ?: error("Not found default value for auto generated get${originalPropertyName}LiveData method")
127127

128-
val typeValueParameter = valueParam.defaultValue?.expression?.type ?: error("Not found default value in get${originalPropertyName}LiveData")
128+
val typeValueParameter = valueParam.symbol.owner.type
129129

130130
val expressionBodyDefaultValue = pluginContext.irFactory.createExpressionBody(startOffset, endOffset) {
131131
expression = IrConstImpl(startOffset, endOffset, typeValueParameter, IrConstKind.Null, null)

compiler-plugin/src/main/kotlin/io/github/toxa2033/saved/state/compiler/extensions/SavedStateResolveExtension.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import org.jetbrains.kotlin.types.KotlinTypeFactory
1818
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
1919
import org.jetbrains.kotlin.types.typeUtil.makeNullable
2020
import io.github.toxa2033.saved.state.compiler.utils.FqNames.SAVE_STATE_ANNOTATION_NAME
21+
import org.jetbrains.kotlin.name.FqName
22+
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
2123
import java.util.concurrent.ConcurrentLinkedDeque
2224

2325
open class SavedStateResolveExtension : SyntheticResolveExtension {
@@ -40,7 +42,10 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
4042
fromSupertypes: List<SimpleFunctionDescriptor>,
4143
result: MutableCollection<SimpleFunctionDescriptor>
4244
) {
43-
val propertyDescriptionData = listPropertyDescriptionData.find { name in it.creations } ?: return
45+
val propertyDescriptionData = listPropertyDescriptionData.find {
46+
it.classDescriptorFqName == thisDescriptor.fqNameSafe
47+
} ?: return
48+
if (name !in propertyDescriptionData.creations) return
4449
println("FUNCTION CREATED - $name" +
4550
"\nClass - ${thisDescriptor.name}" +
4651
" list method ${listPropertyDescriptionData.map { it.creations }}"
@@ -80,7 +85,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
8085
Name.identifier("$GET$fieldName$VALUE"),
8186
Name.identifier("$GET_IDENTIFIER_START$fieldName")
8287
)
83-
listPropertyDescriptionData.add(PropertyDescriptionData(listMethod, property))
88+
listPropertyDescriptionData.add(PropertyDescriptionData(listMethod, property, thisDescriptor.fqNameSafe))
8489
propertyNames.add(Name.identifier("${property.name.asString()}$IDENTIFIER".uppercase()))
8590
listMethod
8691
}
@@ -120,7 +125,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
120125
emptyList(),
121126
thisClassDescriptor.builtIns.stringType,
122127
Modality.FINAL,
123-
DescriptorVisibilities.PRIVATE
128+
DescriptorVisibilities.PROTECTED
124129
)
125130
}
126131
}
@@ -167,7 +172,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
167172
listOfNotNull(argument),
168173
type,
169174
Modality.FINAL,
170-
DescriptorVisibilities.PRIVATE
175+
DescriptorVisibilities.PROTECTED
171176
)
172177
}
173178
}
@@ -208,7 +213,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
208213
listOf(argument),
209214
thisClassDescriptor.builtIns.unitType,
210215
Modality.FINAL,
211-
DescriptorVisibilities.PRIVATE
216+
DescriptorVisibilities.PROTECTED
212217
)
213218
}
214219
}
@@ -243,5 +248,6 @@ private val ClassDescriptor.mutableLifecycleClassDescriptor: ClassDescriptor
243248

244249
data class PropertyDescriptionData(
245250
val creations: List<Name>,
246-
val property: PropertyDescriptor
251+
val property: PropertyDescriptor,
252+
val classDescriptorFqName: FqName
247253
)

idea-plugin/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ intellij {
2323
}
2424

2525
patchPluginXml {
26-
sinceBuild = "191.0"
26+
sinceBuild = "203.*"
2727
untilBuild = "212.*"
28-
version = System.getenv('RELEASE_VERSION') ?: "1.0.0"
28+
version = System.getenv('RELEASE_VERSION') ?: "1.0.5"
29+
changeNotes="Fix several bugs"
2930
}
3031

3132
publishPlugin {
3233
token = System.getenv("IDEA_PUBLISH_TOKEN")
3334
}
3435

3536
runIde {
36-
37+
ideDir = file('/Applications/Android Studio.app/Contents')
3738
}

idea-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<idea-plugin>
22
<id>io.github.toxa2033.saved.state.plugin.idea</id>
3-
<name>Saved State IDEA</name>
3+
<name>SavedStateHandle Kotlin Compiler</name>
44
<vendor email="[email protected]">Toxa2033</vendor>
55

66
<description><![CDATA[
7-
Kotlin compiler plugin generates support methods for use SaveStateHandle without constants and string variables.<br>
8-
<a href="https://github.com/Toxa2033/SavedStateCompilerPlugin">Visit on Github</a>
7+
This plugin adds support to intellij idea kotlin compiler plugin for generating SavedStateHandle helper methods.<br>
8+
<a href="https://github.com/Toxa2033/SavedStateCompilerPlugin">Visit on Github for more information</a>
99
]]></description>
1010

1111
<depends>org.jetbrains.kotlin</depends>

0 commit comments

Comments
 (0)