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

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


        return optionClass;
    }

    @Override
    public Expression createNewInstance(Type target) {
        return new TypeBuilder(factory, target)
            .newObject()
            .toExpression();
    }
View Full Code Here


            Expression length) {
        Precondition.checkMustNotBeNull(bytes, "bytes"); //$NON-NLS-1$
        Precondition.checkMustNotBeNull(start, "start"); //$NON-NLS-1$
        Precondition.checkMustNotBeNull(length, "length"); //$NON-NLS-1$
        Type type = factory.newNamedType(Models.toName(factory, optionClass.getName()));
        return new TypeBuilder(factory, type)
            .method("getBytesLength", bytes, start, length)
            .toExpression();
    }
View Full Code Here

        Precondition.checkMustNotBeNull(length1, "length1"); //$NON-NLS-1$
        Precondition.checkMustNotBeNull(bytes2, "bytes2"); //$NON-NLS-1$
        Precondition.checkMustNotBeNull(start2, "start2"); //$NON-NLS-1$
        Precondition.checkMustNotBeNull(length2, "length2"); //$NON-NLS-1$
        Type type = factory.newNamedType(Models.toName(factory, optionClass.getName()));
        return new TypeBuilder(factory, type)
            .method("compareBytes",
                    bytes1, start1, length1,
                    bytes2, start2, length2)
            .toExpression();
    }
View Full Code Here

                            context.resolve(Class.class),
                            context.resolve(model.getSymbol())),
                    f.newSimpleName("getSupportedType"),
                    Collections.<FormalParameterDeclaration>emptyList(),
                    Arrays.asList(new Statement[] {
                            new TypeBuilder(f, context.resolve(model.getSymbol()))
                                .dotClass()
                                .toReturnStatement()
                    }));
            return decl;
        }
View Full Code Here

        }

        private MethodDeclaration createGetMinimumFragmentSize() {
            boolean fastMode = isFastMode();
            Expression value = fastMode
                ? new TypeBuilder(f, context.resolve(Long.class)).field("MAX_VALUE").toExpression()
                : Models.toLiteral(f, -1L);
            return f.newMethodDeclaration(
                    null,
                    new AttributeBuilder(f)
                        .annotation(context.resolve(Override.class))
View Full Code Here

                .apply(InfixOperator.GREATER, Models.toLiteral(f, 0L))
                .toExpression();
            if (isFastMode() == false) {
                statements.add(f.newIfStatement(
                        isNotHead,
                        f.newBlock(new TypeBuilder(f, context.resolve(IllegalArgumentException.class))
                            .newObject(Models.toLiteral(f, MessageFormat.format(
                                    "{0} does not support fragmentation.",
                                    context.getQualifiedTypeName().toNameString())))
                            .toThrowStatement())));
            }

            SimpleName fragmentInput = f.newSimpleName("fragmentInput");
            statements.add(f.newLocalVariableDeclaration(
                    context.resolve(InputStream.class),
                    fragmentInput,
                    null));
            if (isFastMode()) {
                statements.add(new ExpressionBuilder(f, fragmentInput)
                    .assignFrom(new TypeBuilder(f, context.resolve(DelimiterRangeInputStream.class))
                        .newObject(
                                blessInputStream(stream),
                                Models.toLiteral(f, '\n'),
                                fragmentSize,
                                isNotHead)
                        .toExpression())
                    .toStatement());
            } else {
                statements.add(new ExpressionBuilder(f, fragmentInput)
                    .assignFrom(blessInputStream(stream))
                    .toStatement());
            }

            if (conf.isEnableHeader()) {
                statements.add(f.newIfStatement(
                        new ExpressionBuilder(f, offset)
                            .apply(InfixOperator.EQUALS, Models.toLiteral(f, 0L))
                            .toExpression(),
                        f.newBlock(new ExpressionBuilder(f, f.newThis())
                                .method(NAME_SKIP_HEADER, fragmentInput)
                                .toStatement())));
            }

            SimpleName parser = f.newSimpleName("parser");
            statements.add(new TypeBuilder(f, context.resolve(TsvParser.class))
                .newObject(new TypeBuilder(f, context.resolve(InputStreamReader.class))
                        .newObject(fragmentInput, Models.toLiteral(f, conf.getCharsetName()))
                        .toExpression())
                .toLocalVariableDeclaration(context.resolve(TsvParser.class), parser));

            List<Expression> arguments = Lists.create();
            arguments.add(parser);
            if (hasFileName()) {
                arguments.add(new TypeBuilder(f, context.resolve(StringOption.class))
                        .newObject(path)
                        .toExpression());
            }
            statements.add(new TypeBuilder(f, f.newNamedType(f.newSimpleName(NAME_READER)))
                .newObject(arguments)
                .toReturnStatement());
            MethodDeclaration decl = f.newMethodDeclaration(
                    null,
                    new AttributeBuilder(f)
View Full Code Here

            List<Statement> statements = Lists.create();
            statements.add(createNullCheck(path));
            statements.add(createNullCheck(stream));

            SimpleName emitter = f.newSimpleName("emitter");
            statements.add(new TypeBuilder(f, context.resolve(TsvEmitter.class))
                .newObject(new TypeBuilder(f, context.resolve(OutputStreamWriter.class))
                        .newObject(blessOutputStream(stream), Models.toLiteral(f, conf.getCharsetName()))
                        .toExpression())
                .toLocalVariableDeclaration(context.resolve(TsvEmitter.class), emitter));

            if (conf.isEnableHeader()) {
                statements.add(new ExpressionBuilder(f, f.newThis())
                                .method(NAME_ADD_HEADER, emitter)
                                .toStatement());
            }

            statements.add(new TypeBuilder(f, f.newNamedType(f.newSimpleName(NAME_WRITER)))
                .newObject(emitter)
                .toReturnStatement());

            MethodDeclaration decl = f.newMethodDeclaration(
                    null,
View Full Code Here

        private MethodDeclaration createAddHeader() {
            SimpleName emitter = f.newSimpleName("emitter");
            SimpleName buf = f.newSimpleName("buf");
            List<Statement> statements = Lists.create();
            statements.add(new TypeBuilder(f, context.resolve(StringOption.class))
                    .newObject()
                    .toLocalVariableDeclaration(context.resolve(StringOption.class), buf));

            for (PropertyDeclaration property : model.getDeclaredProperties()) {
                switch (TsvFieldTrait.getKind(property, Kind.VALUE)) {
View Full Code Here

            if (CODEC_SHORT_NAMES.containsKey(codecName)) {
                codecName = CODEC_SHORT_NAMES.get(codecName);
            }
            assert codecName != null;
            assert isHadoopConfRequired();
            return new TypeBuilder(f, context.resolve(Models.toName(f, "org.apache.hadoop.util.ReflectionUtils")))
                .method("newInstance",
                        new TypeBuilder(f, context.resolve(Models.toName(f, codecName)))
                            .dotClass()
                            .toExpression(),
                        new ExpressionBuilder(f, f.newThis())
                            .method("getConf")
                            .toExpression())
View Full Code Here

            assert parameter != null;
            return f.newIfStatement(
                    new ExpressionBuilder(f, parameter)
                        .apply(InfixOperator.EQUALS, Models.toNullLiteral(f))
                        .toExpression(),
                    f.newBlock(new TypeBuilder(f, context.resolve(IllegalArgumentException.class))
                        .newObject(Models.toLiteral(f, MessageFormat.format(
                                "{0} must not be null",
                                parameter.getToken())))
                        .toThrowStatement()));
        }
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.