// in class ReferenceBinding: /** Insert a method into a sorted array. */ public static MethodBinding[] sortedInsert(MethodBinding[] sortedMethods, MethodBinding newMethod) { if (sortedMethods != null) { int max = sortedMethods.length; if (max > 0) { int insertBefore = 0; int left = 0, right = max - 1; int mid = 0; while (left <= right) { mid = (left + right) /2; MethodBinding midM = sortedMethods[mid]; int compare = METHOD_COMPARATOR.compare(newMethod, midM); if (compare < 0) { right = mid-1; insertBefore = mid; } else if (compare > 0) { left = mid+1; insertBefore = mid+1; } else { insertBefore = mid; break; // mid's name is equal to `name' } } MethodBinding[] result = new MethodBinding[max+1]; System.arraycopy(sortedMethods, 0, result, 0, insertBefore); System.arraycopy(sortedMethods, insertBefore, result, insertBefore+1, max-insertBefore); result[insertBefore] = newMethod; return result; } } return new MethodBinding[] {newMethod}; } // in class SourceTypeBinding: /** Add a method respecting the current state wrt sorting and resolving. */ public void addMethod(MethodBinding methodBinding) { int size = this.methods.length; if ((this.tagBits & TagBits.AreMethodsComplete) != 0) if (this.resolveTypesFor(methodBinding) == null) return; // don't add erroenous method // differentiate between sorted and unsorted state: if ((this.tagBits & TagBits.AreMethodsSorted) != 0) { this.methods= ReferenceBinding.sortedInsert(this.methods, methodBinding); } else { //grow array System.arraycopy(this.methods, 0, this.methods= new MethodBinding[size + 1], 0, size); this.methods[size] = methodBinding; } }