001package daikon.derive.unary; 002 003import daikon.Global; 004import daikon.VarInfo; 005import java.util.logging.Level; 006import java.util.logging.Logger; 007import org.checkerframework.checker.nullness.qual.Nullable; 008 009public final class SequenceLengthFactory extends UnaryDerivationFactory { 010 011 /** Debug output. */ 012 public static final Logger debug = Logger.getLogger("daikon.derive.unary.SequenceLengthFactory"); 013 014 @Override 015 public UnaryDerivation @Nullable [] instantiate(VarInfo vi) { 016 if (!SequenceLength.dkconfig_enabled) { 017 return null; 018 } 019 020 if (!vi.is_direct_array()) { 021 return null; 022 } 023 024 if (!vi.aux.hasSize()) { 025 // Don't derive if auxiliary info says size of this collection 026 // has no meaning 027 return null; 028 } 029 030 if (!SequenceLength.applicable(vi)) { 031 Global.tautological_suppressed_derived_variables++; 032 return null; 033 } 034 035 if (debug.isLoggable(Level.FINE)) { 036 debug.fine("Instantiating for " + vi.name() + " in " + vi.ppt); 037 } 038 039 if (vi.aux.nullTerminating()) { 040 return new UnaryDerivation[] {new SequenceLength(vi, 0), new SequenceLength(vi, -1)}; 041 } else { 042 // If it can't terminate with nulls, then all members are important, 043 // so we only need to do shift for 0 044 return new UnaryDerivation[] {new SequenceLength(vi, 0)}; 045 } 046 } 047}