/** * 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); } } }
/** * Get a {@link CstFieldRef} that corresponds with this instance. * * @return {@code non-null;} the corresponding field reference */ public CstFieldRef getFieldRef() { if (fieldRef == null) { fieldRef = new CstFieldRef(getDefiningClass(), getNat()); } return fieldRef; } }
/** * Interns the given constant in the appropriate section of this * instance, or do nothing if the given constant isn't the sort * that should be interned. * * @param cst {@code non-null;} constant to possibly intern */ /*package*/ void internIfAppropriate(Constant cst) { if (cst instanceof CstString) { stringIds.intern((CstString) cst); } else if (cst instanceof CstType) { typeIds.intern((CstType) cst); } else if (cst instanceof CstBaseMethodRef) { methodIds.intern((CstBaseMethodRef) cst); } else if (cst instanceof CstFieldRef) { fieldIds.intern((CstFieldRef) cst); } else if (cst instanceof CstEnumRef) { fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst == null) { throw new NullPointerException("cst == null"); } }
/** * {@inheritDoc} * * <b>Note:</b> This returns the enumerated type. */ public Type getType() { return getDefiningClass().getClassType(); }
/** * Get a {@link CstFieldRef} that corresponds with this instance. * * @return {@code non-null;} the corresponding field reference */ public CstFieldRef getFieldRef() { if (fieldRef == null) { fieldRef = new CstFieldRef(getDefiningClass(), getNat()); } return fieldRef; } }
/** * Interns the given constant in the appropriate section of this * instance, or do nothing if the given constant isn't the sort * that should be interned. * * @param cst {@code non-null;} constant to possibly intern */ /*package*/ void internIfAppropriate(Constant cst) { if (cst instanceof CstString) { stringIds.intern((CstString) cst); } else if (cst instanceof CstType) { typeIds.intern((CstType) cst); } else if (cst instanceof CstBaseMethodRef) { methodIds.intern((CstBaseMethodRef) cst); } else if (cst instanceof CstFieldRef) { fieldIds.intern((CstFieldRef) cst); } else if (cst instanceof CstEnumRef) { fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst == null) { throw new NullPointerException("cst == null"); } }
/** * {@inheritDoc} * * <b>Note:</b> This returns the enumerated type. */ @Override public Type getType() { return getDefiningClass().getClassType(); }
/** * Get a {@link CstFieldRef} that corresponds with this instance. * * @return {@code non-null;} the corresponding field reference */ public CstFieldRef getFieldRef() { if (fieldRef == null) { fieldRef = new CstFieldRef(getDefiningClass(), getNat()); } return fieldRef; } }
/** * Interns the given constant in the appropriate section of this * instance, or do nothing if the given constant isn't the sort * that should be interned. * * @param cst {@code non-null;} constant to possibly intern */ /*package*/ void internIfAppropriate(Constant cst) { if (cst instanceof CstString) { stringIds.intern((CstString) cst); } else if (cst instanceof CstType) { typeIds.intern((CstType) cst); } else if (cst instanceof CstBaseMethodRef) { methodIds.intern((CstBaseMethodRef) cst); } else if (cst instanceof CstFieldRef) { fieldIds.intern((CstFieldRef) cst); } else if (cst instanceof CstEnumRef) { fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst == null) { throw new NullPointerException("cst == null"); } }
/** * 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); } } }
/** * {@inheritDoc} * * <b>Note:</b> This returns the enumerated type. */ public Type getType() { return getDefiningClass().getClassType(); }
/** * Get a {@link CstFieldRef} that corresponds with this instance. * * @return {@code non-null;} the corresponding field reference */ public CstFieldRef getFieldRef() { if (fieldRef == null) { fieldRef = new CstFieldRef(getDefiningClass(), getNat()); } return fieldRef; } }
/** * Interns the given constant in the appropriate section of this * instance, or do nothing if the given constant isn't the sort * that should be interned. * * @param cst {@code non-null;} constant to possibly intern */ /*package*/ void internIfAppropriate(Constant cst) { if (cst instanceof CstString) { stringIds.intern((CstString) cst); } else if (cst instanceof CstType) { typeIds.intern((CstType) cst); } else if (cst instanceof CstBaseMethodRef) { methodIds.intern((CstBaseMethodRef) cst); } else if (cst instanceof CstFieldRef) { fieldIds.intern((CstFieldRef) cst); } else if (cst instanceof CstEnumRef) { fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst == null) { throw new NullPointerException("cst == null"); } }
return new CstEnumRef(new CstNat(constName, typeName));
/** * {@inheritDoc} * * <b>Note:</b> This returns the enumerated type. */ @Override public Type getType() { return getDefiningClass().getClassType(); }
/** * Get a {@link CstFieldRef} that corresponds with this instance. * * @return {@code non-null;} the corresponding field reference */ public CstFieldRef getFieldRef() { if (fieldRef == null) { fieldRef = new CstFieldRef(getDefiningClass(), getNat()); } return fieldRef; } }
/** * Interns the given constant in the appropriate section of this * instance, or do nothing if the given constant isn't the sort * that should be interned. * * @param cst {@code non-null;} constant to possibly intern */ /*package*/ void internIfAppropriate(Constant cst) { if (cst instanceof CstString) { stringIds.intern((CstString) cst); } else if (cst instanceof CstType) { typeIds.intern((CstType) cst); } else if (cst instanceof CstBaseMethodRef) { methodIds.intern((CstBaseMethodRef) cst); } else if (cst instanceof CstFieldRef) { fieldIds.intern((CstFieldRef) cst); } else if (cst instanceof CstEnumRef) { fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst == null) { throw new NullPointerException("cst == null"); } }
return new CstEnumRef(new CstNat(constName, typeName));
/** * {@inheritDoc} * * <b>Note:</b> This returns the enumerated type. */ public Type getType() { return getDefiningClass().getClassType(); }
/** * Get a {@link CstFieldRef} that corresponds with this instance. * * @return {@code non-null;} the corresponding field reference */ public CstFieldRef getFieldRef() { if (fieldRef == null) { fieldRef = new CstFieldRef(getDefiningClass(), getNat()); } return fieldRef; } }