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

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


    }

    @Override
    protected List<? extends TypeBodyDeclaration> override(Context context) {
        ImplementationBuilder builder = new ImplementationBuilder(context);
        ModelFactory f = context.environment.getFactory();
        builder.addStatement(new TypeBuilder(f, context.importer.toType(UnsupportedOperationException.class))
            .newObject(Models.toLiteral(f, "マスタ確認演算子は組み込みの方法で処理されます"))
            .toThrowStatement());
        return builder.toImplementation();
    }
View Full Code Here


public class MasterJoinFlowProcessor extends RendezvousProcessor {

    @Override
    public void emitRendezvous(Context context) {
        MasterKindFlowAnalyzer masterAnalyzer = new MasterKindFlowAnalyzer(context);
        ModelFactory f = context.getModelFactory();

        FlowElementPortDescription tx = context.getInputPort(MasterJoin.ID_INPUT_TRANSACTION);

        FlowElementPortDescription joinedPort = context.getOutputPort(MasterJoin.ID_OUTPUT_JOINED);
        FlowElementPortDescription missedPort = context.getOutputPort(MasterJoin.ID_OUTPUT_MISSED);

        DataObjectMirror resultCache = context.createModelCache(joinedPort.getDataType());
        DataClass outputType = getEnvironment().getDataClasses().load(joinedPort.getDataType());
        List<Statement> process = Lists.create();
        process.add(resultCache.createReset());

        Joined annotation = TypeUtil.erase(joinedPort.getDataType()).getAnnotation(Joined.class);
        Set<String> saw = Sets.create();
        for (Joined.Term term : annotation.terms()) {
            DataClass inputType = getEnvironment().getDataClasses().load(term.source());
            Expression input;
            if (term.source().equals(context.getInputPort(MasterJoin.ID_INPUT_MASTER).getDataType())) {
                input = masterAnalyzer.getGetRawMasterExpression();
            } else {
                input = context.getProcessInput(tx);
            }
            for (Joined.Mapping mapping : term.mappings()) {
                if (saw.contains(mapping.destination())) {
                    continue;
                }
                saw.add(mapping.destination());
                Property sourceProperty = inputType.findProperty(mapping.source());
                Property destinationProperty = outputType.findProperty(mapping.destination());
                process.add(destinationProperty.createSetter(
                        resultCache.get(),
                        sourceProperty.createGetter(input)));
            }
        }

        ResultMirror joined = context.getOutput(joinedPort);
        process.add(joined.createAdd(resultCache.get()));

        ResultMirror missed = context.getOutput(missedPort);
        context.addProcess(tx, f.newIfStatement(
                masterAnalyzer.getHasMasterExpresion(),
                f.newBlock(process),
                f.newBlock(missed.createAdd(context.getProcessInput(tx)))));
    }
View Full Code Here

@TargetOperator(Fold.class)
public class FoldFlowProcessor extends RendezvousProcessor {

    @Override
    public void emitRendezvous(Context context) {
        ModelFactory f = context.getModelFactory();
        OperatorDescription desc = context.getOperatorDescription();

        FlowElementPortDescription input = context.getInputPort(Fold.ID_INPUT);
        FlowElementPortDescription output = context.getOutputPort(Fold.ID_OUTPUT);

        Expression init = context.createField(boolean.class, "initialized");
        context.addBegin(new ExpressionBuilder(f, init)
            .assignFrom(Models.toLiteral(f, false))
            .toStatement());

        DataObjectMirror cache = context.createModelCache(output.getDataType());
        Expression impl = context.createImplementation();
        Expression proc = context.getProcessInput(input);
        List<Expression> arguments = Lists.create();
        arguments.add(cache.get());
        arguments.add(proc);
        for (OperatorDescription.Parameter param : desc.getParameters()) {
            arguments.add(Models.toLiteral(f, param.getValue()));
        }

        context.addProcess(input, f.newIfStatement(
                init,
                f.newBlock(new ExpressionBuilder(f, impl)
                    .method(desc.getDeclaration().getName(), arguments)
                    .toStatement()),
                f.newBlock(
                        cache.createSet(proc),
                        new ExpressionBuilder(f, init)
                            .assignFrom(Models.toLiteral(f, true))
                            .toStatement())));
View Full Code Here

        build(entries, packager);
        assertThat(environment.hasError(), is(false));
    }

    private CompilationUnit getErroneousSource() {
        ModelFactory f = Models.getModelFactory();
        CompilationUnit cu = f.newCompilationUnit(
                f.newPackageDeclaration(Models.toName(f, "com.example")),
                Collections.<ImportDeclaration>emptyList(),
                Collections.singletonList(f.newClassDeclaration(
                        null,
                        new AttributeBuilder(f)
                            .Public()
                            .Private()
                            .toAttributes(),
                        f.newSimpleName("Hello"),
                        Collections.<TypeParameterDeclaration>emptyList(),
                        null,
                        Collections.<Type>emptyList(),
                        Collections.<TypeBodyDeclaration>emptyList())),
                Collections.<Comment>emptyList());
View Full Code Here

            writer.close();
        }
    }

    private void write(Packager packager, String pkg, String rel, String value) throws IOException {
        ModelFactory f = Models.getModelFactory();
        OutputStream output = packager.openStream(
                pkg == null ? null : Models.toName(f, pkg),
                rel);
        try {
            output.write(value.getBytes("UTF-8"));
View Full Code Here

            output.close();
        }
    }

    private CompilationUnit java(String name) {
        ModelFactory f = Models.getModelFactory();
        return f.newCompilationUnit(
                f.newPackageDeclaration(Models.toName(f, "com.example")),
                Collections.<ImportDeclaration>emptyList(),
                Collections.singletonList(f.newClassDeclaration(
                        null,
                        new AttributeBuilder(f)
                            .Public()
                            .toAttributes(),
                        f.newSimpleName(name),
                        Collections.<TypeParameterDeclaration>emptyList(),
                        null,
                        Collections.<Type>emptyList(),
                        Collections.<TypeBodyDeclaration>emptyList())),
                Collections.<Comment>emptyList());
View Full Code Here

            assertThat(collected, is(nullValue()));
            this.collected = collected(classes.get(0));
        }

        protected TypeDeclaration collected(OperatorClass operatorClass) {
            ModelFactory factory = Models.getModelFactory();
            PackageElement pkg = (PackageElement) operatorClass.getElement().getEnclosingElement();
            OperatorClassGenerator generator = new OperatorImplementationClassGenerator(
                    env,
                    factory,
                    new ImportBuilder(
View Full Code Here

        }
        return compiler.getClassLoader();
    }

    private List<VolatileJavaFile> emit(DmdlSourceRepository source) throws IOException {
        ModelFactory factory = Models.getModelFactory();
        VolatileEmitter emitter = new VolatileEmitter();
        com.asakusafw.dmdl.java.Configuration conf = new com.asakusafw.dmdl.java.Configuration(
                factory,
                source,
                Models.toName(factory, "com.example"),
View Full Code Here

    /**
     * これまでにこのビルダーでインポートしたクラスに対するインポート宣言の一覧を返す。
     * @return インポートしたクラスに対するインポート宣言の一覧
     */
    public List<ImportDeclaration> toImportDeclarations() {
        ModelFactory f = resolver.factory;
        Map<QualifiedName, SimpleName> imported = resolver.imported;
        Set<Name> implicit = createImplicit();

        List<ImportDeclaration> results = new ArrayList<ImportDeclaration>();
        for (QualifiedName name : imported.keySet()) {
            if (implicit.contains(name.getQualifier())) {
                continue;
            }
            results.add(f.newImportDeclaration(ImportKind.SINGLE_TYPE, name));
        }
        Collections.sort(results, ImportComparator.INSTANCE);
        return results;
    }
View Full Code Here

        return Collections.singletonList(new ExternalIoStage(getId(), stage, builder.build()));
    }

    @Override
    public List<ExternalIoStage> emitEpilogue(IoContext context) throws IOException {
        ModelFactory f = getEnvironment().getModelFactory();
        NamingClassEmitter namingEmitter = new NamingClassEmitter(getEnvironment(), MODULE_NAME);
        OrderingClassEmitter orderingEmitter = new OrderingClassEmitter(getEnvironment(), MODULE_NAME);
        List<Slot> slots = Lists.create();
        for (Output output : context.getOutputs()) {
            DirectFileOutputDescription desc = extract(output.getDescription());
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.