Skip to content

Commit

Permalink
Merge pull request #2 from Toxa2033/fix_release_bugs
Browse files Browse the repository at this point in the history
Fix generate synth method
  • Loading branch information
Toxa2033 committed Jun 8, 2022
2 parents 181ff60 + c8320bb commit 0234fb1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import org.jetbrains.kotlin.backend.common.ClassLoweringPass
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.lower
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.symbols.IrSymbol

open class IrGenerationSavedStateExtension : IrGenerationExtension {

override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
IrGenerationSavedStateExtensionPass(pluginContext).lower(moduleFragment)
}

override fun resolveSymbol(symbol: IrSymbol, context: TranslationPluginContext): IrDeclaration? {
return super.resolveSymbol(symbol, context)
}
}

private class IrGenerationSavedStateExtensionPass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SavedStateIrGenerator(

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

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

val expressionBodyDefaultValue = pluginContext.irFactory.createExpressionBody(startOffset, endOffset) {
expression = IrConstImpl(startOffset, endOffset, typeValueParameter, IrConstKind.Null, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import io.github.toxa2033.saved.state.compiler.utils.FqNames.SAVE_STATE_ANNOTATION_NAME
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import java.util.concurrent.ConcurrentLinkedDeque

open class SavedStateResolveExtension : SyntheticResolveExtension {
Expand All @@ -40,7 +42,10 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
fromSupertypes: List<SimpleFunctionDescriptor>,
result: MutableCollection<SimpleFunctionDescriptor>
) {
val propertyDescriptionData = listPropertyDescriptionData.find { name in it.creations } ?: return
val propertyDescriptionData = listPropertyDescriptionData.find {
it.classDescriptorFqName == thisDescriptor.fqNameSafe
} ?: return
if (name !in propertyDescriptionData.creations) return
println("FUNCTION CREATED - $name" +
"\nClass - ${thisDescriptor.name}" +
" list method ${listPropertyDescriptionData.map { it.creations }}"
Expand Down Expand Up @@ -80,7 +85,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
Name.identifier("$GET$fieldName$VALUE"),
Name.identifier("$GET_IDENTIFIER_START$fieldName")
)
listPropertyDescriptionData.add(PropertyDescriptionData(listMethod, property))
listPropertyDescriptionData.add(PropertyDescriptionData(listMethod, property, thisDescriptor.fqNameSafe))
propertyNames.add(Name.identifier("${property.name.asString()}$IDENTIFIER".uppercase()))
listMethod
}
Expand Down Expand Up @@ -120,7 +125,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
emptyList(),
thisClassDescriptor.builtIns.stringType,
Modality.FINAL,
DescriptorVisibilities.PRIVATE
DescriptorVisibilities.PROTECTED
)
}
}
Expand Down Expand Up @@ -167,7 +172,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
listOfNotNull(argument),
type,
Modality.FINAL,
DescriptorVisibilities.PRIVATE
DescriptorVisibilities.PROTECTED
)
}
}
Expand Down Expand Up @@ -208,7 +213,7 @@ open class SavedStateResolveExtension : SyntheticResolveExtension {
listOf(argument),
thisClassDescriptor.builtIns.unitType,
Modality.FINAL,
DescriptorVisibilities.PRIVATE
DescriptorVisibilities.PROTECTED
)
}
}
Expand Down Expand Up @@ -243,5 +248,6 @@ private val ClassDescriptor.mutableLifecycleClassDescriptor: ClassDescriptor

data class PropertyDescriptionData(
val creations: List<Name>,
val property: PropertyDescriptor
val property: PropertyDescriptor,
val classDescriptorFqName: FqName
)
7 changes: 4 additions & 3 deletions idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ intellij {
}

patchPluginXml {
sinceBuild = "191.0"
sinceBuild = "203.*"
untilBuild = "212.*"
version = System.getenv('RELEASE_VERSION') ?: "1.0.0"
version = System.getenv('RELEASE_VERSION') ?: "1.0.5"
changeNotes="Fix several bugs"
}

publishPlugin {
token = System.getenv("IDEA_PUBLISH_TOKEN")
}

runIde {

ideDir = file('/Applications/Android Studio.app/Contents')
}
6 changes: 3 additions & 3 deletions idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<idea-plugin>
<id>io.github.toxa2033.saved.state.plugin.idea</id>
<name>Saved State IDEA</name>
<name>SavedStateHandle Kotlin Compiler</name>
<vendor email="95toxa95@gmail.com">Toxa2033</vendor>

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

<depends>org.jetbrains.kotlin</depends>
Expand Down

0 comments on commit 0234fb1

Please sign in to comment.