/** * 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; }
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(); }
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; }