private List createPropertiesForHasManyExpression(Expression e, ClassNode classNode) { List properties = new ArrayList(); if (e instanceof MapExpression) { MapExpression me = (MapExpression) e; List mapEntries = me.getMapEntryExpressions(); for (Iterator j = mapEntries.iterator(); j.hasNext(); ) { MapEntryExpression mee = (MapEntryExpression) j.next(); Expression keyExpression = mee.getKeyExpression(); String key = keyExpression.getText(); addAssociationForKey(key, properties, classNode); } } return properties; }
private void createConstructorOrdered(ClassNode cNode, List<PropertyNode> list) { final MapExpression argMap = new MapExpression(); final Parameter[] orderedParams = new Parameter[list.size()]; int index = 0; for (PropertyNode pNode : list) { Parameter param = new Parameter(pNode.getField().getType(), pNode.getField().getName()); orderedParams[index++] = param; argMap.addMapEntryExpression( new ConstantExpression(pNode.getName()), new VariableExpression(pNode.getName())); } final BlockStatement orderedBody = new BlockStatement(); orderedBody.addStatement( new ExpressionStatement( new ConstructorCallExpression( ClassNode.THIS, new ArgumentListExpression(new CastExpression(HASHMAP_TYPE, argMap))))); doAddConstructor( cNode, new ConstructorNode(ACC_PUBLIC, orderedParams, ClassNode.EMPTY_ARRAY, orderedBody)); }
private Collection createPropertiesForBelongsToExpression(Expression e, ClassNode classNode) { List properties = new ArrayList(); if (e instanceof MapExpression) { MapExpression me = (MapExpression) e; List mapEntries = me.getMapEntryExpressions(); for (Iterator i = mapEntries.iterator(); i.hasNext(); ) { MapEntryExpression mme = (MapEntryExpression) i.next(); String key = mme.getKeyExpression().getText(); String type = mme.getValueExpression().getText(); properties.add( new PropertyNode( key, Modifier.PUBLIC, ClassHelper.make(type), classNode, null, null, null)); } } return properties; }