本文整理匯總了Java中java.lang.reflect.Field.getAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.getAnnotation方法的具體用法?Java Field.getAnnotation怎麽用?Java Field.getAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Field
的用法示例。
在下文中一共展示了Field.getAnnotation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAllProtbufFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static final Map<Field, ProtobufAttribute> getAllProtbufFields(
Class<? extends Object> fromClazz) {
Map<Field, ProtobufAttribute> protoBufFields =
CLASS_TO_FIELD_MAP_CACHE.get(fromClazz.getCanonicalName());
if (protoBufFields != null) {
return protoBufFields;
} else {
protoBufFields = new HashMap<>();
}
final List<Field> fields = JReflectionUtils.getAllFields(new ArrayList<Field>(), fromClazz);
for (Field field : fields) {
final Annotation annotation = field.getAnnotation(ProtobufAttribute.class);
if (annotation == null) {
continue;
}
final ProtobufAttribute gpbAnnotation = (ProtobufAttribute) annotation;
protoBufFields.put(field, gpbAnnotation);
}
CLASS_TO_FIELD_MAP_CACHE.put(fromClazz.getCanonicalName(), protoBufFields);
return protoBufFields;
}
示例2: CollectionProperty
import java.lang.reflect.Field; //導入方法依賴的package包/類
public CollectionProperty(EntityMetadata metadata, Field field) {
super(metadata, field);
Collection collection = field.getAnnotation(Collection.class);
if(!java.util.Collection.class.isAssignableFrom(field.getType())){
throw new HibatisException("Collection屬性必須為集合類型");
}
this.isLazy = collection.lazy();
this.isIn = collection.in();
this.cacheable = collection.cacheable();
ParameterizedType type = (ParameterizedType) field.getGenericType();
this.referenceType = (Class<?>) type.getActualTypeArguments()[0];
this.rawType = field.getType();
if(this.rawType != List.class){
throw new HibatisException("@Collection隻支持java.util.List類型");
}
this.setProperties(collection.property());
this.setReferences(collection.reference());
String[] orderBy = collection.orderBy();
if(orderBy != null){
sorts = new Sort[orderBy.length];
for (int i = 0; i < sorts.length; i++) {
String order = orderBy[i];
sorts[i] = Sort.parse(order);
}
}
}
示例3: compose
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public String compose(String fieldValue, Field idField, Class<?> clazz) {
final Id id = idField.getAnnotation(Id.class);
if (id == null) {
throw new IllegalArgumentException("Missing Id-annotation on Id-annotated field? Weird...");
} else {
return id.prefix() + fieldValue + id.suffix();
}
}
示例4: getTiedName
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* 得到字段的綁定名稱,如果含有{@linkplain ExceptDBField}注解則會返回null。
*
* @param field 使用{@linkplain PortInObj.Nece}、{@linkplain DBField}或{@linkplain PortInObj.UnNece
* }注解標注字段,使用{@linkplain DBField}來映射數據庫字段名。
*/
public static String getTiedName(Field field)
{
if (field.isAnnotationPresent(ExceptDBField.class))
{
return null;
}
field.setAccessible(true);
String name = null;
if (field.isAnnotationPresent(PortInObj.Nece.class))
{
name = PortUtil.tied(field.getAnnotation(PortInObj.Nece.class), field, true);
} else if (field.isAnnotationPresent(PortInObj.UnNece.class))
{
name = PortUtil.tied(field.getAnnotation(PortInObj.UnNece.class), field, true);
} else if (field.isAnnotationPresent(DBField.class))
{
name = field.getName();
DBField dbField = field.getAnnotation(DBField.class);
if (!dbField.value().equals(""))
{
name = dbField.value();
}
}
return name;
}
示例5: generate
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public void generate(ObjectNode fieldFormDefinition, Field field) {
TextArea annotation = field.getAnnotation(TextArea.class);
fieldFormDefinition.put("key", field.getName());
fieldFormDefinition.put("type", "textarea");
String fieldAddonLeft = annotation.fieldAddonLeft();
if (!fieldAddonLeft.isEmpty()) {
fieldFormDefinition.put("fieldAddonLeft", fieldAddonLeft);
}
String fieldAddonRight = annotation.fieldAddonRight();
if (!fieldAddonRight.isEmpty()) {
fieldFormDefinition.put("fieldAddonRight", fieldAddonRight);
}
String description = annotation.description();
if (!description.isEmpty()) {
fieldFormDefinition.put("description", description);
}
String placeHolder = annotation.placeHolder();
if (!placeHolder.isEmpty()) {
fieldFormDefinition.put("placeholder", placeHolder);
}
boolean noTitle = annotation.noTitle();
if (noTitle) {
fieldFormDefinition.put("notitle", noTitle);
}
String validationMessage = annotation.validationMessage();
if (!validationMessage.isEmpty()) {
fieldFormDefinition.put("validationMessage", validationMessage);
}
boolean readOnly = annotation.readOnly();
if (readOnly) {
fieldFormDefinition.put("readonly", readOnly);
}
}
示例6: getColumnByProperty
import java.lang.reflect.Field; //導入方法依賴的package包/類
static Column getColumnByProperty(final String propertyName, final Field[] properties) {
Field matchProperty = getPropertyField(propertyName, properties);
if (matchProperty.isAnnotationPresent(Column.class)) {
return matchProperty.getAnnotation(Column.class);
}
return null;
}
示例7: IdProperty
import java.lang.reflect.Field; //導入方法依賴的package包/類
public IdProperty(EntityMetadata metadata , Field field){
super(metadata , field);
Id id = field.getAnnotation(Id.class);
if(id.useGeneratedKeys()){
keyGenerator = new Jdbc3KeyGenerator();
}
}
示例8: extractKey
import java.lang.reflect.Field; //導入方法依賴的package包/類
private CsdlPropertyRef extractKey(Field f) throws CsdlExtractException {
ODataProperty prop = f.getAnnotation(ODataProperty.class);
if (prop == null) {
throw new CsdlExtractException("Field annotated as ODataKey must be annotated as ODataProperty as well");
}
return new CsdlPropertyRef().setName(prop.name());
}
示例9: processFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Processes all fields of a class
*
* @param fields
* array of fields
* @param definition
* current definition
* @param rootDefinition
* definition where the recursion started to prevent an endless
* loop
* @return list of {@link Property} objects
* @throws ParserException
* Error while the parsing process
*/
public List<Property> processFields(Field[] fields, Definition definition, Definition rootDefinition)
throws ParserException {
DataTypeFactory typeHandler = new DataTypeFactory();
List<Property> properties = new ArrayList<>();
for (Field field : fields) {
if (field.getAnnotation(JsonIgnore.class) == null && field.getAnnotation(JsonBackReference.class) == null) {
Property property = new Property();
Class<?> typeClass = field.getType();
Annotation[] annotations = field.getAnnotations();
Type genericType = field.getGenericType();
processGenerics(genericType, property, definition, rootDefinition);
DataType typeObject = typeHandler.getDataType(typeClass.getName());
String type = typeObject.getType();
String name = field.getName();
property.setName(name);
if (type.length() > 14 && (type.substring(14).equals(definition.getClassName())
|| type.substring(14).equals(rootDefinition.getClassName()))) {
property.setReference(type);
} else if (type.startsWith("#")) {
createDefinitionBySchemaAndPackageIfNotExists(type, typeClass.getTypeName(), rootDefinition);
property.setReference(type);
} else {
property.setType(type);
property.setFormat(typeObject.getFormat());
}
properties.add(property);
processAnnotations(annotations, definition, name);
}
}
return properties;
}
示例10: testCreateForPersistenceContextField2
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Test
public void testCreateForPersistenceContextField2() throws Exception {
class Bean {
@PersistenceContext(name = "other")
private Object foo;
}
Field field = Bean.class.getDeclaredField("foo");
PersistenceContext ctx = field.getAnnotation(PersistenceContext.class);
Reference r = Reference.createFor(ctx, field);
assertEquals(EntityManager.class, r.getInterfaceOrClass());
assertEquals("other", r.getName());
}
示例11: addPositionalParameters
import java.lang.reflect.Field; //導入方法依賴的package包/類
/** Calls {@link #addPositionalParameter(Field, CommandLine.Help.IParamLabelRenderer)} for all non-hidden ConsoleArgs in the list.
* @param fields fields annotated with {@link Parameters} to add usage descriptions for
* @param paramLabelRenderer knows how to render option parameters */
public void addPositionalParameters(List<Field> fields, IParamLabelRenderer paramLabelRenderer) {
for (Field field : fields) {
Parameters parameters = field.getAnnotation(Parameters.class);
if (!parameters.hidden()) {
addPositionalParameter(field, paramLabelRenderer);
}
}
}
示例12: decompose
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public String decompose(String idValue, Field idField, Class<?> clazz) {
final Id id = idField.getAnnotation(Id.class);
if (id == null) {
throw new IllegalArgumentException("Missing Id-annotation on Id-annotated field? Weird...");
} else {
return idValue.substring(id.prefix().length(), idValue.length() - id.suffix().length());
}
}
示例13: getAnnotationRuleFromField
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Annotation getAnnotationRuleFromField(final Object obj, final Field field,
final Class<? extends Annotation> annotation) {
Annotation anno = null;
try {
final Annotation annoField = field.getAnnotation(annotation);
final Annotation annoMethod = obj.getClass()
.getDeclaredMethod(B4zV4lidatorUtil.getMethod(obj, field).getName()).getAnnotation(annotation);
anno = Objects.nonNull(annoField) ? annoField : annoMethod;
} catch (SecurityException | NoSuchMethodException e) {
e.printStackTrace();
}
return anno;
}
示例14: getAllModifiableVariableHoldersRecursively
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Returns a list of all the modifiable variable holders in the object,
* including this instance.
*
* @param object
* Analyzed object
* @return A list of objects with their modifiable variable fields (only
* objects with modifiable variables are selected)
*/
public static List<ModifiableVariableListHolder> getAllModifiableVariableHoldersRecursively(Object object) {
List<ModifiableVariableListHolder> holders = new LinkedList<>();
List<Field> modFields = getAllModifiableVariableFields(object);
if (!modFields.isEmpty()) {
holders.add(new ModifiableVariableListHolder(object, modFields));
}
List<Field> allFields = ReflectionHelper.getFieldsUpTo(object.getClass(), null, null);
for (Field f : allFields) {
try {
HoldsModifiableVariable holdsVariable = f.getAnnotation(HoldsModifiableVariable.class);
f.setAccessible(true);
Object possibleHolder = f.get(object);
if (possibleHolder != null && holdsVariable != null) {
if (possibleHolder instanceof List) {
holders.addAll(getAllModifiableVariableHoldersFromList((List) possibleHolder));
} else if (possibleHolder.getClass().isArray()) {
holders.addAll(getAllModifiableVariableHoldersFromArray((Object[]) possibleHolder));
} else {
holders.addAll(getAllModifiableVariableHoldersRecursively(possibleHolder));
}
}
} catch (IllegalAccessException | IllegalArgumentException ex) {
LOGGER.debug("Accessing field {} of type {} not possible: {}", f.getName(), f.getType(), ex.toString());
}
}
return holders;
}
示例15: groupByAnnotation
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Map<Class<? extends Annotation>, Collection<Field>> groupByAnnotation(
final Collection<Field> fields,
final Class<? extends Annotation>... annotations
) {
final Map<Class<? extends Annotation>, Collection<Field>> ret = new HashMap<>();
for (final Class<? extends Annotation> annotation : annotations) {
ret.put(annotation, new HashSet<>());
for (final Field field : fields) {
if (field.getAnnotation(annotation) != null) {
ret.get(annotation).add(field);
}
}
}
return ret;
}