Source:
<code><START> public String canSubmit(final PatchSet.Id patchSetId, final ReviewDb db, <END> final ApprovalTypes approvalTypes, FunctionState.Factory functionStateFactory) throws OrmException { if (change.getStatus().isClosed()) { return "Change " + patchSetId.getParentKey() + " is closed"; } if (!patchSetId.equals(change.currentPatchSetId())) { return "Patch set " + patchSetId + " not current"; } if (!getRefControl().canSubmit()) { return "User does not have permission to submit"; } final List<PatchSetApproval> allApprovals = new ArrayList<PatchSetApproval>(db.patchSetApprovals().byPatchSet( patchSetId).toList()); if(!(getCurrentUser() instanceof IdentifiedUser)) { throw new IllegalArgumentException("user is not identified"); } final PatchSetApproval myAction = ChangeUtil.createSubmitApproval(patchSetId, (IdentifiedUser) getCurrentUser(), db); final ApprovalType actionType = approvalTypes.getApprovalType(myAction.getCategoryId()); if (actionType == null || !actionType.getCategory().isAction()) { throw new IllegalArgumentException(myAction.getCategoryId() + " not an action"); } final FunctionState fs = functionStateFactory.create(change, patchSetId, allApprovals); for (ApprovalType c : approvalTypes.getApprovalTypes()) { CategoryFunction.forCategory(c.getCategory()).run(c, fs); } if (!CategoryFunction.forCategory(actionType.getCategory()).isValid( getCurrentUser(), actionType, fs)) { return actionType.getCategory().getName() + " not permitted"; } fs.normalize(actionType, myAction); if (myAction.getValue() <= 0) { return actionType.getCategory().getName() + " not permitted"; } return null; }</code><technical_language>I odd return a String here, null "good" result != null "bad result". Feels icky me. enum, some other sort of state object</technical_language>

Target:
public CanSubmitResult canSubmit(final PatchSet.Id patchSetId, final ReviewDb db, final ApprovalTypes approvalTypes, FunctionState.Factory functionStateFactory) throws OrmException { if (change.getStatus().isClosed()) { return new CanSubmitResult("Change " + change.getId() + " is closed"); } if (!patchSetId.equals(change.currentPatchSetId())) { return new CanSubmitResult("Patch set " + patchSetId + " is not current"); } if (!getRefControl().canSubmit()) { return new CanSubmitResult("User does not have permission to submit"); } if (!(getCurrentUser() instanceof IdentifiedUser)) { return new CanSubmitResult("User is not signed-in"); } final List<PatchSetApproval> allApprovals = new ArrayList<PatchSetApproval>(db.patchSetApprovals().byPatchSet( patchSetId).toList()); final PatchSetApproval myAction = ChangeUtil.createSubmitApproval(patchSetId, (IdentifiedUser) getCurrentUser(), db); final ApprovalType actionType = approvalTypes.getApprovalType(myAction.getCategoryId()); if (actionType == null || !actionType.getCategory().isAction()) { return new CanSubmitResult("Invalid action " + myAction.getCategoryId()); } final FunctionState fs = functionStateFactory.create(change, patchSetId, allApprovals); for (ApprovalType c : approvalTypes.getApprovalTypes()) { CategoryFunction.forCategory(c.getCategory()).run(c, fs); } if (!CategoryFunction.forCategory(actionType.getCategory()).isValid( getCurrentUser(), actionType, fs)) { return new CanSubmitResult(actionType.getCategory().getName() + " not permitted"); } fs.normalize(actionType, myAction); if (myAction.getValue() <= 0) { return new CanSubmitResult(actionType.getCategory().getName() + " not permitted"); } return CanSubmitResult.OK; }