diff --git a/README.md b/README.md index 0fcd9ba..a303cb9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It uses annotation processing to generate code that does bundle manipulation and ```java 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) { super.onCreate(savedInstanceState); @@ -32,7 +32,7 @@ Icepick can also generate the instance state code for custom Views: ```java 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() { return Icepick.saveInstanceState(this, super.onSaveInstanceState()); @@ -55,8 +55,8 @@ If Proguard is enabled make sure you add these rules to your configuration: ``` -dontwarn icepick.** --keep class **$$Icicle { *; } --keepnames class * { @icepick.Icicle *;} +-keep class **$$State { *; } +-keepnames class * { @icepick.State *;} -keepclasseswithmembernames class * { @icepick.* ; } diff --git a/icepick-processor/src/clojure/icepick/processor.clj b/icepick-processor/src/clojure/icepick/processor.clj index 48bd98b..2a888fa 100644 --- a/icepick-processor/src/clojure/icepick/processor.clj +++ b/icepick-processor/src/clojure/icepick/processor.clj @@ -2,7 +2,7 @@ (:require [clojure.java.io :as io] [clojure.string :as str] [stencil.core :as mustache]) - (:import (icepick Icicle + (:import (icepick State Icepick) (javax.tools Diagnostic$Kind) (javax.lang.model.type TypeMirror @@ -128,7 +128,7 @@ public class {{name}} extends {{parent}} { (defn- annotated-class? [^TypeElement elem] (seq (for [field (ElementFilter/fieldsIn (.getEnclosedElements elem)) ann (.getAnnotationMirrors field) - :when (= (.getName Icicle) + :when (= (.getName State) (-> ann .getAnnotationType .asElement str))] field))) diff --git a/icepick-processor/src/java/icepick/processor/IcepickProcessor.java b/icepick-processor/src/java/icepick/processor/IcepickProcessor.java index 69b7b43..9ed14b4 100644 --- a/icepick-processor/src/java/icepick/processor/IcepickProcessor.java +++ b/icepick-processor/src/java/icepick/processor/IcepickProcessor.java @@ -22,7 +22,7 @@ import clojure.lang.IFn; import clojure.lang.Compiler; -import icepick.Icicle; +import icepick.State; import com.google.auto.service.AutoService; @@ -60,6 +60,6 @@ public boolean process(Set annotations, RoundEnvironment } @Override public Set getSupportedAnnotationTypes() { - return new HashSet(Arrays.asList(Icicle.class.getName())); + return new HashSet(Arrays.asList(State.class.getName())); } } diff --git a/icepick-processor/test/icepick/core_test.clj b/icepick-processor/test/icepick/core_test.clj index 43329f7..1120917 100644 --- a/icepick-processor/test/icepick/core_test.clj +++ b/icepick-processor/test/icepick/core_test.clj @@ -44,18 +44,18 @@ (check-fails ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "public class Test {" - " @Icicle private int f1;" + " @State private int f1;" "}"]])) (testing "private class" (check-fails ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "public class Test {" " private static class Inner {" - " @Icicle private int f1;" + " @State private int f1;" " }" "}"]]))) @@ -63,19 +63,19 @@ (check-compiles ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "public class Test {" - " @Icicle int f1;" - " @Icicle boolean f2;" - " @Icicle char[] f3;" + " @State int f1;" + " @State boolean f2;" + " @State char[] f3;" "}"]] - ["test.Test$$Icicle" + ["test.Test$$Icepick" ["package test;" "import android.os.Bundle;" "import icepick.Injector.Helper;" "import icepick.Injector.Object;" - "public class Test$$Icicle extends Object {" - " private final static Helper H = new Helper(\"test.Test$$Icicle.\");" + "public class Test$$Icepick extends Object {" + " private final static Helper H = new Helper(\"test.Test$$Icepick.\");" " public void restore(T target, Bundle state) {" " if (state == null) return;" " target.f1 = H.getInt(state, \"f1\");" @@ -95,17 +95,17 @@ (check-compiles ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "public class Test {" - " @Icicle Float f1;" + " @State Float f1;" "}"]] - ["test.Test$$Icicle" + ["test.Test$$Icepick" ["package test;" "import android.os.Bundle;" "import icepick.Injector.Helper;" "import icepick.Injector.Object;" - "public class Test$$Icicle extends Object {" - " private final static Helper H = new Helper(\"test.Test$$Icicle.\");" + "public class Test$$Icepick extends Object {" + " private final static Helper H = new Helper(\"test.Test$$Icepick.\");" " public void restore(T target, Bundle state) {" " if (state == null) return;" " target.f1 = H.getBoxedFloat(state, \"f1\");" @@ -122,26 +122,26 @@ (check-fails ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "public class Test {" - " @Icicle T f1;" + " @State T f1;" "}"]])) (testing "unless T is Parcelable" (check-compiles ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "import android.os.Parcelable;" "public class Test {" - " @Icicle T f1;" + " @State T f1;" "}"]] - ["test.Test$$Icicle" + ["test.Test$$Icepick" ["package test;" "import android.os.Bundle;" "import icepick.Injector.Helper;" "import icepick.Injector.Object;" - "public class Test$$Icicle extends Object {" - " private final static Helper H = new Helper(\"test.Test$$Icicle.\");" + "public class Test$$Icepick extends Object {" + " private final static Helper H = new Helper(\"test.Test$$Icepick.\");" " public void restore(T target, Bundle state) {" " if (state == null) return;" " target.f1 = H.getParcelable(state, \"f1\");" @@ -156,21 +156,21 @@ (check-compiles ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "import java.util.ArrayList;" "import android.util.SparseArray;" "import android.os.Parcelable;" "public class Test {" - " @Icicle ArrayList f1;" - " @Icicle SparseArray f2;" + " @State ArrayList f1;" + " @State SparseArray f2;" "}"]] - ["test.Test$$Icicle" + ["test.Test$$Icepick" ["package test;" "import android.os.Bundle;" "import icepick.Injector.Helper;" "import icepick.Injector.Object;" - "public class Test$$Icicle extends Object {" - " private final static Helper H = new Helper(\"test.Test$$Icicle.\");" + "public class Test$$Icepick extends Object {" + " private final static Helper H = new Helper(\"test.Test$$Icepick.\");" " public void restore(T target, Bundle state) {" " if (state == null) return;" " target.f1 = H.getParcelableArrayList(state, \"f1\");" @@ -187,24 +187,24 @@ (check-compiles ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "import java.util.ArrayList;" "import android.os.Bundle;" "public class Test {" " static class AL extends ArrayList {}" - " @Icicle AL f1;" - " @Icicle AL f2;" - " @Icicle AL f3;" - " @Icicle Bundle[] f4;" - " @Icicle StringBuffer[] f5;" + " @State AL f1;" + " @State AL f2;" + " @State AL f3;" + " @State Bundle[] f4;" + " @State StringBuffer[] f5;" "}"]] - ["test.Test$$Icicle" + ["test.Test$$Icepick" ["package test;" "import android.os.Bundle;" "import icepick.Injector.Helper;" "import icepick.Injector.Object;" - "public class Test$$Icicle extends Object {" - " private final static Helper H = new Helper(\"test.Test$$Icicle.\");" + "public class Test$$Icepick extends Object {" + " private final static Helper H = new Helper(\"test.Test$$Icepick.\");" " public void restore(T target, Bundle state) {" " if (state == null) return;" " target.f1 = H.getSerializable(state, \"f1\");" @@ -228,22 +228,22 @@ (check-compiles ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "import android.os.Parcelable;" "import android.os.Bundle;" "public class Test {" - " @Icicle T f1;" + " @State T f1;" " static class Inner extends Test {" - " @Icicle String f2;" + " @State String f2;" " }" "}"]] - ["test.Test$$Icicle" + ["test.Test$$Icepick" ["package test;" "import android.os.Bundle;" "import icepick.Injector.Helper;" "import icepick.Injector.Object;" - "public class Test$$Icicle extends Object {" - " private final static Helper H = new Helper(\"test.Test$$Icicle.\");" + "public class Test$$Icepick extends Object {" + " private final static Helper H = new Helper(\"test.Test$$Icepick.\");" " public void restore(T target, Bundle state) {" " if (state == null) return;" " target.f1 = H.getParcelable(state, \"f1\");" @@ -254,13 +254,13 @@ " H.putParcelable(state, \"f1\", target.f1);" " }" "}"]] - ["test.Test$Inner$$Icicle" + ["test.Test$Inner$$Icepick" ["package test;" "import android.os.Bundle;" "import icepick.Injector.Helper;" "import icepick.Injector.Object;" - "public class Test$Inner$$Icicle extends test.Test$$Icicle {" - " private final static Helper H = new Helper(\"test.Test$Inner$$Icicle.\");" + "public class Test$Inner$$Icepick extends test.Test$$Icepick {" + " private final static Helper H = new Helper(\"test.Test$Inner$$Icepick.\");" " public void restore(T target, Bundle state) {" " if (state == null) return;" " target.f2 = H.getString(state, \"f2\");" @@ -276,27 +276,27 @@ (check-compiles ["test.Test" ["package test;" - "import icepick.Icicle;" + "import icepick.State;" "import android.view.View;" "import android.content.Context;" "import android.os.Parcelable;" "import android.os.Bundle;" "public class Test extends View {" " public Test(Context c) {super(c);}" - " @Icicle T f1;" + " @State T f1;" " static class Inner extends Test {" " public Inner(Context c) {super(c);}" - " @Icicle String f2;" + " @State String f2;" " }" "}"]] - ["test.Test$$Icicle" + ["test.Test$$Icepick" ["package test;" "import android.os.Bundle;" "import android.os.Parcelable;" "import icepick.Injector.Helper;" "import icepick.Injector.View;" - "public class Test$$Icicle extends View {" - " private final static Helper H = new Helper(\"test.Test$$Icicle.\");" + "public class Test$$Icepick extends View {" + " private final static Helper H = new Helper(\"test.Test$$Icepick.\");" " public Parcelable restore(T target, Parcelable p) {" " Bundle state = (Bundle) p;" " target.f1 = H.getParcelable(state, \"f1\");" @@ -308,14 +308,14 @@ " return state;" " }" "}"]] - ["test.Test$Inner$$Icicle" + ["test.Test$Inner$$Icepick" ["package test;" "import android.os.Bundle;" "import android.os.Parcelable;" "import icepick.Injector.Helper;" "import icepick.Injector.View;" - "public class Test$Inner$$Icicle extends test.Test$$Icicle {" - " private final static Helper H = new Helper(\"test.Test$Inner$$Icicle.\");" + "public class Test$Inner$$Icepick extends test.Test$$Icepick {" + " private final static Helper H = new Helper(\"test.Test$Inner$$Icepick.\");" " public Parcelable restore(T target, Parcelable p) {" " Bundle state = (Bundle) p;" " target.f2 = H.getString(state, \"f2\");" diff --git a/icepick/src/icepick/Icepick.java b/icepick/src/icepick/Icepick.java index 0bafd11..f2b6a99 100644 --- a/icepick/src/icepick/Icepick.java +++ b/icepick/src/icepick/Icepick.java @@ -9,7 +9,7 @@ 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 JAVA_PREFIX = "java."; diff --git a/icepick/src/icepick/Icicle.java b/icepick/src/icepick/State.java similarity index 90% rename from icepick/src/icepick/Icicle.java rename to icepick/src/icepick/State.java index b81aa48..25626b6 100644 --- a/icepick/src/icepick/Icicle.java +++ b/icepick/src/icepick/State.java @@ -7,5 +7,5 @@ @Target(ElementType.FIELD) @Retention(RetentionPolicy.CLASS) -public @interface Icicle { +public @interface State { } diff --git a/sample/app/src/main/java/com/github/frankiesardo/icepick/CustomView.java b/sample/app/src/main/java/com/github/frankiesardo/icepick/CustomView.java index 89bd523..57cbc3e 100644 --- a/sample/app/src/main/java/com/github/frankiesardo/icepick/CustomView.java +++ b/sample/app/src/main/java/com/github/frankiesardo/icepick/CustomView.java @@ -4,11 +4,11 @@ import android.os.Parcelable; import android.util.AttributeSet; import com.sample.icepick.lib.BaseCustomView; -import icepick.Icicle; +import icepick.State; public class CustomView extends BaseCustomView { - @Icicle Integer textColor; + @State Integer textColor; public CustomView(Context context) { super(context); diff --git a/sample/app/src/main/java/com/github/frankiesardo/icepick/MainActivity.java b/sample/app/src/main/java/com/github/frankiesardo/icepick/MainActivity.java index 6b13b01..1dadcba 100644 --- a/sample/app/src/main/java/com/github/frankiesardo/icepick/MainActivity.java +++ b/sample/app/src/main/java/com/github/frankiesardo/icepick/MainActivity.java @@ -5,11 +5,11 @@ import android.view.Menu; import android.view.MenuItem; import com.sample.icepick.lib.BaseActivity; -import icepick.Icicle; +import icepick.State; public class MainActivity extends BaseActivity { - @Icicle String message; + @State String message; CustomView customView; diff --git a/sample/lib/src/main/java/com/sample/icepick/lib/BaseActivity.java b/sample/lib/src/main/java/com/sample/icepick/lib/BaseActivity.java index 0c3471e..328860b 100644 --- a/sample/lib/src/main/java/com/sample/icepick/lib/BaseActivity.java +++ b/sample/lib/src/main/java/com/sample/icepick/lib/BaseActivity.java @@ -4,11 +4,11 @@ import android.os.Bundle; import android.os.Parcelable; import icepick.Icepick; -import icepick.Icicle; +import icepick.State; import android.util.Log; public class BaseActivity extends Activity { - @Icicle protected String baseMessage; + @State protected String baseMessage; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/sample/lib/src/main/java/com/sample/icepick/lib/BaseCustomView.java b/sample/lib/src/main/java/com/sample/icepick/lib/BaseCustomView.java index bfbf119..81d7ab4 100644 --- a/sample/lib/src/main/java/com/sample/icepick/lib/BaseCustomView.java +++ b/sample/lib/src/main/java/com/sample/icepick/lib/BaseCustomView.java @@ -5,11 +5,11 @@ import android.util.AttributeSet; import android.widget.TextView; import icepick.Icepick; -import icepick.Icicle; +import icepick.State; public class BaseCustomView extends TextView { - @Icicle protected Integer backgroundColor; + @State protected Integer backgroundColor; public BaseCustomView(Context context) { super(context); diff --git a/sample/local.properties b/sample/local.properties index 9d3b47b..5fa01bb 100644 --- a/sample/local.properties +++ b/sample/local.properties @@ -7,5 +7,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Thu Aug 28 19:37:17 BST 2014 -sdk.dir=/usr/local/Cellar/android-sdk/r21.0.1 +#Wed Jul 22 23:37:14 BST 2015 +sdk.dir=/Users/frankie/Library/Android/sdk diff --git a/sample/sample.iml b/sample/sample.iml new file mode 100644 index 0000000..397f459 --- /dev/null +++ b/sample/sample.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file