Ejemplo n.º 1
0
  /**
   * Creates a method with a body for the getter.
   *
   * @return getter body
   */
  private String createGetterBody() {
    // TODO: use access modifier given by user

    int modifier = this.getGetterVisibility();
    if (field.isStatic()) {
      modifier |= BinModifier.STATIC;
    }
    BinMethod getter =
        new BinMethod(
            getterName,
            BinParameter.NO_PARAMS,
            getField().getTypeRef(),
            modifier,
            BinMethod.Throws.NO_THROWS);
    getter.setOwner(field.getOwner());

    BinMethodFormatter formatter = (BinMethodFormatter) getter.getFormatter();
    String result = FormatSettings.LINEBREAK + formatter.formHeader();

    // TODO migrate to formatting engine also?
    int baseIndent = new BinTypeFormatter(field.getOwner().getBinCIType()).getMemberIndent();
    result += FormatSettings.getIndentString(baseIndent + FormatSettings.getBlockIndent());
    result += "return ";
    if (field.isStatic()) {
      result += hostingClass.getName();
    } else {
      result += "this";
    }
    result += "." + getField().getName() + ";";
    result += FormatSettings.LINEBREAK;

    result += formatter.formFooter();

    return result;
  }
Ejemplo n.º 2
0
  public EncapsulateField(RefactorItContext context, BinField field) {
    super("EncapsulateField", context);

    this.field = field;

    setterName = PropertyNameUtil.getDefaultSetterName(field);
    getterName = PropertyNameUtil.getDefaultGetterName(field)[0];
    hostingClass = field.getOwner().getBinCIType();
  }
Ejemplo n.º 3
0
  public ManagingIndexer getSupervisor(BinField field) {
    if ((supervisor == null) || (accessorsChanged)) {
      supervisor = new ManagingIndexer();
      new EncapsulateFieldIndexer(supervisor, field, getterName, setterName);

      // Find usages
      if (field.isPrivate()) {
        supervisor.visit(field.getCompilationUnit());
      } else {
        supervisor.visit(field.getOwner().getProject());
      }
    }
    this.accessorsChanged = false;
    return supervisor;
  }