Package org.teavm.codegen

Examples of org.teavm.codegen.SourceWriter


    private void generateInit(GeneratorContext context, SourceWriter writer) throws IOException {
        writer.append(context.getParameterName(0)).append(".$id = $rt_nextId();").softNewLine();
    }

    private void generateGetClass(InjectorContext context) throws IOException {
        SourceWriter writer = context.getWriter();
        writer.append("$rt_cls(");
        context.writeExpr(context.getArgument(0));
        writer.append(".constructor)");
    }
View Full Code Here


                break;
        }
    }

    private void generateIsAssignableFrom(InjectorContext context) throws IOException {
        SourceWriter writer = context.getWriter();
        writer.append("$rt_isAssignable(");
        context.writeExpr(context.getArgument(1));
        writer.append(".$data,").ws();
        context.writeExpr(context.getArgument(0));
        writer.append(".$data)");
    }
View Full Code Here

        context.writeExpr(context.getArgument(0));
        writer.append(".$data)");
    }

    private void generateIsInstance(InjectorContext context) throws IOException {
        SourceWriter writer = context.getWriter();
        writer.append("$rt_isInstance(");
        context.writeExpr(context.getArgument(1));
        writer.append(",").ws();
        context.writeExpr(context.getArgument(0));
        writer.append(".$data)");
    }
View Full Code Here

            }
        }
    }

    private void generateFunction(InjectorContext context) throws IOException {
        SourceWriter writer = context.getWriter();
        writer.append("(function($instance,").ws().append("$property)").ws().append("{").ws()
                .append("return function()").ws().append("{").indent().softNewLine();
        writer.append("return $instance[$property].apply($instance,").ws().append("arguments);").softNewLine();
        writer.outdent().append("};})(");
        context.writeExpr(context.getArgument(0));
        writer.append(",").ws();
        context.writeExpr(context.getArgument(1));
        writer.append(")");
    }
View Full Code Here

        context.writeExpr(context.getArgument(1));
        writer.append(")");
    }

    private void renderProperty(Expr property, InjectorContext context) throws IOException {
        SourceWriter writer = context.getWriter();
        String name = extractPropertyName(property);
        if (name == null) {
            writer.append('[');
            context.writeExpr(property);
            writer.append(']');
        } else if (!isIdentifier(name)) {
            writer.append("[\"");
            context.writeEscaped(name);
            writer.append("\"]");
        } else {
            writer.append(".").append(name);
        }
    }
View Full Code Here

        this.propertyNames = propertyNames;
    }

    @Override
    public Object invoke(BuildTimeResourceProxy proxy, Object[] args) throws Throwable {
        SourceWriter writer = (SourceWriter)args[0];
        writer.append('{');
        for (int i = 0; i < propertyNames.length; ++i) {
            if (i > 0) {
                writer.append(',').ws();
            }
            ResourceWriterHelper.writeString(writer, propertyNames[i]);
            writer.ws().append(':').ws();
            ResourceWriterHelper.write(writer, proxy.data[i]);
        }
        writer.append('}').tokenBoundary();
        return null;
    }
View Full Code Here

* @author Alexey Andreev
*/
public class JSNativeGenerator implements Injector, DependencyPlugin {
    @Override
    public void generate(InjectorContext context, MethodReference methodRef) throws IOException {
        SourceWriter writer = context.getWriter();
        switch (methodRef.getName()) {
            case "getGlobal":
                writer.append("window");
                break;
            case "isUndefined":
                writer.append("(");
                context.writeExpr(context.getArgument(0));
                writer.ws().append("===").ws().append("undefined)");
                break;
            case "getTypeName":
                writer.append("(typeof ");
                context.writeExpr(context.getArgument(0));
                writer.append(")");
                break;
            case "get":
                context.writeExpr(context.getArgument(0));
                renderProperty(context.getArgument(1), context);
                break;
            case "set":
                writer.append('(');
                context.writeExpr(context.getArgument(0));
                renderProperty(context.getArgument(1), context);
                writer.ws().append('=').ws();
                context.writeExpr(context.getArgument(2));
                writer.append(')');
                break;
            case "invoke":
                context.writeExpr(context.getArgument(0));
                renderProperty(context.getArgument(1), context);
                writer.append('(');
                for (int i = 2; i < context.argumentCount(); ++i) {
                    if (i > 2) {
                        writer.append(',').ws();
                    }
                    context.writeExpr(context.getArgument(i));
                }
                writer.append(')');
                break;
            case "instantiate":
                writer.append("(new ");
                context.writeExpr(context.getArgument(0));
                renderProperty(context.getArgument(1), context);
                writer.append('(');
                for (int i = 2; i < context.argumentCount(); ++i) {
                    if (i > 2) {
                        writer.append(',').ws();
                    }
                    context.writeExpr(context.getArgument(i));
                }
                writer.append("))");
                break;
            case "wrap":
                if (methodRef.getDescriptor().parameterType(0).isObject("java.lang.String")) {
                    writer.append("$rt_ustr(");
                    context.writeExpr(context.getArgument(0));
                    writer.append(")");
                } else {
                    context.writeExpr(context.getArgument(0));
                }
                break;
            case "function":
                generateFunction(context);
                break;
            case "unwrapString":
                writer.append("$rt_str(");
                context.writeExpr(context.getArgument(0));
                writer.append(")");
                break;
            default:
                if (methodRef.getName().startsWith("unwrap")) {
                    context.writeExpr(context.getArgument(0));
                }
View Full Code Here

TOP

Related Classes of org.teavm.codegen.SourceWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.