Package com.asakusafw.utils.java.model.util

Examples of com.asakusafw.utils.java.model.util.TypeBuilder


        private MethodDeclaration createStageInputsMethod() throws IOException {
            SimpleName list = factory.newSimpleName("results");
            SimpleName attributes = factory.newSimpleName("attributes");
            List<Statement> statements = Lists.create();
            statements.add(new TypeBuilder(factory, t(ArrayList.class, t(StageInput.class)))
                .newObject()
                .toLocalVariableDeclaration(t(List.class, t(StageInput.class)), list));
            statements.add(new ExpressionBuilder(factory, Models.toNullLiteral(factory))
                .toLocalVariableDeclaration(t(Map.class, t(String.class), t(String.class)), attributes));

            for (ResolvedSlot slot : slots) {
                Type mapperType = generateMapper(slot);
                statements.add(new ExpressionBuilder(factory, attributes)
                    .assignFrom(new TypeBuilder(factory, t(HashMap.class, t(String.class), t(String.class)))
                        .newObject()
                        .toExpression())
                    .toStatement());
                for (SourceInfo input : slot.getSource().getInputs()) {
                    for (Map.Entry<String, String> entry : input.getAttributes().entrySet()) {
                        statements.add(new ExpressionBuilder(factory, attributes)
                            .method("put",
                                    Models.toLiteral(factory, entry.getKey()),
                                    Models.toLiteral(factory, entry.getValue()))
                            .toStatement());
                    }
                    for (Location location : input.getLocations()) {
                        statements.add(new ExpressionBuilder(factory, list)
                            .method("add", new TypeBuilder(factory, t(StageInput.class))
                                .newObject(
                                        Models.toLiteral(factory, location.toPath(PATH_SEPARATOR)),
                                        factory.newClassLiteral(t(input.getFormat())),
                                        factory.newClassLiteral(mapperType),
                                        attributes)
View Full Code Here



        private MethodDeclaration createStageOutputsMethod() {
            SimpleName list = factory.newSimpleName("results");
            List<Statement> statements = Lists.create();
            statements.add(new TypeBuilder(factory, t(ArrayList.class, t(StageOutput.class)))
                .newObject()
                .toLocalVariableDeclaration(t(List.class, t(StageOutput.class)), list));
            for (ResolvedSlot slot : slots) {
                Expression valueType = factory.newClassLiteral(t(slot.getValueClass().getType()));
                Class<?> outputFormatType = slot.getSource().getOutputFormatType();
                statements.add(new ExpressionBuilder(factory, list)
                    .method("add", new TypeBuilder(factory, t(StageOutput.class))
                        .newObject(
                                Models.toLiteral(factory, slot.getSource().getOutputName()),
                                factory.newClassLiteral(t(NullWritable.class)),
                                valueType,
                                factory.newClassLiteral(t(outputFormatType)))
View Full Code Here

                ShuffleModel.Segment segment = entry.getKey();
                SimpleName name = entry.getValue();
                Name shuffleTypeName = segment.getCompiled().getCombineOutputType().getQualifiedName();
                statements.add(new ExpressionBuilder(factory, factory.newThis())
                    .field(name)
                    .assignFrom(new TypeBuilder(factory, importer.toType(shuffleTypeName))
                        .newObject(context)
                        .toExpression())
                    .toStatement());
                segments.put(segment.getPort(), segment);
            }

            // rendezvous
            for (Map.Entry<Fragment, SimpleName> entry : rendezvousNames.entrySet()) {
                Fragment fragment = entry.getKey();
                Type rendezvousType = importer.toType(fragment.getCompiled().getQualifiedName());
                List<Expression> arguments = Lists.create();
                for (FlowElementInput input : fragment.getInputPorts()) {
                    Segment segment = segments.get(input);
                    assert segment != null;
                    SimpleName shuffleName = shuffleNames.get(segment);
                    assert shuffleName != null;
                    arguments.add(new ExpressionBuilder(factory, factory.newThis())
                        .field(shuffleName)
                        .toExpression());
                }
                SimpleName name = entry.getValue();
                statements.add(new ExpressionBuilder(factory, factory.newThis())
                    .field(name)
                    .assignFrom(new TypeBuilder(factory, rendezvousType)
                        .newObject(arguments)
                        .toExpression())
                    .toStatement());
            }
View Full Code Here

                        .field(rendezvousName)
                        .toReturnStatement());
                }
            }
            cases.add(factory.newSwitchDefaultLabel());
            cases.add(new TypeBuilder(factory, t(AssertionError.class))
                .newObject()
                .toThrowStatement());

            SimpleName argument = names.create("nextKey");
            List<Statement> statements = Lists.create();
View Full Code Here

            List<Expression> order = new ArrayList<Expression>();
            for (ShuffleKey.Order entry : key.getOrderings()) {
                order.addAll(new AttributeBuilder(factory)
                        .annotation(
                                t(KeyInfo.Order.class),
                                "direction", new TypeBuilder(factory, t(KeyInfo.Direction.class))
                                        .field(entry.getDirection().name())
                                        .toExpression(),
                                "expression", Models.toLiteral(factory, entry.getProperty()))
                        .toAnnotations());
            }
View Full Code Here

        }

        private MethodDeclaration createSlotNames() {
            SimpleName resultName = factory.newSimpleName("results");
            List<Statement> statements = Lists.create();
            statements.add(new TypeBuilder(factory, importer.toType(String.class))
                .array(1)
                .newArray(getSlotCount())
                .toLocalVariableDeclaration(
                        importer.toType(String[].class),
                        resultName));
View Full Code Here

        }

        private MethodDeclaration createSlotObjects() {
            SimpleName resultName = factory.newSimpleName("results");
            List<Statement> statements = Lists.create();
            statements.add(new TypeBuilder(factory, importer.toType(Writable.class))
                .array(1)
                .newArray(getSlotCount())
                .toLocalVariableDeclaration(
                        importer.toType(Writable[].class),
                        resultName));
View Full Code Here

            cases.add(f.newSwitchCaseLabel(f.newSimpleName(constant.name())));
            cases.add(next.createAdd(input));
            cases.add(f.newBreakStatement());
        }
        cases.add(f.newSwitchDefaultLabel());
        cases.add(new TypeBuilder(f, context.convert(AssertionError.class))
            .newObject(result)
            .toThrowStatement());
        context.add(f.newSwitchStatement(result, cases));
    }
View Full Code Here

        private MethodDeclaration createStageInputsMethod() throws IOException {
            SimpleName list = factory.newSimpleName("results");
            SimpleName attributes = factory.newSimpleName("attributes");

            List<Statement> statements = Lists.create();
            statements.add(new TypeBuilder(factory, t(ArrayList.class, t(StageInput.class)))
                .newObject()
                .toLocalVariableDeclaration(t(List.class, t(StageInput.class)), list));
            statements.add(new ExpressionBuilder(factory, Models.toNullLiteral(factory))
                .toLocalVariableDeclaration(t(Map.class, t(String.class), t(String.class)), attributes));

            for (CopyDescription slot : slots) {
                SourceInfo info = slot.getInput();
                Type mapperType = generateMapper(slot);
                Type formatClass = t(info.getFormat());
                statements.add(new ExpressionBuilder(factory, attributes)
                    .assignFrom(new TypeBuilder(factory, t(HashMap.class, t(String.class), t(String.class)))
                        .newObject()
                        .toExpression())
                    .toStatement());
                for (Map.Entry<String, String> entry : info.getAttributes().entrySet()) {
                    statements.add(new ExpressionBuilder(factory, attributes)
                        .method("put",
                                Models.toLiteral(factory, entry.getKey()),
                                Models.toLiteral(factory, entry.getValue()))
                        .toStatement());
                }
                for (Location input : info.getLocations()) {
                    statements.add(new ExpressionBuilder(factory, list)
                        .method("add", new TypeBuilder(factory, t(StageInput.class))
                            .newObject(
                                    Models.toLiteral(factory, input.toPath(PATH_SEPARATOR)),
                                    factory.newClassLiteral(formatClass),
                                    factory.newClassLiteral(mapperType),
                                    attributes)
View Full Code Here


        private MethodDeclaration createStageOutputsMethod() {
            SimpleName list = factory.newSimpleName("results");
            List<Statement> statements = Lists.create();
            statements.add(new TypeBuilder(factory, t(ArrayList.class, t(StageOutput.class)))
                .newObject()
                .toLocalVariableDeclaration(t(List.class, t(StageOutput.class)), list));
            for (CopyDescription slot : slots) {
                Expression valueType = factory.newClassLiteral(t(slot.getDataModel().getType()));
                statements.add(new ExpressionBuilder(factory, list)
                    .method("add", new TypeBuilder(factory, t(StageOutput.class))
                        .newObject(
                                Models.toLiteral(factory, slot.getName()),
                                factory.newClassLiteral(t(NullWritable.class)),
                                valueType,
                                factory.newClassLiteral(t(slot.getOutputFormatType())))
View Full Code Here

TOP

Related Classes of com.asakusafw.utils.java.model.util.TypeBuilder

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.