Esempio n. 1
0
  public PropertyNode addProperty(
      String name,
      int modifiers,
      ClassNode type,
      Expression initialValueExpression,
      Statement getterBlock,
      Statement setterBlock) {
    for (PropertyNode pn : getProperties()) {
      if (pn.getName().equals(name)) {
        if (pn.getInitialExpression() == null && initialValueExpression != null)
          pn.getField().setInitialValueExpression(initialValueExpression);

        if (pn.getGetterBlock() == null && getterBlock != null) pn.setGetterBlock(getterBlock);

        if (pn.getSetterBlock() == null && setterBlock != null) pn.setSetterBlock(setterBlock);

        return pn;
      }
    }
    PropertyNode node =
        new PropertyNode(
            name, modifiers, type, redirect(), initialValueExpression, getterBlock, setterBlock);
    addProperty(node);
    return node;
  }
  private void injectAssociations(ClassNode classNode) {

    List properties = classNode.getProperties();
    List propertiesToAdd = new ArrayList();
    for (Iterator p = properties.iterator(); p.hasNext(); ) {
      PropertyNode pn = (PropertyNode) p.next();
      final boolean isHasManyProperty =
          pn.getName().equals(/*GrailsDomainClassProperty.*/ RELATES_TO_MANY)
              || pn.getName().equals(/*GrailsDomainClassProperty.*/ HAS_MANY);
      if (isHasManyProperty) {
        Expression e = pn.getInitialExpression();
        propertiesToAdd.addAll(createPropertiesForHasManyExpression(e, classNode));
      }
      final boolean isBelongsTo = pn.getName().equals(/*GrailsDomainClassProperty.*/ BELONGS_TO);
      if (isBelongsTo) {
        Expression e = pn.getInitialExpression();
        propertiesToAdd.addAll(createPropertiesForBelongsToExpression(e, classNode));
      }
    }
    injectAssociationProperties(classNode, propertiesToAdd);
  }
 private void addProperty(ClassNode cNode, PropertyNode pNode) {
   final FieldNode fn = pNode.getField();
   cNode.getFields().remove(fn);
   cNode.addProperty(
       pNode.getName(),
       pNode.getModifiers() | ACC_FINAL,
       pNode.getType(),
       pNode.getInitialExpression(),
       pNode.getGetterBlock(),
       pNode.getSetterBlock());
   final FieldNode newfn = cNode.getField(fn.getName());
   cNode.getFields().remove(newfn);
   cNode.addField(fn);
 }