//  [java]
    public void write(SourceWriter w) {
        // class header
        String packageName = "it.geosolutions.jaiext.jiffle.runtime";
        w.line("package " + packageName + ";");
        w.newLine();
        w.line("import java.util.List;");
        w.line("import java.util.ArrayList;");
        w.line("import java.util.Arrays;");
        w.newLine();

        // add the script source, if available
        String script = w.getScript();
        if (script != null) {
            String[] lines = script.split("\n");
            w.line("/**");
            w.line(" * Java runtime class generated from the following Jiffle script: ");
            w.line(" *<code>");
            for (String line : lines) {
                w.append(" * ").append(line).newLine();
            }
            w.line(" *</code>");
            w.line(" */");
        }

        // class declaration
        String template = "public class %s extends %s {";
        String className;
        Jiffle.RuntimeModel model = w.getRuntimeModel();
        if (model == Jiffle.RuntimeModel.DIRECT) {
            className = "JiffleDirectRuntimeImpl";
        } else {
            className = "JiffleIndirectRuntimeImpl";
        }
        w.line(format(template, className, w.getBaseClassName()));

        // writing class fields
        w.inc();
        // ... if we are using a internal class, dodge map lookups while working on pixels
        if (w.isInternalBaseClass()) {
            for (String sourceImage : sourceImages) {
                w.indent().append("SourceImage s_").append(sourceImage).append(";").newLine();
            }
            if (model == Jiffle.RuntimeModel.DIRECT) {
                for (String destImage : destImages) {
                    w.indent()
                            .append("DestinationImage d_")
                            .append(destImage)
                            .append(";")
                            .newLine();
                }
            }
        }
        globals.writeFields(w);
        w.newLine();

        // adding the constructor
        w.indent().append("public ").append(className).append("() {").newLine();
        w.inc();
        w.indent().append("super(new String[] {");
        globals.listNames(w);
        w.append("});").newLine();
        w.dec();
        w.line("}");
        w.newLine();

        // add the options init, if required
        if (options != null && !options.isEmpty()) {
            w.line("protected void initOptionVars() {");
            w.inc();
            for (Map.Entry<String, String> entry : options.entrySet()) {
                String name = entry.getKey();
                String value = entry.getValue();
                try {
                    String activeExpr = OptionLookup.getActiveRuntimExpr(name, value);
                    w.line(activeExpr);
                } catch (UndefinedOptionException e) {
                    throw new JiffleParserException(e);
                }
            }
            w.dec();
            w.line("}");
        }

        // and field initializer method
        w.line("protected void initImageScopeVars() {");
        w.inc();
        if (w.isInternalBaseClass()) {
            for (String sourceImage : sourceImages) {
                w.indent()
                        .append("s_")
                        .append(sourceImage)
                        .append(" = (SourceImage) _images.get(\"")
                        .append(sourceImage)
                        .append("\");")
                        .newLine();
            }
            if (model == Jiffle.RuntimeModel.DIRECT) {
                for (String destImage : destImages) {
                    w.indent()
                            .append("d_")
                            .append(destImage)
                            .append("= (DestinationImage) _destImages.get(\"")
                            .append(destImage)
                            .append("\");")
                            .newLine();
                }
            }
        }
        globals.write(w);
        w.line("_imageScopeVarsInitialized = true;");
        w.dec();
        w.line("}");
        w.newLine();

        // the evaluate method
        if (model == Jiffle.RuntimeModel.DIRECT) {
            w.line("public void evaluate(double _x, double _y) {");
        } else {
            w.line("public void evaluate(double _x, double _y, double[] result) {");
        }
        w.inc();

        // basic checks at the beginning of pixel evaluation
        w.line("if (!isWorldSet()) {");
        w.inc();
        w.line("setDefaultBounds();");
        w.dec();
        w.line("}");
        w.line("if (!_imageScopeVarsInitialized) {");
        w.inc();
        w.line("initImageScopeVars();");
        w.dec();
        w.line("}");
        w.line("_stk.clear();");

        // centralize the source reads to avoid repeated reads
        readOptimizer.declareRepeatedReads(w);

        // the actual script
        w.newLine();
        stmts.write(w);

        w.dec();
        w.line("}");

        // closing class
        w.dec();
        w.line("}");
    }