Skip to content

Commit 190fe51

Browse files
committed
[anno] [change error with Json&di in apt ]
1 parent 6ed700e commit 190fe51

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

router-anno-compiler/src/main/java/com/ljsw/router/compiler/processor/AutowiredProcessor.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ public class AutowiredProcessor extends AbstractProcessor {
7171
*/
7272
private Map<TypeElement, List<Element>> parentAndChild = new HashMap<>();
7373

74-
//UIRouter:com.mrzhang.component.componentlib.router.ui.UIRouter
75-
private static final ClassName UIRouterClass =
76-
ClassName.get("com.mrzhang.component.componentlib.router.ui", "UIRouter");
74+
// private static final ClassName UIRouterClass =
75+
// ClassName.get("com.mrzhang.component.componentlib.router.ui", "UIRouter");
76+
//
77+
// private static final ClassName RouterClass =
78+
// ClassName.get("com.mrzhang.component.componentlib.router", "Router");
7779

78-
private static final ClassName RouterClass =
79-
ClassName.get("com.mrzhang.component.componentlib.router", "Router");
80+
private static final ClassName JsonServiceInterface =
81+
ClassName.get("com.ljsw.component.json","JsonService");
8082

8183
// private static final ClassName ARouterClass = ClassName.get("com.alibaba.android.arouter.launcher", "ARouter");
8284
private static final ClassName AndroidLog = ClassName.get("android.util", "Log");
@@ -163,26 +165,18 @@ private void generateHelper() throws IOException, IllegalAccessException {
163165

164166
logger.info("======== inject jsonservice");
165167

166-
injectMethodBuilder.addStatement("$T router = $T.getInstance()",
167-
RouterClass,
168-
RouterClass);
169-
170-
injectMethodBuilder.beginControlFlow("if (router.getService($T.class.getSimpleName()) != null)",
171-
ClassName.get(type_JsonService));
172-
173-
injectMethodBuilder.addStatement("jsonService = ($T) router.getService($T.class.getSimpleName())",
174-
ClassName.get(type_JsonService),
175-
ClassName.get(type_JsonService));
176-
177-
178-
injectMethodBuilder.endControlFlow();
179-
180-
// injectMethodBuilder.addStatement(_statement,
181-
// RouterClass,
168+
// injectMethodBuilder.addStatement("$T router = $T.getInstance()",
182169
// RouterClass,
183-
// ClassName.get(type_JsonService),
170+
// RouterClass);
171+
// injectMethodBuilder.beginControlFlow("if (router.getService($T.class.getSimpleName()) != null)",
172+
// ClassName.get(type_JsonService));
173+
// injectMethodBuilder.addStatement("jsonService = ($T) router.getService($T.class.getSimpleName())",
184174
// ClassName.get(type_JsonService),
185175
// ClassName.get(type_JsonService));
176+
// injectMethodBuilder.endControlFlow();
177+
178+
injectMethodBuilder.addStatement("jsonService = $T.Factory.getInstance().create()",
179+
ClassName.get(type_JsonService));
186180

187181
injectMethodBuilder.addStatement("$T substitute = ($T)target", ClassName.get(parent), ClassName.get(parent));
188182

router-anno-compiler/src/main/java/com/ljsw/router/compiler/utils/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public interface Constants {
4343
String BOOLEAN = LANG + ".Boolean";
4444
String STRING = LANG + ".String";
4545

46-
String ISYRINGE = "com.mrzhang.component.componentlib.router.facade.ISyringe";
46+
String ISYRINGE = "com.ljsw.component.di.route.ISyringe";
4747

48-
String JSON_SERVICE = "com.mrzhang.componentservice.json.JsonService";
48+
String JSON_SERVICE = "com.ljsw.component.json.JsonService";
4949

5050
String ROUTER_UTIL_METHOD_ADDTO = "addTo";
5151

sharecomponent/src/main/java/com/mrzhang/share/ShareActivity.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.ljsw.component.json.JsonService;
1111
import com.ljsw.router.facade.annotation.Autowired;
1212
import com.ljsw.router.facade.annotation.RouteNode;
13-
import com.mrzhang.component.componentlib.router.Router;
1413

1514
/**
1615
* Created by mrzhang on 2017/6/20.
@@ -39,24 +38,19 @@ public void setS(String s) {
3938
TestDto testDto;
4039

4140
private JsonService jsonService = JsonService.Factory.getInstance().create();
41+
private AutowiredService autowiredService = AutowiredService.Factory.getInstance().create();
4242

4343
@Override
4444
protected void onCreate(@Nullable Bundle savedInstanceState) {
4545
super.onCreate(savedInstanceState);
4646
setContentView(R.layout.share_activity_share);
47-
// UIRouter.getInstance().inject
48-
49-
Router router = Router.getInstance();
50-
// if (router.getService(AutowiredService.class.getSimpleName()) != null) {
51-
// AutowiredService service = (AutowiredService) router.getService(AutowiredService.class.getSimpleName());
52-
// service.autowire(this);
53-
// }
47+
autowiredService.autowire(this);
5448

5549

5650
TextView textView = (TextView) findViewById(R.id.share_tv_tag);
5751
textView.setText("share: " + bookName);
5852

59-
Log.d(TAG,"dto:\r"+(jsonService.toJsonString(testDto));
53+
Log.d(TAG, "dto:\r" + (jsonService.toJsonString(testDto)));
6054

6155
}
6256

0 commit comments

Comments
 (0)