Package com.asakusafw.utils.java.model.syntax

Examples of com.asakusafw.utils.java.model.syntax.ModelFactory


            ImportBuilder importer,
            List<? extends Expression> arguments) throws IOException {
        assert className != null;
        assert importer != null;
        assert arguments != null;
        ModelFactory f = environment.getModelFactory();
        Statement ctorChain = f.newSuperConstructorInvocation(arguments);
        ConstructorDeclaration ctorDecl = f.newConstructorDeclaration(
                new JavadocBuilder(f)
                    .text("Creates a new instance.")
                    .toJavadoc(),
                new AttributeBuilder(f)
                    .Public()
                    .toAttributes(),
                className,
                Collections.<FormalParameterDeclaration>emptyList(),
                Collections.singletonList(ctorChain));
        ClassDeclaration typeDecl = f.newClassDeclaration(
                new JavadocBuilder(f)
                    .toJavadoc(),
                new AttributeBuilder(f)
                    .annotation(importer.toType(TraceLocation.class), createTraceLocationElements())
                    .Public()
                    .Final()
                    .toAttributes(),
                className,
                importer.resolve(baseClass),
                Collections.<Type>emptyList(),
                Collections.singletonList(ctorDecl));
        CompilationUnit source = f.newCompilationUnit(
                importer.getPackageDeclaration(),
                importer.toImportDeclarations(),
                Collections.singletonList(typeDecl),
                Collections.<Comment>emptyList());
        environment.emit(source);
View Full Code Here


        LOG.debug("epilogue of \"{}\" will use {}", moduleId, name);
        return name;
    }

    private Map<String, Expression> createTraceLocationElements() {
        ModelFactory factory = environment.getModelFactory();
        Map<String, Expression> results = new LinkedHashMap<String, Expression>();
        results.put("batchId", Models.toLiteral(factory, environment.getBatchId()));
        results.put("flowId", Models.toLiteral(factory, environment.getFlowId()));
        results.put("stageId", Models.toLiteral(factory, Naming.getEpilogueName(moduleId)));
        return results;
View Full Code Here

*/
public class OriginalNameEmitter extends JavaDataModelDriver {

    @Override
    public List<Annotation> getTypeAnnotations(EmitContext context, ModelDeclaration model) {
        ModelFactory f = context.getModelFactory();
        Expression value = Models.toLiteral(f, getOriginalName(model));
        return new AttributeBuilder(f)
            .annotation(context.resolve(OriginalName.class), "value", value)
            .toAnnotations();
    }
View Full Code Here

        OriginalNameTrait trait = property.getTrait(OriginalNameTrait.class);
        if (trait == null) {
            return Collections.emptyList();
        }

        ModelFactory f = context.getModelFactory();
        Expression value = Models.toLiteral(f, trait.getName());
        return new AttributeBuilder(f)
            .annotation(context.resolve(OriginalName.class), "value", value)
            .toAnnotations();
    }
View Full Code Here

*/
public class ColumnOrderEmitter extends JavaDataModelDriver {

    @Override
    public List<Annotation> getTypeAnnotations(EmitContext context, ModelDeclaration model) {
        ModelFactory f = context.getModelFactory();
        List<Expression> columns = Lists.create();
        for (PropertyDeclaration property : model.getDeclaredProperties()) {
            columns.add(Models.toLiteral(f, OriginalNameEmitter.getOriginalName(property)));
        }
        return new AttributeBuilder(f)
            .annotation(context.resolve(ColumnOrder.class),
                    "value", f.newArrayInitializer(columns))
            .toAnnotations();
    }
View Full Code Here

            ModelDeclaration model,
            AstLiteral deleteFlagValue) {
        assert context != null;
        assert model != null;
        assert deleteFlagValue != null;
        ModelFactory f = context.getModelFactory();
        Type type;
        Expression value;
        switch (deleteFlagValue.kind) {
        case BOOLEAN:
            type = context.resolve(boolean.class);
            value = Models.toLiteral(f, deleteFlagValue.toBooleanValue());
            break;
        case INTEGER:
            type = context.resolve(int.class);
            value = Models.toLiteral(f, deleteFlagValue.toIntegerValue().intValue());
            break;
        case STRING:
            type = context.resolve(Text.class);
            value = new TypeBuilder(f, context.resolve(Text.class))
                .newObject(Models.toLiteral(f, deleteFlagValue.toStringValue()))
                .toExpression();
            break;
        default:
            throw new AssertionError(deleteFlagValue);
        }
        return f.newFieldDeclaration(
                null,
                new AttributeBuilder(f)
                    .Private()
                    .Static()
                    .Final()
                    .toAttributes(),
                type,
                f.newSimpleName(FIELD_DELETE_FLAG_VALUE),
                value);
    }
View Full Code Here

            ModelDeclaration model,
            CacheSupportTrait trait) {
        assert context != null;
        assert model != null;
        assert trait != null;
        ModelFactory f = context.getModelFactory();
        List<Statement> statements = Lists.create();
        statements.add(new ExpressionBuilder(f, Models.toLiteral(f, computeModelVersion(context, model, trait)))
            .toReturnStatement());
        return f.newMethodDeclaration(
                null,
                new AttributeBuilder(f)
                    .annotation(context.resolve(Override.class))
                    .Public()
                    .toAttributes(),
                context.resolve(long.class),
                f.newSimpleName("__tgc__DataModelVersion"),
                Collections.<FormalParameterDeclaration>emptyList(),
                statements);
    }
View Full Code Here

            ModelDeclaration model,
            PropertySymbol timestamp) {
        assert context != null;
        assert model != null;
        assert timestamp != null;
        ModelFactory f = context.getModelFactory();
        String name = OriginalNameEmitter.getOriginalName(timestamp.findDeclaration());
        List<Statement> statements = Lists.create();
        statements.add(new ExpressionBuilder(f, Models.toLiteral(f, name))
            .toReturnStatement());
        return f.newMethodDeclaration(
                null,
                new AttributeBuilder(f)
                    .annotation(context.resolve(Override.class))
                    .Public()
                    .toAttributes(),
                context.resolve(String.class),
                f.newSimpleName("__tgc__TimestampColumn"),
                Collections.<FormalParameterDeclaration>emptyList(),
                statements);
    }
View Full Code Here

            ModelDeclaration model,
            PropertySymbol sid) {
        assert context != null;
        assert model != null;
        assert sid != null;
        ModelFactory f = context.getModelFactory();
        List<Statement> statements = Lists.create();
        statements.add(new ExpressionBuilder(f, f.newThis())
            .method(context.getValueGetterName(sid.findDeclaration()))
            .toReturnStatement());
        return f.newMethodDeclaration(
                null,
                new AttributeBuilder(f)
                    .annotation(context.resolve(Override.class))
                    .Public()
                    .toAttributes(),
                context.resolve(long.class),
                f.newSimpleName("__tgc__SystemId"),
                Collections.<FormalParameterDeclaration>emptyList(),
                statements);
    }
View Full Code Here

            EmitContext context,
            ModelDeclaration model,
            PropertySymbol deleteFlagOrNull) {
        assert context != null;
        assert model != null;
        ModelFactory f = context.getModelFactory();
        List<Statement> statements = Lists.create();
        if (deleteFlagOrNull == null) {
            statements.add(new ExpressionBuilder(f, Models.toLiteral(f, false))
                .toReturnStatement());
        } else {
            statements.add(new ExpressionBuilder(f, f.newThis())
                .method(context.getOptionGetterName(deleteFlagOrNull.findDeclaration()))
                .method("has", f.newSimpleName(FIELD_DELETE_FLAG_VALUE))
                .toReturnStatement());
        }
        return f.newMethodDeclaration(
                null,
                new AttributeBuilder(f)
                    .annotation(context.resolve(Override.class))
                    .Public()
                    .toAttributes(),
                context.resolve(boolean.class),
                f.newSimpleName("__tgc__Deleted"),
                Collections.<FormalParameterDeclaration>emptyList(),
                statements);
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.utils.java.model.syntax.ModelFactory

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.