1 19 package edu.umd.cs.findbugs.props; 20 21 22 import edu.umd.cs.findbugs.*; 23 import java.util.*; 24 25 33 public class WarningPropertySet implements Cloneable { 34 private Map<WarningProperty, Object > map; 35 36 @Override 37 public String toString() { 38 StringBuffer buf = new StringBuffer ("{ "); 39 for (Map.Entry<WarningProperty, Object > entry : map.entrySet()) { 40 WarningProperty prop = entry.getKey(); 41 Object attribute = entry.getValue(); 42 buf.append(" "); 43 buf.append(prop.getPriorityAdjustment()); 44 buf.append("\t"); 45 buf.append(prop.getName()); 46 buf.append("\t"); 47 buf.append(attribute); 48 buf.append("\n"); 49 } 50 buf.append("}\n"); 51 return buf.toString(); 52 } 53 54 58 public WarningPropertySet() { 59 this.map = new HashMap<WarningProperty, Object >(); 60 } 61 62 @Override 64 public Object clone() { 65 try { 66 return super.clone(); 67 } catch (CloneNotSupportedException e) { 68 throw new AssertionError (e); 69 } 70 } 71 72 80 public WarningPropertySet addProperty(WarningProperty prop) { 81 map.put(prop, Boolean.TRUE); 82 return this; 83 } 84 85 92 public WarningPropertySet setProperty(WarningProperty prop, String value) { 93 map.put(prop, value); 94 return this; 95 } 96 97 103 public void setProperty(WarningProperty prop, Boolean value) { 104 map.put(prop, value); 105 } 106 107 113 public boolean containsProperty(WarningProperty prop) { 114 return map.keySet().contains(prop); 115 } 116 117 126 public boolean checkProperty(WarningProperty prop, Object value) { 127 Object attribute = getProperty(prop); 128 return (attribute != null && attribute.equals(value)); 129 } 130 131 139 public Object getProperty(WarningProperty prop) { 140 return map.get(prop); 141 } 142 143 151 public int computePriority(int basePriority) { 152 boolean relaxedReporting = FindBugsAnalysisFeatures.isRelaxedMode(); 153 154 boolean atLeastMedium = false; 155 boolean falsePositive = false; 156 boolean atMostLow = false; 157 int priority = basePriority; 158 if (!relaxedReporting) { 159 for (WarningProperty warningProperty : map.keySet()) { 160 PriorityAdjustment adj = warningProperty.getPriorityAdjustment(); 161 if (adj == PriorityAdjustment.FALSE_POSITIVE) { 162 falsePositive = true; 163 }else if (adj == PriorityAdjustment.RAISE_PRIORITY) 164 165 --priority; 166 else if (adj == PriorityAdjustment.RAISE_PRIORITY_TO_AT_LEAST_NORMAL) { 167 168 --priority; 169 atLeastMedium = true; 170 } else if (adj == PriorityAdjustment.RAISE_PRIORITY_TO_HIGH) { 171 172 return Detector.HIGH_PRIORITY; 173 }else if (adj == PriorityAdjustment.LOWER_PRIORITY) { 174 ++priority; 175 }else if (adj == PriorityAdjustment.AT_MOST_LOW) { 176 priority++; 177 atMostLow = true; 178 }else if (adj == PriorityAdjustment.NO_ADJUSTMENT) { 179 assert true; } else throw new IllegalStateException ("Unknown priority " + adj); 181 182 } 183 if (atMostLow) return Math.min(Math.max(Detector.LOW_PRIORITY, priority), Detector.EXP_PRIORITY); 184 if (atLeastMedium && priority > Detector.NORMAL_PRIORITY) priority = Detector.NORMAL_PRIORITY; 185 else if (falsePositive && !atLeastMedium) return Detector.EXP_PRIORITY+1; 186 187 188 if (priority < Detector.HIGH_PRIORITY) 189 priority = Detector.HIGH_PRIORITY; 190 else if (priority > Detector.EXP_PRIORITY) 191 priority = Detector.EXP_PRIORITY; 192 } 193 194 return priority; 195 } 196 197 204 public boolean isFalsePositive(int priority) { 205 return priority > Detector.EXP_PRIORITY; 206 } 207 208 213 public void decorateBugInstance(BugInstance bugInstance) { 214 for (Map.Entry<WarningProperty, Object > entry : map.entrySet()) { 215 WarningProperty prop = entry.getKey(); 216 Object attribute = entry.getValue(); 217 if (attribute == null) 218 attribute = ""; 219 bugInstance.setProperty(prop.getName(), attribute.toString()); 220 } 221 } 222 } 223 | Popular Tags |