1 19 20 package edu.umd.cs.findbugs.ba.npe; 21 22 import edu.umd.cs.findbugs.annotations.CheckForNull; 23 import edu.umd.cs.findbugs.ba.EdgeTypes; 24 import edu.umd.cs.findbugs.ba.vna.ValueNumber; 25 import edu.umd.cs.findbugs.util.Strings; 26 import edu.umd.cs.findbugs.util 27 .Util; 28 37 public class IsNullConditionDecision implements EdgeTypes { 38 private final @CheckForNull ValueNumber value; 39 private final @CheckForNull IsNullValue ifcmpDecision; 40 private final @CheckForNull IsNullValue fallThroughDecision; 41 42 50 public IsNullConditionDecision(@CheckForNull ValueNumber value, @CheckForNull IsNullValue ifcmpDecision, @CheckForNull IsNullValue fallThroughDecision) { 51 this.value = value; 52 53 assert !(ifcmpDecision == null && fallThroughDecision == null); 55 this.ifcmpDecision = ifcmpDecision; 56 this.fallThroughDecision = fallThroughDecision; 57 } 58 59 public int hashCode() { 60 return Util.nullSafeHashcode(value) + 5 61 * Util.nullSafeHashcode(ifcmpDecision) + 17 62 * Util.nullSafeHashcode(fallThroughDecision); 63 } 64 65 public boolean equals(Object o) { 66 if (!(o instanceof IsNullConditionDecision)) 67 return false; 68 IsNullConditionDecision other = (IsNullConditionDecision) o; 69 return Util.nullSafeEquals(value, other.value) 70 && Util.nullSafeEquals(ifcmpDecision, other.ifcmpDecision) 71 && Util.nullSafeEquals(fallThroughDecision, 72 other.fallThroughDecision); 73 } 74 77 public ValueNumber getValue() { 78 return value; 79 } 80 81 84 public boolean isRedundant() { 85 return ifcmpDecision == null || fallThroughDecision == null; 86 } 87 88 96 public boolean isEdgeFeasible(int edgeType) { 97 IsNullValue decision = getDecision(edgeType); 98 return decision != null; 99 } 100 101 108 public @CheckForNull IsNullValue getDecision(int edgeType) { 109 assert edgeType == IFCMP_EDGE || edgeType == FALL_THROUGH_EDGE; 110 if (edgeType == IFCMP_EDGE) 111 return ifcmpDecision; 112 else 113 return fallThroughDecision; 114 } 115 116 @Override 117 public String toString() { 118 StringBuffer buf = new StringBuffer (); 119 buf.append(value != null ? value.toString() : "NoValue,"); 120 buf.append("ifcmp="); 121 buf.append(ifcmpDecision != null ? Strings.trimComma(ifcmpDecision.toString()) : "INFEASIBLE"); 122 buf.append(",fallthru="); 123 buf.append(fallThroughDecision != null ? Strings.trimComma(fallThroughDecision.toString()) : "INFEASIBLE"); 124 return buf.toString(); 125 } 126 } 127 128 | Popular Tags |