ConstructorBlockBuilder<?> ctor = classBuilder.publicConstructor();
final Collection<MetaClass> pages = ClassScanner.getTypesAnnotatedWith(Page.class, context);
for (MetaClass pageClass : pages) {
if (!pageClass.isAssignableTo(IsWidget.class)) {
throw new GenerationException(
"Class " + pageClass.getFullyQualifiedName() + " is annotated with @Page, so it must implement IsWidget");
}
Page annotation = pageClass.getAnnotation(Page.class);
String pageName = getPageName(pageClass);
List<Class<? extends PageRole>> annotatedPageRoles = Arrays.asList(annotation.role());
MetaClass prevPageWithThisName = pageNames.put(pageName, pageClass);
if (prevPageWithThisName != null) {
throw new GenerationException(
"Page names must be unique, but " + prevPageWithThisName + " and " + pageClass +
" are both named [" + pageName + "]");
}
Statement pageImplStmt = generateNewInstanceOfPageImpl(pageClass, pageName);
if (annotatedPageRoles.contains(DefaultPage.class)) {
// need to assign the page impl to a variable and add it to the map twice
ctor.append(Stmt.declareFinalVariable("defaultPage", PageNode.class, pageImplStmt));
pageImplStmt = Variable.get("defaultPage");
ctor.append(
Stmt.nestedCall(Refs.get("pagesByName"))
.invoke("put", "", pageImplStmt));
ctor.append(
Stmt.nestedCall(Refs.get("pagesByRole"))
.invoke("put", DefaultPage.class, pageImplStmt));
}
else if (pageName.equals("")) {
throw new GenerationException(
"Page " + pageClass.getFullyQualifiedName() + " has an empty path. Only the" +
" page with startingPage=true is permitted to have an empty path.");
}
final String fieldName = StringUtils.uncapitalize(pageClass.getName());