This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for getParcelableArray ClassCastException
- Loading branch information
1 parent
e608029
commit c2136c8
Showing
18 changed files
with
199 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...ndroidannotations/src/main/java/org/androidannotations/holder/BundleExtractionHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
* | ||
* 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. | ||
*/ | ||
package org.androidannotations.holder; | ||
|
||
import static com.sun.codemodel.JExpr._null; | ||
import static com.sun.codemodel.JExpr.cast; | ||
import static com.sun.codemodel.JExpr.invoke; | ||
import static com.sun.codemodel.JExpr.lit; | ||
import static com.sun.codemodel.JMod.PRIVATE; | ||
|
||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.lang.model.element.TypeElement; | ||
|
||
import org.androidannotations.process.ProcessHolder.Classes; | ||
|
||
import com.sun.codemodel.JBlock; | ||
import com.sun.codemodel.JClass; | ||
import com.sun.codemodel.JCodeModel; | ||
import com.sun.codemodel.JDefinedClass; | ||
import com.sun.codemodel.JMethod; | ||
import com.sun.codemodel.JVar; | ||
|
||
public class BundleExtractionHolder implements HasBundleExtraction { | ||
|
||
protected EComponentHolder holder; | ||
|
||
public BundleExtractionHolder(EComponentHolder holder) { | ||
this.holder = holder; | ||
} | ||
|
||
@Override | ||
public JMethod getGetParcelableArrayMethod() { | ||
JMethod method = getGeneratedClass().method(PRIVATE, classes().PARCELABLE.array(), "getParcelableArray"); | ||
JVar bundleParam = method.param(classes().BUNDLE, "bundle"); | ||
JVar keyParam = method.param(classes().STRING, "key"); | ||
JVar typeParam = method.param(classes().CLASS.narrow(classes().PARCELABLE.array().wildcard()), "type"); | ||
|
||
JBlock methodBody = method.body(); | ||
|
||
JVar valueVar = methodBody.decl(classes().PARCELABLE.array(), "value", invoke(bundleParam, "getParcelableArray").arg(keyParam)); | ||
methodBody._if(valueVar.eq(_null()))._then()._return(_null()); | ||
JVar copyVar = methodBody.decl(classes().OBJECT, "copy", classes().ARRAY.staticInvoke("newInstance").arg(typeParam.invoke("getComponentType")).arg(valueVar.ref("length"))); | ||
methodBody.staticInvoke(classes().SYSTEM, "arraycopy").arg(valueVar).arg(lit(0)).arg(copyVar).arg(lit(0)).arg(valueVar.ref("length")); | ||
methodBody._return(cast(classes().PARCELABLE.array(), copyVar)); | ||
|
||
return method; | ||
} | ||
|
||
@Override | ||
public JDefinedClass getGeneratedClass() { | ||
return holder.getGeneratedClass(); | ||
} | ||
|
||
@Override | ||
public TypeElement getAnnotatedElement() { | ||
return holder.getAnnotatedElement(); | ||
} | ||
|
||
@Override | ||
public ProcessingEnvironment processingEnvironment() { | ||
return holder.processingEnvironment(); | ||
} | ||
|
||
@Override | ||
public Classes classes() { | ||
return holder.classes(); | ||
} | ||
|
||
@Override | ||
public JCodeModel codeModel() { | ||
return holder.codeModel(); | ||
} | ||
|
||
@Override | ||
public JClass refClass(String fullyQualifiedClassName) { | ||
return holder.refClass(fullyQualifiedClassName); | ||
} | ||
|
||
@Override | ||
public JClass refClass(Class<?> clazz) { | ||
return holder.refClass(clazz); | ||
} | ||
|
||
@Override | ||
public JDefinedClass definedClass(String fullyQualifiedClassName) { | ||
return holder.definedClass(fullyQualifiedClassName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...s/androidannotations/src/main/java/org/androidannotations/holder/HasBundleExtraction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
* | ||
* 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. | ||
*/ | ||
package org.androidannotations.holder; | ||
|
||
import com.sun.codemodel.JMethod; | ||
|
||
public interface HasBundleExtraction extends GeneratedClassHolder { | ||
|
||
JMethod getGetParcelableArrayMethod(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.