raven-compiler/src/main/java/org/raven/compiler/Compiler.java
/**
     * Places any non-static fields and functions into a synthetic class with
     * the same name as the containing file. Adds class initializer to any
     * class that does not have one.
     *
     * @param tree The ast
     */
Places any non-static fields and functions into a synthetic class with
the same name as the containing file. Adds class initializer to any
class that does not have one.

@param tree The ast
Places any non - static fields and functions into a synthetic class with the same name as the containing file . Adds class initializer to any class that does not have one . @param tree The ast
private void modifyTree(final RavenTree tree) {
        String className = tree.getPackage().add(tree.getName().toString()).toString().replace(".", "/");
        ClassDef def = tree.getClasses().stream().filter(cd -> cd.getFullName().equals(className)).findFirst().orElse(
                new ClassDef(new Modifier[]{Modifier.PUBLIC}, tree.getPackage(), tree.getName().toString(),
                        new QualifiedName("java", "lang", "Object"), new QualifiedName[0], new ArrayList<>())
        );
        Block b = new Block();
        Fun clinit = new Fun(new QualifiedName("<clinit>"), b, new Modifier[]{Modifier.STATIC}, null);
        for (Statement statement : tree.getStatements()) {
            if (statement instanceof VarDecl) {
                VarDecl decl = (VarDecl) statement;
                decl.addModifier(Modifier.STATIC);
                def.getStatements().add(statement);
                b.append(new BinOp(decl.getName(), Operator.ASSIGNMENT, decl.getInitialValue()));
            } else {
                b.append(statement);
            }
            statement.setParent(def);
        }
        for (Fun fun : tree.getFunctions()) {
            fun.addModifier(Modifier.STATIC);
            def.getStatements().add(fun);
            fun.setParent(def);
        }
        def.getStatements().add(clinit);
        tree.addClass(def);
        for (ClassDef classDef : tree.getClasses()) {
            classDef.setPackage(tree.getPackage());
            if (!classDef.equals(def)) {
                clinit = new Fun(new QualifiedName("<clinit>"), new Block(), new Modifier[]{Modifier.STATIC}, null);
                classDef.getStatements().add(clinit);
            }
        }
    }
private void modifyTree ( final RavenTree tree ) { String className = tree . getPackage ( ) . add ( tree . getName ( ) . toString ( ) ) . toString ( ) . replace ( "." , "/" ) ; ClassDef def = tree . getClasses ( ) . stream ( ) . filter ( cd -> cd . getFullName ( ) . equals ( className ) ) . findFirst ( ) . orElse ( new ClassDef ( new Modifier [ ] { Modifier . PUBLIC } , tree . getPackage ( ) , tree . getName ( ) . toString ( ) , new QualifiedName ( "java" , "lang" , "Object" ) , new QualifiedName [ 0 ] , new ArrayList < > ( ) ) ) ; Block b = new Block ( ) ; Fun clinit = new Fun ( new QualifiedName ( "<clinit>" ) , b , new Modifier [ ] { Modifier . STATIC } , null ) ; for ( Statement statement : tree . getStatements ( ) ) { if ( statement instanceof VarDecl ) { VarDecl decl = ( VarDecl ) statement ; decl . addModifier ( Modifier . STATIC ) ; def . getStatements ( ) . add ( statement ) ; b . append ( new BinOp ( decl . getName ( ) , Operator . ASSIGNMENT , decl . getInitialValue ( ) ) ) ; } else { b . append ( statement ) ; } statement . setParent ( def ) ; } for ( Fun fun : tree . getFunctions ( ) ) { fun . addModifier ( Modifier . STATIC ) ; def . getStatements ( ) . add ( fun ) ; fun . setParent ( def ) ; } def . getStatements ( ) . add ( clinit ) ; tree . addClass ( def ) ; for ( ClassDef classDef : tree . getClasses ( ) ) { classDef . setPackage ( tree . getPackage ( ) ) ; if ( ! classDef . equals ( def ) ) { clinit = new Fun ( new QualifiedName ( "<clinit>" ) , new Block ( ) , new Modifier [ ] { Modifier . STATIC } , null ) ; classDef . getStatements ( ) . add ( clinit ) ; } } }
Places any non-static fields and functions into a synthetic class with
 the same name as the containing file.
Places any non - static fields and functions into a synthetic class with the same name as the containing file .
// add the functions and fields to the synthetic class // add class initializer if one does not exist