Skip to content

Commit

Permalink
suppressed unchecked cast warnings in parcel code
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrimble committed Nov 28, 2015
1 parent 3ca46db commit 9d0d1d4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright © 2010-2014 Nokia
*
* 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.jsonschema2pojo.util;

import com.sun.codemodel.JAnnotationArrayMember;
import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JMethod;

public class Models {

public static void suppressWarnings(JMethod method, String... values) {
JAnnotationUse annotation = method.annotate(SuppressWarnings.class);
JAnnotationArrayMember member = annotation.paramArray("value");
for( String value : values ) {
member.param(value);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.os.Parcel;
import android.os.Parcelable.Creator;
import com.sun.codemodel.*;
import static org.jsonschema2pojo.util.Models.*;


public class ParcelableHelper {
Expand Down Expand Up @@ -63,6 +64,7 @@ private void addCreateFromParcel(JDefinedClass jclass, JDefinedClass creatorClas
JMethod createFromParcel = creatorClass.method(JMod.PUBLIC, jclass, "createFromParcel");
JVar in = createFromParcel.param(Parcel.class, "in");
JVar instance = createFromParcel.body().decl(jclass, "instance", JExpr._new(jclass));
suppressWarnings(createFromParcel, "unchecked");
for (JFieldVar f : jclass.fields().values()) {
if (f.type().erasure().name().equals("List")) {
createFromParcel.body()
Expand Down

0 comments on commit 9d0d1d4

Please sign in to comment.