001package daikon.inv;
002
003import daikon.PptSlice;
004import daikon.PptTopLevel;
005import org.checkerframework.checker.lock.qual.GuardSatisfied;
006import org.checkerframework.dataflow.qual.Pure;
007
008/**
009 * This is a special implication invariant that guards any invariants that are over variables that
010 * are sometimes missing. For example, if the invariant {@code a.x = 0} is true, the guarded
011 * implication is {@code a != null => a.x = 0}.
012 */
013public class GuardingImplication extends Implication {
014  // We are Serializable, so we specify a version to allow changes to
015  // method signatures without breaking serialization.  If you add or
016  // remove fields, you should change this number to the current date.
017  static final long serialVersionUID = 20020725L;
018
019  private GuardingImplication(
020      PptSlice ppt, Invariant predicate, Invariant consequent, boolean iff) {
021    super(ppt, predicate, consequent, iff, predicate, consequent);
022  }
023
024  // Do not call this!  The only location these should be created is in
025  // Invariant.createGuardedInvariant().  (I need to find a way to enforce this.)
026  // A GuardingImplication is never installed in a PptMap -- it's only
027  // printed by using format_using.
028  public static GuardingImplication makeGuardingImplication(
029      PptTopLevel ppt, Invariant predicate, Invariant consequent, boolean iff) {
030    assert predicate != null;
031    assert consequent != null;
032
033    // No duplicate check because the way it is set up no duplicates should
034    // occur:  No invariants are duplicates, and since each guarding
035    // implication is based off of an existing invariant in a PptSlice, we
036    // are guarenteed no duplicate guarding implications exist.
037
038    GuardingImplication result =
039        new GuardingImplication(ppt.joiner_view, predicate, consequent, iff);
040    return result;
041  }
042
043  @Pure
044  @Override
045  public boolean isWorthPrinting() {
046    return right.isWorthPrinting();
047    // return !right.isObvious();
048  }
049
050  @Override
051  public boolean enoughSamples(@GuardSatisfied GuardingImplication this) {
052    return right.enoughSamples();
053  }
054
055  @Override
056  public double computeConfidence() {
057    return right.computeConfidence();
058  }
059}