Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Feature request: Custom extended type support #14

Open
alicederyn opened this issue Feb 8, 2015 · 0 comments
Open

Feature request: Custom extended type support #14

alicederyn opened this issue Feb 8, 2015 · 0 comments

Comments

@alicederyn
Copy link
Collaborator

alicederyn commented Feb 8, 2015

Current thinking is to support custom "single-property builder" templates, with the API cloned onto the enclosing builder. For instance, a Set template might look like:

public class SetPropertyTemplate<T>
    extends AbstractPropertyTemplate<Set<T>, SetPropertyTemplate<T>> {
  private final HashSet<T> property = new HashSet<>();
  public void addProperty(T element) {
    property.add(checkNotNull(element));
  }
  public void addAllProperty(Iterable<T> elements) {
    for (T element : elements) {
      addProperty(element);
    }
  }
  public void clearProperty() {
    property.clear();
  }
  public Set<T> getProperty() {
    return unmodifiableSet(property);
  }
  @Override public void mergeFrom(Set<T> elements) {
    addAllProperty(elements);
  }
  @Override public ImmutableSet<T> getImmutableValue() {
    return ImmutableSet.copyOf(property);
  }
  @Override public void clear() {
    property.clear();
  }
}

Here, "Property" is a magic string that gets replaced by the actual property name when the API is cloned, so for instance a set property called Values would result in methods addValues, addAllValues, clearValues and getValues. It should also be possible to inline the template definition as part of code generation, making custom extensions indistinguishable from built-in extensions. We could even use templates for all existing customization.

A key motivating example is values like IDs and timestamps that are generally minted at build time, but should not be overridden during deserialization.

@alicederyn alicederyn reopened this Feb 10, 2015
@alicederyn alicederyn changed the title Feature request: Support customized extended type support Feature request: customized extended type support Feb 10, 2015
@alicederyn alicederyn changed the title Feature request: customized extended type support Feature request: Customizable extended type support Feb 10, 2015
@alicederyn alicederyn changed the title Feature request: Customizable extended type support Feature request: Custom extended type support Feb 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant