Git Product home page Git Product logo

android-parcelable-intellij-plugin-kotlin's Introduction

Android Parcelable boilerplate code generation

Inspired by android-parcelable-intellij-plugin

Installation

Plugin is uploaded to plugin repository. If you like, you can also install it manually:

  1. Download ParcelableGenerator release
  2. Open IntelliJ/Android Studio
  3. Preferences -> Plugins -> Install plugin from disk....
  4. Choose the downloaded jar file

Dependencies

It depends on the latest version of Kotlin plugin.

Usage

Just press ALT + Insert (or your equivalent keybinding for code generation) in your editor and select Parcelable. It will auto generate Parcelable boilerplate code for your class.

Now Suported Types

  • Types implementing Parceable or Serializable
  • List of Parcelable objects
  • Array of Parcelable objects
  • Primitive Kotlin types: String, Byte, Double, Float, Int, Long, Boolean, Char
  • Kotlin Array types: Array<String>, ByteArray, DoubleArray, FloatArray, IntArray, LongArray, CharArray, BooleanArray
  • List of any objects (Warning: validation is not performed)
  • Enum type

License

Copyright (C) 2016 Nekocode (https://github.com/nekocode)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-parcelable-intellij-plugin-kotlin's People

Contributors

londospark avatar nekocode avatar xorsk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-parcelable-intellij-plugin-kotlin's Issues

Plugin works only with default constructor vars

For some reason your plugin takes into account only vars that are declared in the default constructor and doesn't see any outstanding vars. IMO it's a bug, since some attributes are not supposed to be a part of the constructor, but are supposed to be preserved through Parcelable.

Plagiarism ?

Hello @nekocode and @xorsk
I'm just accidentally browse some kotlin plugin through android studio and found that this man also re-publish your plugin with the same name with yours Parcelable Code Generator Hope this information helps both of you.

Exception

Hi, I just want to report this crash:

Kotlin 1.0.3
IntelliJ IDEA 2016.2 EAP
Build #IU-162.1120.6, built on June 28, 2016
JRE: 1.8.0_76-release-b216 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

null
java.lang.AssertionError
    at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.getPsiClassFromEvent(ParcelableAction.java:76)
    at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.update(ParcelableAction.java:69)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:123)
    at com.intellij.ide.util.gotoByName.GotoActionModel.updateActionBeforeShow(GotoActionModel.java:261)
    at com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper.getPresentation(GotoActionModel.java:466)
    at com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper.isAvailable(GotoActionModel.java:461)
    at com.intellij.ide.util.gotoByName.GotoActionModel$MatchedValue.compareTo(GotoActionModel.java:195)
    at com.intellij.ide.util.gotoByName.GotoActionModel.compare(GotoActionModel.java:255)
    at java.util.TreeMap.put(TreeMap.java:552)
    at java.util.TreeSet.add(TreeSet.java:255)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
    at java.util.TreeSet.addAll(TreeSet.java:312)
    at com.intellij.ide.util.gotoByName.GotoActionModel.sort(GotoActionModel.java:397)
    at com.intellij.ide.actions.GotoActionAction$2.filter(GotoActionAction.java:132)
    at com.intellij.ide.util.gotoByName.ChooseByNameBase$CalcElementsThread.a(ChooseByNameBase.java:1537)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils$4.a(ProgressIndicatorUtils.java:185)
    at com.intellij.openapi.application.TransactionGuardImpl$6.run(TransactionGuardImpl.java:291)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:326)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:310)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:863)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:699)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:385)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


java.lang.AssertionError
    at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.getPsiClassFromEvent(ParcelableAction.java:76)
    at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.update(ParcelableAction.java:69)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:123)
    at com.intellij.ide.util.gotoByName.GotoActionModel.updateActionBeforeShow(GotoActionModel.java:261)
    at com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper.getPresentation(GotoActionModel.java:466)
    at com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper.isAvailable(GotoActionModel.java:461)
    at com.intellij.ide.util.gotoByName.GotoActionModel$MatchedValue.compareTo(GotoActionModel.java:195)
    at com.intellij.ide.util.gotoByName.GotoActionModel.compare(GotoActionModel.java:255)
    at java.util.TreeMap.put(TreeMap.java:552)
    at java.util.TreeSet.add(TreeSet.java:255)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
    at java.util.TreeSet.addAll(TreeSet.java:312)
    at com.intellij.ide.util.gotoByName.GotoActionModel.sort(GotoActionModel.java:397)
    at com.intellij.ide.actions.GotoActionAction$2.filter(GotoActionAction.java:132)
    at com.intellij.ide.util.gotoByName.ChooseByNameBase$CalcElementsThread.a(ChooseByNameBase.java:1537)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils$4.a(ProgressIndicatorUtils.java:185)
    at com.intellij.openapi.application.TransactionGuardImpl$6.run(TransactionGuardImpl.java:291)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:326)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:310)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:863)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:699)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:385)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Exception when using code generation in Java class, plugin enabled

I have this exception when i using code generation in Java class (IDEA 14.1.01674, java 1.7.0_79):

org/jetbrains/kotlin/psi/KtFile
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/psi/KtFile
at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.getPsiClassFromEvent(ParcelableAction.java:82)
at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.update(ParcelableAction.java:69)
at com.intellij.openapi.actionSystem.AnAction.beforeActionPerformedUpdate(AnAction.java:243)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:111)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.b(PopupFactoryImpl.java:934)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.b(PopupFactoryImpl.java:924)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.buildGroup(PopupFactoryImpl.java:860)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.a(PopupFactoryImpl.java:257)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.(PopupFactoryImpl.java:214)
at com.intellij.ui.popup.PopupFactoryImpl.a(PopupFactoryImpl.java:194)
at com.intellij.ui.popup.PopupFactoryImpl.a(PopupFactoryImpl.java:168)
at com.intellij.ui.popup.PopupFactoryImpl.createActionGroupPopup(PopupFactoryImpl.java:296)
at com.intellij.codeInsight.generation.actions.GenerateAction.actionPerformed(GenerateAction.java:38)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:586)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:637)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.d(IdeKeyEventDispatcher.java:476)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:212)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:538)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

java.lang.NoClassDefFoundError: org/jetbrains/kotlin/psi/KtFile
at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.getPsiClassFromEvent(ParcelableAction.java:82)
at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.update(ParcelableAction.java:69)
at com.intellij.openapi.actionSystem.AnAction.beforeActionPerformedUpdate(AnAction.java:243)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:111)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.b(PopupFactoryImpl.java:934)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.b(PopupFactoryImpl.java:924)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.buildGroup(PopupFactoryImpl.java:860)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.a(PopupFactoryImpl.java:257)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.(PopupFactoryImpl.java:214)
at com.intellij.ui.popup.PopupFactoryImpl.a(PopupFactoryImpl.java:194)
at com.intellij.ui.popup.PopupFactoryImpl.a(PopupFactoryImpl.java:168)
at com.intellij.ui.popup.PopupFactoryImpl.createActionGroupPopup(PopupFactoryImpl.java:296)
at com.intellij.codeInsight.generation.actions.GenerateAction.actionPerformed(GenerateAction.java:38)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:586)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:637)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.d(IdeKeyEventDispatcher.java:476)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:212)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:538)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

java.lang.NoClassDefFoundError: org/jetbrains/kotlin/psi/KtFile
at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.getPsiClassFromEvent(ParcelableAction.java:82)
at cn.nekocode.plugin.parcelablegenerator.ParcelableAction.update(ParcelableAction.java:69)
at com.intellij.openapi.actionSystem.AnAction.beforeActionPerformedUpdate(AnAction.java:243)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:111)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.b(PopupFactoryImpl.java:934)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.b(PopupFactoryImpl.java:924)
at com.intellij.ui.popup.PopupFactoryImpl$ActionStepBuilder.buildGroup(PopupFactoryImpl.java:860)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.a(PopupFactoryImpl.java:257)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.(PopupFactoryImpl.java:214)
at com.intellij.ui.popup.PopupFactoryImpl.a(PopupFactoryImpl.java:194)
at com.intellij.ui.popup.PopupFactoryImpl.a(PopupFactoryImpl.java:168)
at com.intellij.ui.popup.PopupFactoryImpl.createActionGroupPopup(PopupFactoryImpl.java:296)
at com.intellij.codeInsight.generation.actions.GenerateAction.actionPerformed(GenerateAction.java:38)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:586)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:637)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.d(IdeKeyEventDispatcher.java:476)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:212)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:538)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Plugin Exception

Using Android Studio 1.5.1 and trying to install this plugin, all I get is the following exception which might have something to do with compiled version?

cannot create class "cn.nekocode.plugin.parcelablegenerator.ParcelableAction" [Plugin:     cn.nekocode.plugin.parcelablegenerator]
com.intellij.diagnostic.PluginException: cannot create class "cn.nekocode.plugin.parcelablegenerator.ParcelableAction" [Plugin: cn.nekocode.plugin.parcelablegenerator]
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:178)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:518)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getActionImpl(ActionManagerImpl.java:498)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getAction(ActionManagerImpl.java:491)
    at com.intellij.openapi.actionSystem.DefaultActionGroup.unStub(DefaultActionGroup.java:354)
    at com.intellij.openapi.actionSystem.DefaultActionGroup.getChildren(DefaultActionGroup.java:312)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1323)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1316)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1316)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1310)
    at com.intellij.codeInsight.generation.actions.GenerateAction.preload(GenerateAction.java:99)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1328)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1331)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1310)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.doPreloadActions(ActionManagerImpl.java:1298)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.access$200(ActionManagerImpl.java:78)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$4.run(ActionManagerImpl.java:1281)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
    at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
Caused by: com.intellij.diagnostic.PluginException: cn/nekocode/plugin/parcelablegenerator/ParcelableAction : Unsupported major.minor version 52.0 [Plugin: cn.nekocode.plugin.parcelablegenerator]
    at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:130)
    at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.java:77)
    at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:66)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:249)
    at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:154)
    ... 25 more
Caused by: java.lang.UnsupportedClassVersionError: cn/nekocode/plugin/parcelablegenerator/ParcelableAction : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:471)
    at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:259)
    at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:255)
    at com.intellij.util.lang.UrlClassLoader._findClass(UrlClassLoader.java:231)
    at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:124)
    ... 31 more

Compat generated code

Will be cool if the generated code was more compact using one liner functions or something like:

override fun describeContents(): Int = 0

companion object {
    @JvmField val CREATOR: Parcelable.Creator<User> = object : Parcelable.Creator<User> {
      override fun createFromParcel(source: Parcel): User = User(source)
      override fun newArray(size: Int): Array<User?> = arrayOfNulls(size)
    }
  }

instead of

override fun describeContents(): Int {
    return 0
  }

  companion object {
    @JvmField final val CREATOR: Parcelable.Creator<User> = object : Parcelable.Creator<User> {
      override fun createFromParcel(source: Parcel): User {
        return User(source)
      }

      override fun newArray(size: Int): Array<User?> {
        return arrayOfNulls(size)
      }
    }
  }

Deserialization for list parcelable crashes when you call writeTypedList(null) first

Current generated code for list of parcelables will crash if you put an empty list.

Error example

Caused by: java.lang.IllegalStateException: source.createTypedArrayL…(AvatarUrlHolder.CREATOR) must not be null

Example code

class AvatarUrlHolder(val id: Long, val url: String) : Parcelable {

  constructor(source: Parcel) : this(source.readLong(), source.readString())

  override fun describeContents() = 0

  override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
    writeLong(id)
    writeString(url)
  }

  companion object {
    @JvmField
    val CREATOR: Parcelable.Creator<AvatarUrlHolder> = object : Parcelable.Creator<AvatarUrlHolder> {
      override fun createFromParcel(source: Parcel): AvatarUrlHolder = AvatarUrlHolder(source)
      override fun newArray(size: Int): Array<AvatarUrlHolder?> = arrayOfNulls(size)
    }
  }

}

// Class that have the list
class People(val avatars: List<AvatarUrlHolder>) : Parcelable {

  constructor(source: Parcel) : this(
    source.createTypedArrayList(AvatarUrlHolder.CREATOR)
  )

  override fun describeContents() = 0

  override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
    writeTypedList(agreedExpertsAvatars)
  }

  companion object {
    @JvmField
    val CREATOR: Parcelable.Creator<People> = object : Parcelable.Creator<People> {
      override fun createFromParcel(source: Parcel): People = People(source)
      override fun newArray(size: Int): Array<People?> = arrayOfNulls(size)
    }
  }
}

If you create the people with People(listOf()) the method writeTypedList will crash with:

Caused by: java.lang.IllegalStateException: source.createTypedArrayL…(AvatarUrlHolder.CREATOR) must not be null

Solution

This can be fixed if the generated code in the constructor looks like:

listOf<AvatarUrlHolder>().apply {
  source.readTypedList(this, AvatarUrlHolder.CREATOR)
}

instead of:

source.createTypedArrayList(AvatarUrlHolder.CREATOR)

Support Parcelables

Hi,
I wanted to include LatLng, a parcelable class from the Google Maps API, and the plugin generated wrong code for this field, inventing a method name based on the class name.
To solve the problem, I added these two extension functions in the companion object:

private fun Parcel.readLatLng(): LatLng? = LatLng.CREATOR.createFromParcel(this)
private fun Parcel.writeLatLng(position: LatLng?) = position?.writeToParcel(this, 0)

so I could use them in place of the wrong code.
Could this plugin support Parcelables along with primitives types?

dest: Parcel?

Writing to a Parcel always requires an instance of Parcel. Nullability and safe calls should be removed.

No need for dest null check

Hi! Thanks for the generator!
I think we don't need to check the dest for null in

        override fun writeToParcel(dest: Parcel?, flags: Int) {
            dest?.writeInt(orderId)
        }

because dest will never be null.
Check out the Parcelable javadoc and the example in it:

      public void writeToParcel(Parcel out, int flags) {
          out.writeInt(mData);
      }

This method not meant to be called with null Parcel.

So I think it will be good for readability to remove this unnecessary null check by set dest as non-null parameter:

        override fun writeToParcel(dest: Parcel, flags: Int) {
            dest.writeInt(orderId)
        }

uncaught NoSuchMethodError

Hi guys,

this plugin worked pretty good for me before,
today I am getting this plugin crash while trying to generate parcelable code.
This error occurs even when I try to regenerate code at existed classes.
I tried to clear cache and restart, clean project, reinstall plugin, degrade kotlin version, even new project. Nothing helps.

Kotlin 1.0.5-2
Android Studio 2.2.3
Build #AI-145.3537739, built on December 2, 2016
JRE: 1.8.0_112-release-b05 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Plugin Error: Parcelable Code Generator(for kotlin) threw an uncaught NoSuchMethodError. Disable Plugin
NoSuchMethodError: org.jetbrains.kotlin.descriptors.ClassDescriptor.getUnsubstitutedPrimaryConstructor()Lorg/jetbrains/kotlin/descriptors/ConstructorDescriptor;

How to get the kotlin-plugin.jar

hi,i want to learn how to develop plugin for kotlin . but when i pull your project , the library about kotlin is not found. like "KtClass" and so on. please tell me how to build this project

Kotlin style equals

In generated code lint is proposing to change

1.equals(source.readInt())

with use of == because it is more idiomatic in Kotlin.

Improvements idea

The idea was took from https://medium.com/@BladeCoder/reducing-parcelable-boilerplate-code-using-kotlin-741c3124a49a.

If you have an internal KParcelable then:

  1. You dont have to put describeContents everywhere.
interface KParcelable : Parcelable {
    override fun describeContents() = 0
    override fun writeToParcel(dest: Parcel, flags: Int)
}
  1. You can have a parcelableCreator function like:
inline fun <reified T> parcelableCreator(crossinline create: (Parcel) -> T): 
Parcelable.Creator<T> {
    return object : Parcelable.Creator<T> {
        override fun createFromParcel(source: Parcel) = create(source)
        override fun newArray(size: Int) = arrayOfNulls<T>(size)
    }
}

to write simpler creators:

companion object {
        @JvmField
        val CREATOR: Parcelable.Creator<RealEstate> = parcelableCreator(::RealEstate)
    }

Unneded '?' in classLoader declaration

I have val income: Income? property and following code is generated for it

source.readParcelable<Income?>(Income?::class.java.classLoader)

As you see the '?' mark in Income?::class.java.classLoader is not needed. And lint says "type in class literal must not be nullable".

Support Enums

When I try to generate a parcelable class which contains an enum, it generates something like:

enum class SortOrder {
    AlphaAscending ,
    AlphaDescending,
    Date
}
constructor(source: Parcel) : this(source.readSortOrder())

override fun writeToParcel(dest: Parcel?, flags: Int) {
        dest?.writeSortOrder(sortOrder)
    }

and cannot resolve those read or write methods. Not sure if this has something to do with my code, or this plugin.

optional fields

If the class has optional fields, it might be helpful to use writeValue/readValue calls.
With my optional fields, current plugin generates source.readString?() which is invalid, besides if I remove the '?', the function will probably result in NPE if field is null.

Use apply writing values to improve readability

To make the generated code more idiomatic you can use apply to apply things to the same object, sample:

Before:

override fun writeToParcel(dest: Parcel, flags: Int) {
    dest.writeLong(id)
    dest.writeString(firstName)
    dest.writeString(lastName)
    dest.writeString(affiliation)
    dest.writeString(about)
    dest.writeString(city)
    dest.writeString(state)
    dest.writeString(country)
    dest.writeDouble(latitude)
    dest.writeDouble(longitude)
    dest.writeTypedList(subtopics)
    dest.writeInt((if (isTopExpert) 1 else 0))
  }

After:

override fun writeToParcel(dest: Parcel, flags: Int) = dest.apply {
    writeLong(id)
    writeString(firstName)
    writeString(lastName)
    writeString(affiliation)
    writeString(about)
    writeString(city)
    writeString(state)
    writeString(country)
    writeDouble(latitude)
    writeDouble(longitude)
    writeTypedList(subtopics)
    writeInt((if (isTopExpert) 1 else 0))
  }

Bad style for generated code for constructor

Version: 0.7.1
Android Studio: 2.2.3

Response:

constructor(source: Parcel) : this(
  source.readLong(),
  source.readString(),
  source.readString()
  )

How it will be better:

constructor(source: Parcel) : this(source.readLong(), source.readString(),  source.readString())

Kotlin is crashing with uncaught StackOverflowError

I keep my Kotlin version up-to-date. When I use 1.1.1, the generate command always generates incomplete code, and usually a tooltip appears with Kotlin crash message.

Just curious, @nekocode have you tried running this with latest Kotlin? Or anyone, can confirm?

Request: allow to use the new androidExtensions way

It's much shorter code:

gradle file:

apply plugin: 'org.jetbrains.kotlin.android.extensions'
androidExtensions {
experimental = true
}

sample code of a class with 3 Dates in it:

@SuppressLint("ParcelCreator")
@Parcelize
class MonthItem(val today: Date, val startDate: Date, val endDate: Date) : Parcelable {
}

The plugin here will only ask us which fields to add there, and which to ignore. Maybe also the order.

Source code corruption while adding imports

Here is a code sample with a change performed by the plugin, which breaks the correctness

 /*
  * XXXXXXX
  * Copyright © 2016 XXXX
  * 
  * Created by XXX
- */
+ */import java.util.*
+import android.os.Parcel
+import android.os.Parcelable
 
 package my.superb.package
 
 import android.net.Uri

Generated code for Map fields dont compile

Try a class like

class BugReportRepositoryBuilder(val apiKey: String, val projectId: String, val properties: Map<String, String>)

and generate file dont compile:

class BugReportRepositoryBuilder(val apiKey: String,
                                 val projectId: String,
                                 val properties: Map<String, String>)
  : BugReportRepository.Builder, Parcelable {

  companion object {
    @JvmField val CREATOR: Parcelable.Creator<BugReportRepositoryBuilder> = object : Parcelable.Creator<BugReportRepositoryBuilder> {
      override fun createFromParcel(source: Parcel): BugReportRepositoryBuilder = BugReportRepositoryBuilder(source)
      override fun newArray(size: Int): Array<BugReportRepositoryBuilder?> = arrayOfNulls(size)
    }
  }

  constructor(source: Parcel) : this(source.readString(), source.readString(), source.readMap<String, String>())

  override fun describeContents() = 0

  override fun writeToParcel(dest: Parcel?, flags: Int) {
    dest?.writeString(apiKey)
    dest?.writeString(projectId)
    dest?.writeMap<String, String>(properties)
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.