/** * The method needs more information from the properties than the CodePosition version of this * method provides, like getting the base symbol code for the scheme and the hierarchy addition. */ public CodePosition addPositionChoice(int index, String entry, String prefix, Properties props) { CodeScheme cs = (CodeScheme) super.addPositionChoice(index, entry, prefix, props); prefix = PropUtils.getScopedPropertyPrefix(prefix) + entry + "."; String next = props.getProperty(prefix + NextProperty); if (next != null) { String nextClassName = props.getProperty(next + ".class"); if (nextClassName != null) { CodePosition cp = (CodePosition) ComponentFactory.create(nextClassName); if (DEBUG) { Debug.output("CodeScheme created next class(" + next + "), " + nextClassName); } if (cp != null) { cs.nextPosition = cp; cp.parsePositions(next, props); } } else { if (DEBUG) { Debug.output("CodeScheme couldn't create next class(" + next + "), " + nextClassName); } } } cs.defaultSymbolCode = props.getProperty(prefix + DefaultSymbolCodeProperty); cs.hierarchyAddition = props.getProperty(prefix + HierarchyCodeAdditionProperty, ""); // Don't need to add to choices, already done in super class // method. return cs; }
@ThreadedTest public void getPosition_atEndOfLastMethod() throws Exception { control.add(0, 0); CodePosition cp = recorder.atEndOfLastMethod().position(); CodePosition verification = ic.atMethodEnd(SimpleClass.class.getDeclaredMethod("add", int.class, int.class)); assertTrue(verification.matches(cp)); }
/** * Parse the hierarchy properties to create SymbolParts for those parts under a particular scheme * represented by this instance of CodeScheme. * * @param hCode the hierarchy code of this scheme, used to grow the tree for subsequent * generations. * @param props the hierarchy properties. * @param parent the SymbolPart parent that the new SymbolPart tree falls under. */ public void parseHierarchy(String hCode, Properties props, SymbolPart parent) { List codePositionList = null; if (nextPosition != null) { codePositionList = nextPosition.getPositionChoices(); } if (codePositionList == null || codePositionList.isEmpty()) { Debug.output(prettyName + ".parseHierarchy(): codePositionList.size = 0"); return; } List parentList = null; for (Iterator it = codePositionList.iterator(); it.hasNext(); ) { CodePosition cp = (CodePosition) it.next(); String newHCode = hCode + "." + cp.getHierarchyNumber(); if (DEBUG) { Debug.output("CodeScheme.parse: " + newHCode + " with " + cp.getPrettyName()); } String entry = props.getProperty(newHCode); if (entry != null) { SymbolPart sp = new SymbolPart(cp, entry, props, parent); if (parentList == null) { parentList = parent.getSubs(); if (parentList == null) { parentList = new ArrayList(); parent.setSubs(parentList); } } if (DEBUG) { Debug.output( "CodeScheme.parse: adding " + sp.getPrettyName() + " to " + parent.getPrettyName()); } parentList.add(sp); if (DEBUG) { Debug.output( "CodeScheme.parse: handling " + cp.getPrettyName() + " children for " + sp.getPrettyName()); } cp.parseHierarchy(newHCode, props, sp); } else { if (DEBUG) { Debug.output("CodeScheme.parse: no entry found for " + newHCode); } } } }
@ThreadedTest public void getPosition_atStart() throws Exception { final SimpleInteger value = new SimpleInteger(0); CodePosition cp = recorder.atStartOf(control.add(value, value)).position(); CodePosition verification = ic.atMethodStart( SimpleClass.class.getDeclaredMethod("add", SimpleInteger.class, SimpleInteger.class)); assertTrue(verification.matches(cp)); }
@ThreadedTest public void getPosition_afterCall() throws Exception { SimpleClass2 target = recorder.createTarget(SimpleClass2.class); control.add(0, 0); CodePosition cp = recorder.in(control.callSecond()).afterCalling(target.setPosition(null, 0)).position(); CodePosition verification = ic.afterCall( SimpleClass.class.getDeclaredMethod("callSecond"), SimpleClass2.class.getDeclaredMethod("setPosition", SimpleClass.class, int.class)); assertTrue(verification.matches(cp)); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } BugInstanceKey other = (BugInstanceKey) obj; if (bugPattern == null) { if (other.bugPattern != null) { return false; } } else if (!bugPattern.equals(other.bugPattern)) { return false; } if (bugPosition == null) { if (other.bugPosition != null) { return false; } } else if (!bugPosition.equals(other.bugPosition)) { return false; } return true; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((bugPattern == null) ? 0 : bugPattern.hashCode()); result = prime * result + ((bugPosition == null) ? 0 : bugPosition.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (portableEquals(obj)) { BugInstance other = (BugInstance) obj; if (bugPosition == null) { if (other.bugPosition != null) { return false; } } else if (!bugPosition.equals(other.bugPosition)) { return false; } return true; } return false; }
public boolean portableEquals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BugInstance other = (BugInstance) obj; if (bugPattern == null) { if (other.bugPattern != null) return false; } else if (!bugPattern.equals(other.bugPattern)) return false; if (bugPosition == null) { if (other.bugPosition != null) return false; } else if (!bugPosition.portableEquals(other.bugPosition)) return false; if (fixInformation == null) { if (other.fixInformation != null) return false; } else if (!fixInformation.equals(other.fixInformation)) return false; return true; }