private static boolean hasName(DocElement element, String name) { assert element != null; assert name != null; switch (element.getModelKind()) { case SIMPLE_NAME: return name.equals(((SimpleName) element).getToken()); case DOC_TEXT: return name.equals(((DocText) element).getString()); default: return false; } }
private Set<String> collectFieldNames(ModelDeclaration model) { assert model != null; Set<String> results = new HashSet<>(); for (PropertyDeclaration property : model.getDeclaredProperties()) { results.add(getFieldName(property).getToken()); } return results; }
private ArrayInitializer toMappings(EmitContext context, List<MappingFactor> mappings) { assert context != null; assert mappings != null; ModelFactory f = context.getModelFactory(); List<Annotation> eachMapping = new ArrayList<>(); 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); }
private Annotation toKey(EmitContext context, ReduceTerm<?> term) { assert context != null; assert term != null; ModelFactory f = context.getModelFactory(); List<Literal> properties = new ArrayList<>(); Map<String, PropertySymbol> reverseMapping = new HashMap<>(); 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); } }
private Annotation toKey(EmitContext context, ReduceTerm<?> term) { assert context != null; assert term != null; ModelFactory f = context.getModelFactory(); List<Literal> properties = new ArrayList<>(); Map<String, PropertySymbol> reverseMapping = new HashMap<>(); 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); } }
private Statement createNullCheck(SimpleName parameter) { 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", //$NON-NLS-1$ parameter.getToken()))) .toThrowStatement())); }
private Statement createNullCheck(SimpleName parameter) { 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", //$NON-NLS-1$ parameter.getToken()))) .toThrowStatement())); }
private Statement createNullCheck(SimpleName parameter) { 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", //$NON-NLS-1$ parameter.getToken()))) .toThrowStatement())); }
private Statement createNullCheck(SimpleName parameter) { 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", //$NON-NLS-1$ parameter.getToken()))) .toThrowStatement())); }
private Statement createNullCheck(SimpleName parameter) { 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", //$NON-NLS-1$ parameter.getToken()))) .toThrowStatement())); }
private Statement createNullCheck(SimpleName parameter) { 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", //$NON-NLS-1$ parameter.getToken()))) .toThrowStatement())); }
private ArrayInitializer toMappings(EmitContext context, List<MappingFactor> foldings) { assert context != null; assert foldings != null; ModelFactory f = context.getModelFactory(); List<Annotation> eachFolding = new ArrayList<>(); 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); }
ModelFactory f = context.getModelFactory(); SimpleName paramName = context.createVariableName( context.getFieldName(property).getToken());