Skip to content

Commit 59519dd

Browse files
author
Francesco Cannizzaro
committed
add AfterBind Annotation
1 parent 9b63bae commit 59519dd

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

.idea/misc.xml

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Add the JitPack repository to your build file
2323
Add the dependency
2424
```gradle
2525
dependencies {
26-
compile 'com.github.fcannizzaro:jsoup-annotations:1.0.1'
26+
compile 'com.github.fcannizzaro:jsoup-annotations:1.0.2'
2727
}
2828
```
2929

@@ -90,6 +90,14 @@ void iterate(Element element, int index){
9090
}
9191
```
9292

93+
## @AfterBind
94+
```java
95+
@AfterBind
96+
void attached(){
97+
// called after object binding is completed.
98+
}
99+
```
100+
93101
## @Child
94102
Denote **Field** as child element (POJO).
95103

app/src/main/java/com/fcannizzaro/jsoup/sample/model/NPM.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fcannizzaro.jsoup.sample.model;
22

3+
import com.fcannizzaro.jsoup.annotations.interfaces.AfterBind;
34
import com.fcannizzaro.jsoup.annotations.interfaces.Items;
45

56
import java.util.List;
@@ -13,4 +14,9 @@ public class NPM {
1314
@Items
1415
public List<Package> packages;
1516

17+
@AfterBind
18+
void attached() {
19+
System.out.println("[attached] " + packages);
20+
}
21+
1622
}

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 10
99
targetSdkVersion 25
1010
versionCode 1
11-
versionName "1.0.1"
11+
versionName "1.0.2"
1212
}
1313
buildTypes {
1414
release {

library/src/main/java/com/fcannizzaro/jsoup/annotations/JsoupProcessor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fcannizzaro.jsoup.annotations;
22

3+
import com.fcannizzaro.jsoup.annotations.interfaces.AfterBind;
34
import com.fcannizzaro.jsoup.annotations.interfaces.Attr;
45
import com.fcannizzaro.jsoup.annotations.interfaces.Child;
56
import com.fcannizzaro.jsoup.annotations.interfaces.ForEach;
@@ -106,11 +107,16 @@ public static <T> T from(Element container, Class<T> clazz) {
106107

107108
}
108109

110+
Method afterBindMethod = null;
111+
109112
for (Method method : clazz.getMethods()) {
110113

111114
ForEach forEach = method.getAnnotation(ForEach.class);
115+
AfterBind afterBind = method.getAnnotation(AfterBind.class);
112116

113-
if (forEach != null) {
117+
if (afterBind != null) {
118+
afterBindMethod = method;
119+
} else if (forEach != null) {
114120

115121
method.setAccessible(true);
116122

@@ -133,6 +139,10 @@ public static <T> T from(Element container, Class<T> clazz) {
133139

134140
}
135141

142+
if (afterBindMethod != null) {
143+
afterBindMethod.invoke(instance);
144+
}
145+
136146
return instance;
137147

138148
} catch (Exception e) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.fcannizzaro.jsoup.annotations.interfaces;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Created by Francesco Cannizzaro (fcannizzaro)
10+
*/
11+
12+
@Retention(RetentionPolicy.RUNTIME)
13+
@Target(ElementType.METHOD)
14+
public @interface AfterBind {
15+
}

0 commit comments

Comments
 (0)