001// A dummy invariant used for testing purposes 002 003package daikon.test.diff; 004 005import daikon.*; 006import daikon.inv.*; 007import java.util.List; 008import org.checkerframework.checker.lock.qual.GuardSatisfied; 009import org.checkerframework.checker.nullness.qual.Nullable; 010import org.checkerframework.dataflow.qual.Pure; 011import org.checkerframework.dataflow.qual.SideEffectFree; 012import typequals.prototype.qual.NonPrototype; 013import typequals.prototype.qual.Prototype; 014 015/** A dummy invariant used for testing purposes. */ 016public class DiffDummyInvariant extends Invariant { 017 // We are Serializable, so we specify a version to allow changes to 018 // method signatures without breaking serialization. If you add or 019 // remove fields, you should change this number to the current date. 020 static final long serialVersionUID = 20020122L; 021 022 /** A string representation of the formula that this dummy invariant represents. */ 023 public String formula; 024 025 /** The confidence fro this dummy invariant. */ 026 public double confidence; 027 028 /** Whether the invariant is worth printing. */ 029 public boolean isWorthPrinting; 030 031 /** Create an instance of DiffDummyInvariant. */ 032 public DiffDummyInvariant(PptSlice ppt, String formula, boolean justified) { 033 this(ppt, formula, justified, true); 034 } 035 036 /** Create an instance of DiffDummyInvariant. */ 037 public DiffDummyInvariant( 038 PptSlice ppt, String formula, boolean justified, boolean isWorthPrinting) { 039 this( 040 ppt, 041 formula, 042 (justified ? Invariant.CONFIDENCE_JUSTIFIED : Invariant.CONFIDENCE_UNJUSTIFIED), 043 isWorthPrinting); 044 } 045 046 /** Create an instance of DiffDummyInvariant. */ 047 public DiffDummyInvariant(PptSlice ppt, String formula, double confidence) { 048 this(ppt, formula, confidence, true); 049 } 050 051 /** Create an instance of DiffDummyInvariant. */ 052 public DiffDummyInvariant( 053 PptSlice ppt, String formula, double confidence, boolean isWorthPrinting) { 054 super(ppt); 055 this.formula = formula; 056 this.confidence = confidence; 057 this.isWorthPrinting = isWorthPrinting; 058 } 059 060 @Override 061 protected Invariant resurrect_done(int[] permutation) { 062 throw new UnsupportedOperationException(); 063 } 064 065 @Pure 066 @Override 067 public boolean isSameInvariant(Invariant other) { 068 return this.isSameFormula(other); 069 } 070 071 @Pure 072 @Override 073 public boolean isSameFormula(Invariant other) { 074 if (other instanceof DiffDummyInvariant) { 075 DiffDummyInvariant o = (DiffDummyInvariant) other; 076 return this.formula.equals(o.formula); 077 } else { 078 return false; 079 } 080 } 081 082 @Override 083 public double computeConfidence() { 084 return confidence; 085 } 086 087 @Override 088 public String repr(@GuardSatisfied DiffDummyInvariant this) { 089 return "DiffDummyInvariant(" + ppt.arity() + "," + formula + "," + confidence + ")"; 090 } 091 092 @SideEffectFree 093 @Override 094 public String format_using(@GuardSatisfied DiffDummyInvariant this, OutputFormat format) { 095 return repr(); 096 } 097 098 // IsWorthPrinting should not be overridden by subclasses. 099 // But this subclass is special: it's not really an invariant, 100 // but is only used for testing. 101 @Pure 102 @Override 103 public boolean isWorthPrinting() { 104 return isWorthPrinting; 105 } 106 107 @Override 108 public boolean enabled() { 109 throw new Error("do not invoke " + getClass() + ".enabled()"); 110 } 111 112 @Override 113 public boolean valid_types(VarInfo[] vis) { 114 throw new Error("do not invoke " + getClass() + ".valid_types()"); 115 } 116 117 @Override 118 protected DiffDummyInvariant instantiate_dyn(PptSlice slice) { 119 throw new Error("do not invoke " + getClass() + ".instantiate_dyn()"); 120 } 121 122 @Override 123 public @Nullable @NonPrototype DiffDummyInvariant merge( 124 @Prototype DiffDummyInvariant this, List<@NonPrototype Invariant> invs, PptSlice parent_ppt) { 125 throw new Error("do not merge DiffDummyInvariant"); 126 } 127}