package arez.processor;

import com.squareup.javapoet.MethodSpec;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;

/**
 * Declaration of a field that must be cascade disposed.
 */
final class CascadeDisposableDescriptor
{
  @Nullable
  private final ExecutableElement _method;
  @Nullable
  private final VariableElement _field;

  CascadeDisposableDescriptor( @Nonnull final VariableElement field )
  {
    _method = null;
    _field = Objects.requireNonNull( field );
  }

  CascadeDisposableDescriptor( @Nonnull final ExecutableElement method )
  {
    _method = Objects.requireNonNull( method );
    _field = null;
  }

  @Nonnull
  ExecutableElement getMethod()
  {
    assert null != _method;
    return _method;
  }

  @Nonnull
  VariableElement getField()
  {
    assert null != _field;
    return _field;
  }

  void buildDisposer( @Nonnull final MethodSpec.Builder builder )
  {
    if ( null != _field )
    {
      builder.addStatement( "$T.dispose( $N )", GeneratorUtil.DISPOSABLE_CLASSNAME, _field.getSimpleName().toString() );
    }
    else
    {
      assert null != _method;
      builder.addStatement( "$T.dispose( $N() )",
                            GeneratorUtil.DISPOSABLE_CLASSNAME,
                            _method.getSimpleName().toString() );
    }
  }
}

@@ -766,203 +766,8 @@
  %7D%0A%0A
-  @Nonnull%0A  ExecutableElement getMethod()%0A  %7B%0A    assert null != _method;%0A    return _method;%0A  %7D%0A%0A  @Nonnull%0A  VariableElement getField()%0A  %7B%0A    assert null != _field;%0A    return _field;%0A  %7D%0A%0A
   vo

Remove some unused methods