@@ -71,7 +71,13 @@ public class RouterProcessor extends AbstractProcessor {
7171 private Types types ;
7272 private Elements elements ;
7373
74+ /**
75+ * (group,hostInfo)
76+ */
7477 private Map <String , HostInfo > routers ;
78+ /**
79+ * (group,List(Node))
80+ */
7581 private Map <String , List <Node >> routerNodes ;
7682
7783 private TypeMirror type_TextUtils ;
@@ -141,58 +147,6 @@ public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnv
141147 return false ;
142148 }
143149
144- // @Deprecated
145- // private void write2Util() {
146- // Set<String> groups = routers.keySet();
147- //
148- // ClassName type_UiRouterLoader = ClassName.get(elements.getTypeElement(TYPE_UIROUTER_LOADER));
149- // for (String group : groups) {
150- // logger.info(">>> write for group:" + group);
151- //
152- // TypeMirror value = routers.get(group);
153- // String path = value.toString();
154- //
155- // String pkg = path.substring(0, path.lastIndexOf("."));
156- // String cn = path.substring(path.lastIndexOf(".") + 1) + "Loader";
157- //
158- // ParameterizedTypeName inputMapTypeOfGroup = ParameterizedTypeName.get(
159- // ClassName.get(Map.class),
160- // ClassName.get(String.class),
161- // ClassName.get(Class.class)
162- // );
163- //
164- // ParameterSpec groupParamSpec =
165- // ParameterSpec.builder(inputMapTypeOfGroup, "mapper").build();
166- //
167- //
168- // MethodSpec.Builder loadIntoMethodOfRootBuilder =
169- // MethodSpec.methodBuilder(ROUTER_UTIL_METHOD_ADDTO)
170- // .addParameter(groupParamSpec)
171- // .addAnnotation(Override.class)
172- // .addModifiers(PUBLIC);
173- //
174- // List<Node> nodes = routerNodes.get(group);
175- // for (Node node : nodes) {
176- // loadIntoMethodOfRootBuilder.addStatement(
177- // "mapper.put($S,$T.class)",
178- // node.getPath(),
179- // ClassName.get((TypeElement) node.getRawType()));
180- // }
181- //
182- //
183- // try {
184- // JavaFile.builder(pkg, TypeSpec.classBuilder(cn)
185- // .addModifiers(PUBLIC)
186- // .addSuperinterface(type_UiRouterLoader)
187- // .addMethod(loadIntoMethodOfRootBuilder.build())
188- // .build()
189- // ).build().writeTo(mFiler);
190- // } catch (IOException e) {
191- // e.printStackTrace();
192- // }
193- // }
194- // }
195-
196150 private void generateRouterImpl () {
197151 Set <String > groups = routers .keySet ();
198152
@@ -255,6 +209,8 @@ private void parseRouteNodes(Set<? extends Element> routeElements) {
255209
256210 TypeMirror type_Activity = elements .getTypeElement (ACTIVITY ).asType ();
257211
212+ Map <String , List <String >> cacheForConflictCheck = new HashMap <>();
213+
258214 for (Element element : routeElements ) {
259215 TypeMirror tm = element .asType ();
260216 RouteNode route = element .getAnnotation (RouteNode .class );
@@ -263,9 +219,23 @@ private void parseRouteNodes(Set<? extends Element> routeElements) {
263219 logger .info (">>> Found activity route: " + tm .toString () + " <<<" );
264220
265221 String group = route .group ();
222+ List <String > groupPaths ;
223+
224+ if (cacheForConflictCheck .containsKey (group )) {
225+ groupPaths = cacheForConflictCheck .get (group );
226+ } else {
227+ groupPaths = new ArrayList <>();
228+ cacheForConflictCheck .put (group , groupPaths );
229+ }
266230
267231 Node node = new Node ();
268- node .setPath (route .path ());
232+ String path = route .path ();
233+
234+ checkPath (group , path , groupPaths );
235+
236+ groupPaths .add (path );
237+
238+ node .setPath (path );
269239 node .setPriority (route .priority ());
270240 node .setNodeType (NodeType .ACTIVITY );
271241 node .setRawType (element );
@@ -283,6 +253,21 @@ private void parseRouteNodes(Set<? extends Element> routeElements) {
283253 }
284254 }
285255
256+ private void checkPath (String group , String path , List <String > groupPaths ) {
257+ if (groupPaths .contains (path ))
258+ throw new IllegalStateException ("conflict path in group:" + group + ",path is:" + path );
259+
260+ if (path == null || path .isEmpty () || !path .startsWith ("/" ))
261+ throw new IllegalArgumentException ("path cannot be null or empty,and should start with /,this is:" + path );
262+
263+ if (path .contains ("//" ) || path .contains ("&" ) || path .contains ("?" ))
264+ throw new IllegalArgumentException ("path should not contain // ,& or ?,this is:" + path );
265+
266+ if (path .endsWith ("/" ))
267+ throw new IllegalArgumentException ("path should not endWith /,this is:" + path
268+ + ";or append a token:index" );
269+ }
270+
286271 private void foundRouters (Set <? extends Element > routers ) {
287272 for (Element element : routers ) {
288273 Router router = element .getAnnotation (Router .class );
@@ -517,4 +502,5 @@ private MethodSpec generateVerify() {
517502 return openUriMethodSpecBuilder .build ();
518503 }
519504
505+
520506}
0 commit comments