Comments (6)
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.
Could you post some failing code?
from android-parcelable-intellij-plugin.
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.
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");
}
from android-parcelable-intellij-plugin.
Hi,
The problem is "getAllFields" method. It returns fields of parent classes also. I replaced it with "getFields" method.
from android-parcelable-intellij-plugin.
Hi,
@fthdgn If you test it,give a pull request please
from android-parcelable-intellij-plugin.
Related Issues (20)
- runtime exception when readList
- NullPointerException: null HOT 4
- android studio mac 配置环境 HOT 1
- There is no Preferences -> Plugins -> Install plugin from disk....
- Object is not parceled correctly if it has a field of an array of its own type HOT 1
- Not work in Andriod_studio_window_x64_2.1.2
- Generate final parameters where possible? HOT 2
- short[] causes broken code HOT 4
- Enum support HOT 3
- Code formating
- Generate code with parent object from library
- After installing, plugin not visible in AS 2.3 HOT 1
- [Question] Why the generated constructor is protected rather than private? HOT 1
- Error writing a list of Parcelable objects with subclasses
- How to parcel private List<T> data; HOT 1
- Request: support Kotlin too
- Android Studio 3.0 not work HOT 10
- when map is null. HOT 1
- Android Studio 4.1 support HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-parcelable-intellij-plugin.