Skip to content

Commit e0fec2d

Browse files
committed
Version 1.2.1: Fixed bug with @InjectViews
Uploaded better version of 'Person' class
1 parent fa9d9a0 commit e0fec2d

File tree

6 files changed

+36
-67
lines changed

6 files changed

+36
-67
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog:
22

33
### Versions:
4+
* **1.2.1** - Fixed bug on @InjectViews annotation and uploaded a new Person class version using @Parcelable.
45
* **1.2.0** - Added @Parcelable annotation and DSL methods.
56
* **1.1.4** - Fixed another minor bug with primitives.
67
* **1.1.3** - Fixed minor bug where methods with primitive parameters weren't found on method search.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Once your project App Module is configured to use Groovy you can add this librar
8585
```groovy
8686
dependencies {
8787
...
88-
compile 'com.arasthel:swissknife:1.2.0'
88+
compile 'com.arasthel:swissknife:1.2.1'
8989
...
9090
}
9191
```

SwissKnife/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 8
99
targetSdkVersion 21
1010
versionCode 1
11-
versionName "1.2.0"
11+
versionName "1.2.1"
1212
}
1313

1414
packagingOptions {

SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectViewsTransformation.groovy

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.codehaus.groovy.ast.*
77
import org.codehaus.groovy.ast.builder.AstBuilder
88
import org.codehaus.groovy.ast.expr.ListExpression
99
import org.codehaus.groovy.ast.stmt.BlockStatement
10+
import org.codehaus.groovy.ast.stmt.ExpressionStatement
1011
import org.codehaus.groovy.ast.stmt.Statement
1112
import org.codehaus.groovy.control.CompilePhase
1213
import org.codehaus.groovy.control.SourceUnit
@@ -29,7 +30,7 @@ public class InjectViewsTransformation implements ASTTransformation, Opcodes {
2930

3031
def ids = [];
3132

32-
Class fieldClass = annotatedField.getType();
33+
ClassNode fieldClass = annotatedField.getType();
3334

3435
if(!AnnotationUtils.isSubtype(fieldClass, List.class)) {
3536
throw new Exception("The annotated field must extend List. Type: $fieldClass.name");
@@ -50,18 +51,20 @@ public class InjectViewsTransformation implements ASTTransformation, Opcodes {
5051

5152
List<Statement> statementList = ((BlockStatement) injectMethod.getCode()).getStatements();
5253

53-
statementList.add(createViewListStatement());
54+
statementList.add(createViewListStatement(annotatedField));
5455

55-
ids.each { statementList.add(createInjectViewStatement(it)); }
56+
ids.each { statementList.add(createInjectViewStatement(annotatedField, it)); }
5657

57-
statementList.add(createFieldAssignStatement(annotatedField));
5858
}
5959

60-
private Statement createViewListStatement() {
60+
private Statement createViewListStatement(FieldNode field) {
6161
return new AstBuilder().buildFromSpec {
6262
expression{
63-
declaration {
64-
variable "views"
63+
binary {
64+
property {
65+
variable "this"
66+
constant field.name
67+
}
6568
token "="
6669
constructorCall(ArrayList.class) {
6770
argumentList {}
@@ -71,38 +74,31 @@ public class InjectViewsTransformation implements ASTTransformation, Opcodes {
7174
}[0];
7275
}
7376

74-
private Statement createInjectViewStatement(String id) {
77+
private Statement createInjectViewStatement(FieldNode field, String id) {
78+
79+
ExpressionStatement injectStatement = AnnotationUtils.createInjectExpression(id)
7580

76-
def statement =
81+
BlockStatement blockStatement = new BlockStatement()
82+
83+
ExpressionStatement addToListExpression =
7784
new AstBuilder().buildFromSpec {
78-
block {
7985
expression {
80-
binary {
81-
variable "views"
82-
token "<<"
83-
staticMethodCall(Finder.class, "findView") {
84-
argumentList {
85-
variable "view"
86-
constant id
87-
}
86+
methodCall {
87+
property {
88+
variable "this"
89+
constant field.name
90+
}
91+
constant "add"
92+
argumentList {
93+
variable "v"
8894
}
8995
}
9096
}
91-
}
9297
}[0];
9398

94-
return statement;
95-
}
99+
blockStatement.addStatement(injectStatement)
100+
blockStatement.addStatement(addToListExpression)
96101

97-
private Statement createFieldAssignStatement(FieldNode field) {
98-
return new AstBuilder().buildFromSpec {
99-
expression {
100-
binary {
101-
variable field.name
102-
token "="
103-
variable "views"
104-
}
105-
}
106-
}[0]
102+
return blockStatement;
107103
}
108104
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919

20-
VERSION_NAME=1.2.0
20+
VERSION_NAME=1.2.1
2121
VERSION_CODE=11
2222
GROUP=com.arasthel
2323

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package com.dexafree.sample;
1+
package com.dexafree.sample
22

3-
4-
import android.os.Parcel;
5-
import android.os.Parcelable
3+
import com.arasthel.swissknife.annotations.Parcelable;
64
import groovy.transform.CompileStatic;
75

8-
9-
public class Person implements Parcelable {
6+
@Parcelable
7+
@CompileStatic
8+
public class Person {
109

1110
private String name;
1211
private int age;
@@ -27,38 +26,11 @@ public class Person implements Parcelable {
2726
this.age = age;
2827
}
2928

30-
31-
@Override
32-
public int describeContents() {
33-
return 0;
34-
}
35-
36-
@Override
37-
public void writeToParcel(Parcel dest, int flags) {
38-
dest.writeString(this.name);
39-
dest.writeInt(this.age);
40-
}
41-
4229
public Person() {
4330
}
4431

4532
public Person(String name, int age){
4633
this.name = name;
4734
this.age = age;
4835
}
49-
50-
private Person(Parcel parcel) {
51-
this.name = parcel.readString();
52-
this.age = parcel.readInt();
53-
}
54-
55-
public static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {
56-
public Person createFromParcel(Parcel source) {
57-
return new Person(source);
58-
}
59-
60-
public Person[] newArray(int size) {
61-
return new Person[size];
62-
}
63-
};
6436
}

0 commit comments

Comments
 (0)