Code Monkey home page Code Monkey logo

Comments (6)

fthdgn avatar fthdgn commented on July 18, 2024 1

Hi @shibenli
I've already created a pull request before my comment. #67 But I think there is a problem with my PR. It also shows my other commits after PR created. I will create a new PR.

from android-parcelable-intellij-plugin.

DariusL avatar DariusL commented on July 18, 2024

Could you post some failing code?

from android-parcelable-intellij-plugin.

beilly avatar beilly commented on July 18, 2024

This Parent Class parcelabled ok :

public class ResultInfo implements Parcelable {
    @SerializedName("status")
    protected Integer status;
    @SerializedName("msg")
    protected String msg;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(this.status);
        dest.writeString(this.msg);
    }

    protected ResultInfo(Parcel in) {
        this.status = (Integer) in.readValue(Integer.class.getClassLoader());
        this.msg = in.readString();
    }

    public static final Parcelable.Creator<ResultInfo> CREATOR = new Parcelable.Creator<ResultInfo>() {
        @Override
        public ResultInfo createFromParcel(Parcel source) {
            return new ResultInfo(source);
        }

        @Override
        public ResultInfo[] newArray(int size) {
            return new ResultInfo[size];
        }
    };
}

When i parce the child class,child is ok:

public class User extends ResultInfo{
    protected  String name;
    protected  Integer id;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(this.name);
        dest.writeValue(this.id);
    }

    protected User(Parcel in) {
        super(in);
        this.name = in.readString();
        this.id = (Integer) in.readValue(Integer.class.getClassLoader());
    }

    public static final Creator<User> CREATOR = new Creator<User>() {
        @Override
        public User createFromParcel(Parcel source) {
            return new User(source);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };
}

But the parent class has been changed like this(public static final Parcelable.Creator CREATOR is missing):

public class ResultInfo implements Parcelable {
    @SerializedName("status")
    protected Integer status;
    @SerializedName("msg")
    protected String msg;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(this.status);
        dest.writeString(this.msg);
    }

    protected ResultInfo(Parcel in) {
        this.status = (Integer) in.readValue(Integer.class.getClassLoader());
        this.msg = in.readString();
    }

}

from android-parcelable-intellij-plugin.

beilly avatar beilly commented on July 18, 2024

I think this problem may caused by CodeGenerator.java (the removeExistingParcelableImplementation method).It will delete it's parent CREATOR.Or you may want to delete child's CREATOR?

    /**
     * Strips the
     *
     * @param psiClass
     */
    private void removeExistingParcelableImplementation(PsiClass psiClass) {
        PsiField[] allFields = psiClass.getAllFields();

        // Look for an existing CREATOR and remove it
        for (PsiField field : allFields) {
            if (field.getName().equals(CREATOR_NAME)) {
                // Creator already exists, need to remove/replace it
                field.delete();
            }
        }

        findAndRemoveMethod(psiClass, psiClass.getName(), TYPE_PARCEL);
        findAndRemoveMethod(psiClass, "describeContents");
        findAndRemoveMethod(psiClass, "writeToParcel", TYPE_PARCEL, "int");
    }

@DariusL

from android-parcelable-intellij-plugin.

fthdgn avatar fthdgn commented on July 18, 2024

Hi,
The problem is "getAllFields" method. It returns fields of parent classes also. I replaced it with "getFields" method.

from android-parcelable-intellij-plugin.

beilly avatar beilly commented on July 18, 2024

Hi,
@fthdgn If you test it,give a pull request please

from android-parcelable-intellij-plugin.

Related Issues (20)

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.