Skip to content

Commit

Permalink
So long, @icicle
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiesardo committed Jul 22, 2015
1 parent 0d7706e commit f60b4b9
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 76 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -9,7 +9,7 @@ It uses annotation processing to generate code that does bundle manipulation and


```java ```java
class ExampleActivity extends Activity { class ExampleActivity extends Activity {
@Icicle String username; // This will be automatically saved and restored @State String username; // This will be automatically saved and restored


@Override public void onCreate(Bundle savedInstanceState) { @Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Expand All @@ -32,7 +32,7 @@ Icepick can also generate the instance state code for custom Views:


```java ```java
class CustomView extends View { class CustomView extends View {
@Icicle int selectedPosition; // This will be automatically saved and restored @State int selectedPosition; // This will be automatically saved and restored


@Override public Parcelable onSaveInstanceState() { @Override public Parcelable onSaveInstanceState() {
return Icepick.saveInstanceState(this, super.onSaveInstanceState()); return Icepick.saveInstanceState(this, super.onSaveInstanceState());
Expand All @@ -55,8 +55,8 @@ If Proguard is enabled make sure you add these rules to your configuration:


``` ```
-dontwarn icepick.** -dontwarn icepick.**
-keep class **$$Icicle { *; } -keep class **$$State { *; }
-keepnames class * { @icepick.Icicle *;} -keepnames class * { @icepick.State *;}
-keepclasseswithmembernames class * { -keepclasseswithmembernames class * {
@icepick.* <fields>; @icepick.* <fields>;
} }
Expand Down
4 changes: 2 additions & 2 deletions icepick-processor/src/clojure/icepick/processor.clj
Expand Up @@ -2,7 +2,7 @@
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.string :as str] [clojure.string :as str]
[stencil.core :as mustache]) [stencil.core :as mustache])
(:import (icepick Icicle (:import (icepick State
Icepick) Icepick)
(javax.tools Diagnostic$Kind) (javax.tools Diagnostic$Kind)
(javax.lang.model.type TypeMirror (javax.lang.model.type TypeMirror
Expand Down Expand Up @@ -128,7 +128,7 @@ public class {{name}}<T extends {{target}}> extends {{parent}}<T> {
(defn- annotated-class? [^TypeElement elem] (defn- annotated-class? [^TypeElement elem]
(seq (for [field (ElementFilter/fieldsIn (.getEnclosedElements elem)) (seq (for [field (ElementFilter/fieldsIn (.getEnclosedElements elem))
ann (.getAnnotationMirrors field) ann (.getAnnotationMirrors field)
:when (= (.getName Icicle) :when (= (.getName State)
(-> ann .getAnnotationType .asElement str))] (-> ann .getAnnotationType .asElement str))]
field))) field)))


Expand Down
Expand Up @@ -22,7 +22,7 @@
import clojure.lang.IFn; import clojure.lang.IFn;
import clojure.lang.Compiler; import clojure.lang.Compiler;


import icepick.Icicle; import icepick.State;


import com.google.auto.service.AutoService; import com.google.auto.service.AutoService;


Expand Down Expand Up @@ -60,6 +60,6 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
} }


@Override public Set<String> getSupportedAnnotationTypes() { @Override public Set<String> getSupportedAnnotationTypes() {
return new HashSet<String>(Arrays.asList(Icicle.class.getName())); return new HashSet<String>(Arrays.asList(State.class.getName()));
} }
} }
112 changes: 56 additions & 56 deletions icepick-processor/test/icepick/core_test.clj
Expand Up @@ -44,38 +44,38 @@
(check-fails (check-fails
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"public class Test {" "public class Test {"
" @Icicle private int f1;" " @State private int f1;"
"}"]])) "}"]]))
(testing "private class" (testing "private class"
(check-fails (check-fails
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"public class Test {" "public class Test {"
" private static class Inner {" " private static class Inner {"
" @Icicle private int f1;" " @State private int f1;"
" }" " }"
"}"]]))) "}"]])))


(deftest simple (deftest simple
(check-compiles (check-compiles
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"public class Test {" "public class Test {"
" @Icicle int f1;" " @State int f1;"
" @Icicle boolean f2;" " @State boolean f2;"
" @Icicle char[] f3;" " @State char[] f3;"
"}"]] "}"]]
["test.Test$$Icicle" ["test.Test$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.Object;" "import icepick.Injector.Object;"
"public class Test$$Icicle<T extends Test> extends Object<T> {" "public class Test$$Icepick<T extends Test> extends Object<T> {"
" private final static Helper H = new Helper(\"test.Test$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$$Icepick.\");"
" public void restore(T target, Bundle state) {" " public void restore(T target, Bundle state) {"
" if (state == null) return;" " if (state == null) return;"
" target.f1 = H.getInt(state, \"f1\");" " target.f1 = H.getInt(state, \"f1\");"
Expand All @@ -95,17 +95,17 @@
(check-compiles (check-compiles
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"public class Test {" "public class Test {"
" @Icicle Float f1;" " @State Float f1;"
"}"]] "}"]]
["test.Test$$Icicle" ["test.Test$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.Object;" "import icepick.Injector.Object;"
"public class Test$$Icicle<T extends Test> extends Object<T> {" "public class Test$$Icepick<T extends Test> extends Object<T> {"
" private final static Helper H = new Helper(\"test.Test$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$$Icepick.\");"
" public void restore(T target, Bundle state) {" " public void restore(T target, Bundle state) {"
" if (state == null) return;" " if (state == null) return;"
" target.f1 = H.getBoxedFloat(state, \"f1\");" " target.f1 = H.getBoxedFloat(state, \"f1\");"
Expand All @@ -122,26 +122,26 @@
(check-fails (check-fails
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"public class Test<T extends CharSequence> {" "public class Test<T extends CharSequence> {"
" @Icicle T f1;" " @State T f1;"
"}"]])) "}"]]))
(testing "unless T is Parcelable" (testing "unless T is Parcelable"
(check-compiles (check-compiles
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"import android.os.Parcelable;" "import android.os.Parcelable;"
"public class Test<T extends Parcelable> {" "public class Test<T extends Parcelable> {"
" @Icicle T f1;" " @State T f1;"
"}"]] "}"]]
["test.Test$$Icicle" ["test.Test$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.Object;" "import icepick.Injector.Object;"
"public class Test$$Icicle<T extends Test> extends Object<T> {" "public class Test$$Icepick<T extends Test> extends Object<T> {"
" private final static Helper H = new Helper(\"test.Test$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$$Icepick.\");"
" public void restore(T target, Bundle state) {" " public void restore(T target, Bundle state) {"
" if (state == null) return;" " if (state == null) return;"
" target.f1 = H.getParcelable(state, \"f1\");" " target.f1 = H.getParcelable(state, \"f1\");"
Expand All @@ -156,21 +156,21 @@
(check-compiles (check-compiles
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"import java.util.ArrayList;" "import java.util.ArrayList;"
"import android.util.SparseArray;" "import android.util.SparseArray;"
"import android.os.Parcelable;" "import android.os.Parcelable;"
"public class Test<T extends Parcelable> {" "public class Test<T extends Parcelable> {"
" @Icicle ArrayList<T> f1;" " @State ArrayList<T> f1;"
" @Icicle SparseArray<T> f2;" " @State SparseArray<T> f2;"
"}"]] "}"]]
["test.Test$$Icicle" ["test.Test$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.Object;" "import icepick.Injector.Object;"
"public class Test$$Icicle<T extends Test> extends Object<T> {" "public class Test$$Icepick<T extends Test> extends Object<T> {"
" private final static Helper H = new Helper(\"test.Test$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$$Icepick.\");"
" public void restore(T target, Bundle state) {" " public void restore(T target, Bundle state) {"
" if (state == null) return;" " if (state == null) return;"
" target.f1 = H.getParcelableArrayList(state, \"f1\");" " target.f1 = H.getParcelableArrayList(state, \"f1\");"
Expand All @@ -187,24 +187,24 @@
(check-compiles (check-compiles
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"import java.util.ArrayList;" "import java.util.ArrayList;"
"import android.os.Bundle;" "import android.os.Bundle;"
"public class Test {" "public class Test {"
" static class AL<T> extends ArrayList<T> {}" " static class AL<T> extends ArrayList<T> {}"
" @Icicle AL<Integer> f1;" " @State AL<Integer> f1;"
" @Icicle AL<String> f2;" " @State AL<String> f2;"
" @Icicle AL<CharSequence> f3;" " @State AL<CharSequence> f3;"
" @Icicle Bundle[] f4;" " @State Bundle[] f4;"
" @Icicle StringBuffer[] f5;" " @State StringBuffer[] f5;"
"}"]] "}"]]
["test.Test$$Icicle" ["test.Test$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.Object;" "import icepick.Injector.Object;"
"public class Test$$Icicle<T extends Test> extends Object<T> {" "public class Test$$Icepick<T extends Test> extends Object<T> {"
" private final static Helper H = new Helper(\"test.Test$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$$Icepick.\");"
" public void restore(T target, Bundle state) {" " public void restore(T target, Bundle state) {"
" if (state == null) return;" " if (state == null) return;"
" target.f1 = H.getSerializable(state, \"f1\");" " target.f1 = H.getSerializable(state, \"f1\");"
Expand All @@ -228,22 +228,22 @@
(check-compiles (check-compiles
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"import android.os.Parcelable;" "import android.os.Parcelable;"
"import android.os.Bundle;" "import android.os.Bundle;"
"public class Test<T extends Parcelable> {" "public class Test<T extends Parcelable> {"
" @Icicle T f1;" " @State T f1;"
" static class Inner extends Test<Bundle> {" " static class Inner extends Test<Bundle> {"
" @Icicle String f2;" " @State String f2;"
" }" " }"
"}"]] "}"]]
["test.Test$$Icicle" ["test.Test$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.Object;" "import icepick.Injector.Object;"
"public class Test$$Icicle<T extends Test> extends Object<T> {" "public class Test$$Icepick<T extends Test> extends Object<T> {"
" private final static Helper H = new Helper(\"test.Test$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$$Icepick.\");"
" public void restore(T target, Bundle state) {" " public void restore(T target, Bundle state) {"
" if (state == null) return;" " if (state == null) return;"
" target.f1 = H.getParcelable(state, \"f1\");" " target.f1 = H.getParcelable(state, \"f1\");"
Expand All @@ -254,13 +254,13 @@
" H.putParcelable(state, \"f1\", target.f1);" " H.putParcelable(state, \"f1\", target.f1);"
" }" " }"
"}"]] "}"]]
["test.Test$Inner$$Icicle" ["test.Test$Inner$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.Object;" "import icepick.Injector.Object;"
"public class Test$Inner$$Icicle<T extends Test.Inner> extends test.Test$$Icicle<T> {" "public class Test$Inner$$Icepick<T extends Test.Inner> extends test.Test$$Icepick<T> {"
" private final static Helper H = new Helper(\"test.Test$Inner$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$Inner$$Icepick.\");"
" public void restore(T target, Bundle state) {" " public void restore(T target, Bundle state) {"
" if (state == null) return;" " if (state == null) return;"
" target.f2 = H.getString(state, \"f2\");" " target.f2 = H.getString(state, \"f2\");"
Expand All @@ -276,27 +276,27 @@
(check-compiles (check-compiles
["test.Test" ["test.Test"
["package test;" ["package test;"
"import icepick.Icicle;" "import icepick.State;"
"import android.view.View;" "import android.view.View;"
"import android.content.Context;" "import android.content.Context;"
"import android.os.Parcelable;" "import android.os.Parcelable;"
"import android.os.Bundle;" "import android.os.Bundle;"
"public class Test<T extends Parcelable> extends View {" "public class Test<T extends Parcelable> extends View {"
" public Test(Context c) {super(c);}" " public Test(Context c) {super(c);}"
" @Icicle T f1;" " @State T f1;"
" static class Inner extends Test<Bundle> {" " static class Inner extends Test<Bundle> {"
" public Inner(Context c) {super(c);}" " public Inner(Context c) {super(c);}"
" @Icicle String f2;" " @State String f2;"
" }" " }"
"}"]] "}"]]
["test.Test$$Icicle" ["test.Test$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import android.os.Parcelable;" "import android.os.Parcelable;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.View;" "import icepick.Injector.View;"
"public class Test$$Icicle<T extends Test> extends View<T> {" "public class Test$$Icepick<T extends Test> extends View<T> {"
" private final static Helper H = new Helper(\"test.Test$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$$Icepick.\");"
" public Parcelable restore(T target, Parcelable p) {" " public Parcelable restore(T target, Parcelable p) {"
" Bundle state = (Bundle) p;" " Bundle state = (Bundle) p;"
" target.f1 = H.getParcelable(state, \"f1\");" " target.f1 = H.getParcelable(state, \"f1\");"
Expand All @@ -308,14 +308,14 @@
" return state;" " return state;"
" }" " }"
"}"]] "}"]]
["test.Test$Inner$$Icicle" ["test.Test$Inner$$Icepick"
["package test;" ["package test;"
"import android.os.Bundle;" "import android.os.Bundle;"
"import android.os.Parcelable;" "import android.os.Parcelable;"
"import icepick.Injector.Helper;" "import icepick.Injector.Helper;"
"import icepick.Injector.View;" "import icepick.Injector.View;"
"public class Test$Inner$$Icicle<T extends Test.Inner> extends test.Test$$Icicle<T> {" "public class Test$Inner$$Icepick<T extends Test.Inner> extends test.Test$$Icepick<T> {"
" private final static Helper H = new Helper(\"test.Test$Inner$$Icicle.\");" " private final static Helper H = new Helper(\"test.Test$Inner$$Icepick.\");"
" public Parcelable restore(T target, Parcelable p) {" " public Parcelable restore(T target, Parcelable p) {"
" Bundle state = (Bundle) p;" " Bundle state = (Bundle) p;"
" target.f2 = H.getString(state, \"f2\");" " target.f2 = H.getString(state, \"f2\");"
Expand Down
2 changes: 1 addition & 1 deletion icepick/src/icepick/Icepick.java
Expand Up @@ -9,7 +9,7 @@


public class Icepick { public class Icepick {


public static final String SUFFIX = "$$Icicle"; public static final String SUFFIX = "$$Icepick";
public static final String ANDROID_PREFIX = "android."; public static final String ANDROID_PREFIX = "android.";
public static final String JAVA_PREFIX = "java."; public static final String JAVA_PREFIX = "java.";


Expand Down
Expand Up @@ -7,5 +7,5 @@


@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.CLASS) @Retention(RetentionPolicy.CLASS)
public @interface Icicle { public @interface State {
} }
Expand Up @@ -4,11 +4,11 @@
import android.os.Parcelable; import android.os.Parcelable;
import android.util.AttributeSet; import android.util.AttributeSet;
import com.sample.icepick.lib.BaseCustomView; import com.sample.icepick.lib.BaseCustomView;
import icepick.Icicle; import icepick.State;


public class CustomView extends BaseCustomView { public class CustomView extends BaseCustomView {


@Icicle Integer textColor; @State Integer textColor;


public CustomView(Context context) { public CustomView(Context context) {
super(context); super(context);
Expand Down
Expand Up @@ -5,11 +5,11 @@
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import com.sample.icepick.lib.BaseActivity; import com.sample.icepick.lib.BaseActivity;
import icepick.Icicle; import icepick.State;


public class MainActivity extends BaseActivity { public class MainActivity extends BaseActivity {


@Icicle String message; @State String message;


CustomView customView; CustomView customView;


Expand Down
Expand Up @@ -4,11 +4,11 @@
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import icepick.Icepick; import icepick.Icepick;
import icepick.Icicle; import icepick.State;
import android.util.Log; import android.util.Log;


public class BaseActivity extends Activity { public class BaseActivity extends Activity {
@Icicle protected String baseMessage; @State protected String baseMessage;


@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Expand Down

0 comments on commit f60b4b9

Please sign in to comment.