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;
  }
  public void visitProperty(PropertyNode node) {
    visitAnnotations(node);
    Statement statement = node.getGetterBlock();
    visitClassCodeContainer(statement);

    statement = node.getSetterBlock();
    visitClassCodeContainer(statement);

    Expression init = node.getInitialExpression();
    if (init != null) init.visit(this);
  }
 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);
 }