Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Import statements" go after class declaration #83

Closed
sisel opened this issue Nov 30, 2018 · 9 comments
Closed

"Import statements" go after class declaration #83

sisel opened this issue Nov 30, 2018 · 9 comments
Assignees
Labels
Milestone

Comments

@sisel
Copy link

sisel commented Nov 30, 2018

eg:

data class Pojo{
  @JvmField val foo:Int,
  @JvmField val bar:String
}
@wuseal
Copy link
Owner

wuseal commented Nov 30, 2018

@sisel Hi, You can achieve your goal by this settings:
image

Then you could generate class like this

data class Test(
    @JvmField
    val a: Int,
    @JvmField
    val b: Int
)

from JSON:

{
  "a": 213,
  "b": 32
}

@sisel
Copy link
Author

sisel commented Dec 6, 2018

Thanks.
And I found a weird behavior when using it with
import com.google.gson.annotations.SerializedName

import is after class 😳

my setting:
image
json:

{
  "a": 213,
  "b": 32
}

result:

class Test(
    @SerializedName("a")
    @JvmField
    val a: Int, // 213
    @SerializedName("b")
    @JvmField
    val b: Int // 32
)
import com.google.gson.annotations.SerializedName

plugin version 2.3.0

@wuseal
Copy link
Owner

wuseal commented Dec 6, 2018

@sisel What? Unbelievable! I just test all works well

import com.google.gson.annotations.SerializedName
data class TTT(
    @SerializedName("a")
    @JvmField
    val a: Int, // 213
    @SerializedName("b")
    @JvmField
    val b: Int // 32
)

Can you provide your config setting? and in which way to generate your classes, Generate class file from JSON or Convert Json into kotlin data class?

@sisel
Copy link
Author

sisel commented Dec 6, 2018

Sorry, I don't know why.
But I can't reproduce it now, it does happen yesterday & this morning😨.

Thanks for your support, and I will upload more info if it happens again.

@wuseal
Copy link
Owner

wuseal commented Dec 6, 2018

@sisel OK, Let's keep this issue opening for one week

@sisel
Copy link
Author

sisel commented Dec 7, 2018

Reproduced!

When package name end with data

I have tested it with
com.demo.data -> happens
com.test.data -> happens
com.demo.data.ge -> nope

@sisel
Copy link
Author

sisel commented Dec 7, 2018

and generated code:
eg: com.demo.data :

package com.demo.data class Test(
    @SerializedName("a")
    @JvmField
    val a: Int, // 213
    @SerializedName("b")
    @JvmField
    val b: Int // 32
)
import com.google.gson.annotations.SerializedName

@kezhenxu94
Copy link
Collaborator

kezhenxu94 commented Dec 8, 2018

Reproduced!

When package name end with data

I have tested it with
com.demo.data -> happens
com.test.data -> happens
com.demo.data.ge -> nope

That's wired, I can't reproduce, here are the settings:
image
image
image
image

And the generated class:

image

I'm testing this on
image
image

Is there any different between our settings? @sisel

And can you reproduce this? @wuseal

@kezhenxu94 kezhenxu94 changed the title Add Option to Generate with @JvmField Annotation "Import statements" go after class declaration Dec 8, 2018
@wuseal
Copy link
Owner

wuseal commented Dec 9, 2018

@sisel @kezhenxu94 Yes. I reproduced it, too.

package test.datadata class TestData(
    @SerializedName("a")
    @JvmField
    val a: Int, // 213
    @SerializedName("a")
    @JvmField
    val b: Int // 32
)
import com.google.gson.annotations.SerializedName

Just insert code after the end of the package declaration line without changing line

@wuseal wuseal added the bug label Dec 9, 2018
wuseal pushed a commit that referenced this issue Dec 23, 2018
wuseal pushed a commit that referenced this issue Dec 23, 2018
This reverts commit 79b22d7
wuseal pushed a commit that referenced this issue Dec 23, 2018
(cherry picked from commit 79b22d7)
@wuseal wuseal self-assigned this Dec 23, 2018
kezhenxu94 added a commit that referenced this issue Dec 24, 2018
@kezhenxu94 kezhenxu94 added the fixed but not released this issue has been solved but is not released yet label Dec 30, 2018
@kezhenxu94 kezhenxu94 added this to the 3.0 milestone Jan 12, 2019
@wuseal wuseal removed the fixed but not released this issue has been solved but is not released yet label Jan 18, 2019
@wuseal wuseal closed this as completed Jan 18, 2019
wuseal pushed a commit that referenced this issue Sep 20, 2021
wuseal pushed a commit that referenced this issue Sep 20, 2021
This reverts commit 79b22d7
wuseal pushed a commit that referenced this issue Sep 20, 2021
(cherry picked from commit 79b22d7)
wuseal pushed a commit that referenced this issue Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants