1 package annotations.el; 2 3 import annotations.util.Hasher; 4 5 /*>>> 6 import org.checkerframework.checker.nullness.qual.*; 7 */ 8 9 /** 10 * A {@link BoundLocation} holds location information for a bound of a type 11 * parameter of a class or method: parameter index and bound index. 12 * It also handles type parameters themselves (not just the bound part). 13 * It would be better named "TypeParameterLocation", or the two uses could 14 * be separated out. 15 */ 16 public final class BoundLocation { 17 /** 18 * The index of the parameter to which the bound applies among all 19 * type parameters of the class or method. 20 */ 21 public final int paramIndex; 22 23 /** 24 * The index of the bound among all bounds on the type parameter. 25 * -1 if for the type parameter itself. 26 */ 27 public final int boundIndex; 28 29 /** 30 * Constructs a new {@link BoundLocation}; the arguments are assigned to 31 * the fields of the same names. 32 */ 33 public BoundLocation(int paramIndex, int boundIndex) { 34 this.paramIndex = paramIndex; 35 this.boundIndex = boundIndex; 36 } 37 38 /** 39 * Returns whether this {@link BoundLocation} equals <code>o</code>; a 40 * slightly faster variant of {@link #equals(Object)} for when the argument 41 * is statically known to be another nonnull {@link BoundLocation}. 42 */ 43 public boolean equals(BoundLocation l) { 44 return paramIndex == l.paramIndex && boundIndex == l.boundIndex; 45 } 46 47 /** 48 * This {@link BoundLocation} equals <code>o</code> if and only if 49 * <code>o</code> is another nonnull {@link BoundLocation} and 50 * <code>this</code> and <code>o</code> have equal {@link #paramIndex} 51 * and {@link #boundIndex}. 52 */ 53 @Override 54 public boolean equals(Object o) { 55 return o instanceof BoundLocation 56 && equals((BoundLocation) o); 57 } 58 59 /** 60 * {@inheritDoc} 61 */ 62 @Override 63 public int hashCode() { 64 Hasher h = new Hasher(); 65 h.mash(paramIndex); 66 h.mash(boundIndex); 67 return h.hash; 68 } 69 70 @Override 71 public String toString() { 72 return "BoundLocation(" + paramIndex + "," + boundIndex + ")"; 73 } 74 } 75