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

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


        assert property != null;
        JavaName name = JavaName.of(property.getName());
        name.addFirst("get");
        name.addLast("as");
        name.addLast("string");
        ModelFactory f = context.getModelFactory();
        return f.newMethodDeclaration(
                new JavadocBuilder(f)
                    .text("{0}を返す。",
                            context.getDescription(property))
                    .returns()
                        .text("{0}",
                                context.getDescription(property))
                    .exception(context.resolve(NullPointerException.class))
                        .text("{0}の値が<code>null</code>である場合",
                                context.getDescription(property))
                    .toJavadoc(),
                new AttributeBuilder(f)
                    .Public()
                    .toAttributes(),
                context.resolve(String.class),
                f.newSimpleName(name.toMemberName()),
                Collections.<FormalParameterDeclaration>emptyList(),
                Collections.singletonList(new ExpressionBuilder(f, f.newThis())
                    .field(context.getFieldName(property))
                    .method("getAsString")
                    .toReturnStatement()));
    }
View Full Code Here


        assert property != null;
        JavaName name = JavaName.of(property.getName());
        name.addFirst("set");
        name.addLast("as");
        name.addLast("string");
        ModelFactory f = context.getModelFactory();
        SimpleName paramName = context.createVariableName(
                context.getFieldName(property).getToken());

        return f.newMethodDeclaration(
                new JavadocBuilder(f)
                    .text("{0}を設定する。",
                            context.getDescription(property))
                    .param(paramName)
                        .text("設定する値",
                                context.getDescription(property))
                    .toJavadoc(),
                new AttributeBuilder(f)
                    .annotation(
                            context.resolve(SuppressWarnings.class),
                            Models.toLiteral(f, "deprecation"))
                    .Public()
                    .toAttributes(),
                context.resolve(void.class),
                f.newSimpleName(name.toMemberName()),
                Arrays.asList(new FormalParameterDeclaration[] {
                        f.newFormalParameterDeclaration(
                                context.resolve(String.class),
                                paramName)
                }),
                Collections.singletonList(new ExpressionBuilder(f, f.newThis())
                    .field(context.getFieldName(property))
                    .method("modify", paramName)
                    .toStatement()));
    }
View Full Code Here

    private static final String GENERATOR_IDENTIFIER = "DMDL"; //$NON-NLS-1$

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

public class ModelInputDriver extends JavaDataModelDriver {

    @Override
    public List<Annotation> getTypeAnnotations(EmitContext context, ModelDeclaration model) throws IOException {
        Type type = generate(context, model);
        ModelFactory f = context.getModelFactory();
        return new AttributeBuilder(f)
            .annotation(context.resolve(ModelInputLocation.class),
                    f.newClassLiteral(context.resolve(type)))
            .toAnnotations();
    }
View Full Code Here

            throw new IllegalStateException(MessageFormat.format(
                    "Internal Error: joined model {0} has no JoinTrait", //$NON-NLS-1$
                    model.getName()));
        }

        ModelFactory f = context.getModelFactory();
        List<Annotation> eTerms = Lists.create();
        for (ReduceTerm<?> term : trait.getTerms()) {
            ClassLiteral source = f.newClassLiteral(context.resolve(term.getSource()));
            ArrayInitializer mappings = toMappings(context, term.getMappings());
            Annotation shuffle = toKey(context, term);
            eTerms.addAll(new AttributeBuilder(f)
                .annotation(context.resolve(Joined.Term.class),
                        "source", source, //$NON-NLS-1$
                        "mappings", mappings, //$NON-NLS-1$
                        "shuffle", shuffle) //$NON-NLS-1$
                .toAnnotations());
        }
        return new AttributeBuilder(f)
            .annotation(context.resolve(Joined.class),
                    "terms", f.newArrayInitializer(eTerms)) //$NON-NLS-1$
            .toAnnotations();
    }
View Full Code Here

    }

    private ArrayInitializer toMappings(EmitContext context, List<MappingFactor> mappings) {
        assert context != null;
        assert mappings != null;
        ModelFactory f = context.getModelFactory();
        List<Annotation> eachMapping = Lists.create();
        for (MappingFactor factor : mappings) {
            String source = context.getFieldName(factor.getSource().findDeclaration()).getToken();
            String target = context.getFieldName(factor.getTarget().findDeclaration()).getToken();
            eachMapping.addAll(new AttributeBuilder(f)
                .annotation(context.resolve(Joined.Mapping.class),
                        "source", Models.toLiteral(f, source), //$NON-NLS-1$
                        "destination", Models.toLiteral(f, target)) //$NON-NLS-1$
                .toAnnotations());
        }
        return f.newArrayInitializer(eachMapping);
    }
View Full Code Here

    }

    private Annotation toKey(EmitContext context, ReduceTerm<?> term) {
        assert context != null;
        assert term != null;
        ModelFactory f = context.getModelFactory();
        List<Literal> properties = Lists.create();
        Map<String, PropertySymbol> reverseMapping = Maps.create();
        for (MappingFactor mapping : term.getMappings()) {
            reverseMapping.put(mapping.getTarget().getName().identifier, mapping.getSource());
        }
        for (PropertySymbol property : term.getGrouping()) {
            PropertySymbol origin = reverseMapping.get(property.getName().identifier);
            assert origin != null;
            PropertyDeclaration decl = origin.findDeclaration();
            properties.add(Models.toLiteral(f, context.getFieldName(decl).getToken()));
        }
        return new AttributeBuilder(f)
            .annotation(context.resolve(Key.class),
                    "group", f.newArrayInitializer(properties)) //$NON-NLS-1$
            .toAnnotations()
            .get(0);
    }
View Full Code Here

*/
public class PropertyOrderDriver extends JavaDataModelDriver {

    @Override
    public List<Annotation> getTypeAnnotations(EmitContext context, ModelDeclaration model) {
        ModelFactory f = context.getModelFactory();
        List<Literal> names = Lists.create();
        for (PropertyDeclaration prop : model.getDeclaredProperties()) {
            names.add(Models.toLiteral(f, prop.getName().identifier));
        }
        return new AttributeBuilder(f)
            .annotation(context.resolve(PropertyOrder.class),
                    f.newArrayInitializer(names))
            .toAnnotations();
    }
View Full Code Here

            throw new IllegalStateException(MessageFormat.format(
                    "Internal Error: summarized model {0} has no SummarizeTrait", //$NON-NLS-1$
                    model.getName()));
        }

        ModelFactory f = context.getModelFactory();
        List<Annotation> eTerms = Lists.create();
        for (ReduceTerm<?> term : trait.getTerms()) {
            ClassLiteral source = f.newClassLiteral(context.resolve(term.getSource()));
            ArrayInitializer mappings = toMappings(context, term.getMappings());
            Annotation shuffle = toKey(context, term);
            eTerms.addAll(new AttributeBuilder(f)
                .annotation(context.resolve(Summarized.Term.class),
                        "source", source, //$NON-NLS-1$
View Full Code Here

    }

    private ArrayInitializer toMappings(EmitContext context, List<MappingFactor> foldings) {
        assert context != null;
        assert foldings != null;
        ModelFactory f = context.getModelFactory();
        List<Annotation> eachFolding = Lists.create();
        for (MappingFactor factor : foldings) {
            Expression aggregator = new TypeBuilder(f, context.resolve(Summarized.Aggregator.class))
                .field(convert(factor.getKind()).name())
                .toExpression();
            String source = context.getFieldName(factor.getSource().findDeclaration()).getToken();
            String target = context.getFieldName(factor.getTarget().findDeclaration()).getToken();
            eachFolding.addAll(new AttributeBuilder(f)
                .annotation(context.resolve(Summarized.Folding.class),
                        "aggregator", aggregator, //$NON-NLS-1$
                        "source", Models.toLiteral(f, source), //$NON-NLS-1$
                        "destination", Models.toLiteral(f, target)) //$NON-NLS-1$
                .toAnnotations());
        }
        return f.newArrayInitializer(eachFolding);
    }
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.