Search in sources :

Example 1 with CheckVisitor

use of org.stjs.generator.check.CheckVisitor in project st-js by st-js.

the class GenerationPlugins method forClass.

/**
 * <p>forClass.</p>
 *
 * @param clazz a {@link java.lang.Class} object.
 * @return a {@link org.stjs.generator.plugin.GenerationPlugins} object.
 */
@SuppressWarnings("unchecked")
public GenerationPlugins<JS> forClass(Class<?> clazz) {
    UsePlugin usePlugins = clazz.getAnnotation(UsePlugin.class);
    if (usePlugins == null || usePlugins.value() == null || usePlugins.value().length == 0) {
        // this class uses the default plugins - no need to create a new one
        return this;
    }
    // TODO - here I can add a cache using the list of plugin names as key
    GenerationPlugins<JS> newPlugins = new GenerationPlugins<JS>();
    newPlugins.checkVisitor = new CheckVisitor(checkVisitor);
    newPlugins.writerVisitor = new WriterVisitor<JS>(writerVisitor);
    for (String pluginName : usePlugins.value()) {
        STJSGenerationPlugin<JS> plugin = optionalPlugins.get(pluginName);
        if (plugin == null) {
            throw new STJSRuntimeException("The class:" + clazz.getName() + " need an unknown Generation Plugin :" + pluginName);
        }
        plugin.contributeCheckVisitor(newPlugins.checkVisitor);
        plugin.contributeWriteVisitor(newPlugins.writerVisitor);
    }
    return newPlugins;
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) CheckVisitor(org.stjs.generator.check.CheckVisitor) UsePlugin(org.stjs.javascript.annotation.UsePlugin)

Aggregations

STJSRuntimeException (org.stjs.generator.STJSRuntimeException)1 CheckVisitor (org.stjs.generator.check.CheckVisitor)1 UsePlugin (org.stjs.javascript.annotation.UsePlugin)1