Search in sources :

Example 1 with AsyncColumn

use of org.jboss.hal.spi.AsyncColumn in project console by hal.

the class RequiredResourcesProcessor method onProcess.

@Override
protected boolean onProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getElementsAnnotatedWith(Requires.class)) {
        TypeElement requiredElement = (TypeElement) e;
        Requires requires = requiredElement.getAnnotation(Requires.class);
        // Get the related id. Currently @Requires can be placed at named proxies or (async) columns
        String id = null;
        NameToken token = requiredElement.getAnnotation(NameToken.class);
        if (token != null) {
            id = token.value()[0];
        } else {
            AsyncColumn asyncColumn = requiredElement.getAnnotation(AsyncColumn.class);
            if (asyncColumn != null) {
                id = asyncColumn.value();
            } else {
                Column column = requiredElement.getAnnotation(Column.class);
                if (column != null) {
                    id = column.value();
                }
            }
        }
        // noinspection ConstantConditions
        if (id != null) {
            RequiredInfo requiredInfo = new RequiredInfo(id, requiredElement);
            requiredInfo.addResources(requires.value());
            requiredInfo.setRecursive(requires.recursive());
            if (requiredInfos.containsKey(id)) {
                RequiredInfo other = requiredInfos.get(id);
                if (!requiredInfo.getResources().equals(other.getResources())) {
                    error(requiredElement, "Different required resources for the same id \"%s\". This class conflicts with %s", id, other.source.getQualifiedName());
                }
            }
            requiredInfos.put(id, requiredInfo);
        }
    }
    if (!requiredInfos.isEmpty()) {
        debug("Generating code for required resources registry");
        code(REQUIRED_RESOURCES_TEMPLATE, REQUIRED_RESOURCES_PACKAGE, REQUIRED_RESOURCES_CLASS, context(REQUIRED_RESOURCES_PACKAGE, REQUIRED_RESOURCES_CLASS));
        List<RegistryBinding> bindings = ImmutableList.of(new RegistryBinding(REQUIRED_RESOURCES_PACKAGE + ".RequiredResources", REQUIRED_RESOURCES_PACKAGE + "." + REQUIRED_RESOURCES_CLASS));
        debug("Generating code for registry module");
        code(REGISTRY_MODULE_TEMPLATE, REGISTRY_MODULE_PACKAGE, REGISTRY_MODULE_CLASS, () -> {
            Map<String, Object> context = new HashMap<>();
            context.put(GENERATED_WITH, RequiredResourcesProcessor.class.getName());
            context.put(PACKAGE_NAME, REGISTRY_MODULE_PACKAGE);
            context.put(CLASS_NAME, REGISTRY_MODULE_CLASS);
            context.put("bindings", bindings);
            return context;
        });
        info("Successfully generated required resources registry [%s] and related module [%s].", REQUIRED_RESOURCES_CLASS, REGISTRY_MODULE_CLASS);
        requiredInfos.clear();
    }
    return false;
}
Also used : Requires(org.jboss.hal.spi.Requires) HashMap(java.util.HashMap) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) AsyncColumn(org.jboss.hal.spi.AsyncColumn) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) AsyncColumn(org.jboss.hal.spi.AsyncColumn) Column(org.jboss.hal.spi.Column)

Example 2 with AsyncColumn

use of org.jboss.hal.spi.AsyncColumn in project console by hal.

the class ColumnRegistrationProcessor method columnInfo.

private ColumnInfo columnInfo(TypeElement element, boolean async) {
    String columnClass = element.getQualifiedName().toString();
    String id;
    if (async) {
        AsyncColumn asyncColumn = element.getAnnotation(AsyncColumn.class);
        id = asyncColumn.value();
    } else {
        Column asyncColumn = element.getAnnotation(Column.class);
        id = asyncColumn.value();
    }
    return new ColumnInfo(columnClass, id, async);
}
Also used : AsyncColumn(org.jboss.hal.spi.AsyncColumn) Column(org.jboss.hal.spi.Column) AsyncColumn(org.jboss.hal.spi.AsyncColumn)

Aggregations

AsyncColumn (org.jboss.hal.spi.AsyncColumn)2 Column (org.jboss.hal.spi.Column)2 NameToken (com.gwtplatform.mvp.client.annotations.NameToken)1 HashMap (java.util.HashMap)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 Requires (org.jboss.hal.spi.Requires)1