/** * Convert a value of an element to a {@code Constant}. * <p><strong>Warning:</strong> Array or TypeId value is not supported yet. * * @param value an annotation element value. * @return a Constant */ static Constant toConstant(Object value) { Class clazz = value.getClass(); if (clazz.isEnum()) { CstString descriptor = new CstString(TypeId.get(clazz).getName()); CstString name = new CstString(((Enum)value).name()); CstNat cstNat = new CstNat(name, descriptor); return new CstEnumRef(cstNat); } else if (clazz.isArray()) { throw new UnsupportedOperationException("Array is not supported yet"); } else if (value instanceof TypeId) { throw new UnsupportedOperationException("TypeId is not supported yet"); } else { return Constants.getConstant(value); } } }
/** * Interns the components of a name-and-type into this instance. * * @param nat {@code non-null;} the name-and-type */ public synchronized void intern(CstNat nat) { intern(nat.getName()); intern(nat.getDescriptor()); }
/** * Returns the type of this field. * * @return {@code non-null;} the field's type */ @Override public Type getType() { return getNat().getFieldType(); }
/** * Gets whether this is a reference to an instance initialization * method. This is just a convenient shorthand for * {@code getNat().isInstanceInit()}. * * @return {@code true} iff this is a reference to an * instance initialization method */ public final boolean isInstanceInit() { return getNat().isInstanceInit(); }
/** {@inheritDoc} */ @Override public String toString() { return "nat{" + toHuman() + '}'; }
/** {@inheritDoc} */ @Override public final boolean equals(Object other) { if ((other == null) || (getClass() != other.getClass())) { return false; } CstMemberRef otherRef = (CstMemberRef) other; return definingClass.equals(otherRef.definingClass) && nat.equals(otherRef.nat); }
/** * Gets whether this is a reference to a class initialization * method. This is just a convenient shorthand for * {@code getNat().isClassInit()}. * * @return {@code true} iff this is a reference to an * instance initialization method */ public final boolean isClassInit() { return getNat().isClassInit(); }
/** {@inheritDoc} */ @Override public final CstString getName() { return nat.getName(); }
/** {@inheritDoc} */ @Override public final int hashCode() { return (definingClass.hashCode() * 31) ^ nat.hashCode(); }
/** {@inheritDoc} */ @Override public final CstString getDescriptor() { return nat.getDescriptor(); }
/** * Interns the components of a name-and-type into this instance. * * @param nat {@code non-null;} the name-and-type */ public void intern(CstNat nat) { intern(nat.getName()); intern(nat.getDescriptor()); }
/** * Constructs an instance. * * @param nat {@code non-null;} the name-and-type; the defining class is derived * from this */ public CstEnumRef(CstNat nat) { super(new CstType(nat.getFieldType()), nat); fieldRef = null; }
/** * Gets whether this is a reference to an instance initialization * method. This is just a convenient shorthand for * {@code getNat().isInstanceInit()}. * * @return {@code true} iff this is a reference to an * instance initialization method */ public final boolean isInstanceInit() { return getNat().isInstanceInit(); }
/** {@inheritDoc} */ @Override public String toString() { return "nat{" + toHuman() + '}'; }
/** {@inheritDoc} */ @Override public final boolean equals(Object other) { if ((other == null) || (getClass() != other.getClass())) { return false; } CstMemberRef otherRef = (CstMemberRef) other; return definingClass.equals(otherRef.definingClass) && nat.equals(otherRef.nat); }
/** * Gets whether this is a reference to a class initialization * method. This is just a convenient shorthand for * {@code getNat().isClassInit()}. * * @return {@code true} iff this is a reference to an * instance initialization method */ public final boolean isClassInit() { return getNat().isClassInit(); }
/** {@inheritDoc} */ @Override public CstString getName() { return field.getNat().getName(); }
/** {@inheritDoc} */ @Override public final int hashCode() { return (definingClass.hashCode() * 31) ^ nat.hashCode(); }
/** {@inheritDoc} */ @Override public final CstString getDescriptor() { return nat.getDescriptor(); }