当前位置: 首页>>代码示例>>Java>>正文


Java Field.getAnnotation方法代码示例

本文整理汇总了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;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:22,代码来源:ProtobufSerializerUtils.java

示例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);
		}
	}
}
 
开发者ID:yaoakeji,项目名称:hibatis,代码行数:27,代码来源:CollectionProperty.java

示例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();
    }
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:10,代码来源:DefaultIdGenerator.java

示例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;
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:33,代码来源:DataUtil.java

示例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);
	}
}
 
开发者ID:JsonSchema-JavaUI,项目名称:sf-java-ui,代码行数:38,代码来源:TextAreaGenerator.java

示例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;
}
 
开发者ID:wz2cool,项目名称:mybatis-dynamic-query,代码行数:9,代码来源:EntityHelper.java

示例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();
	}
}
 
开发者ID:yaoakeji,项目名称:hibatis,代码行数:8,代码来源:IdProperty.java

示例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());
}
 
开发者ID:mat3e,项目名称:olingo-jpa,代码行数:8,代码来源:JpaEntityCsdlProvider.java

示例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;
}
 
开发者ID:SPIRIT-21,项目名称:javadoc2swagger,代码行数:46,代码来源:DefinitionParser.java

示例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());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:ReferenceTest.java

示例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);
        }
    }
}
 
开发者ID:alisianoi,项目名称:lyra2-java,代码行数:12,代码来源:CommandLine.java

示例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());
    }
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:10,代码来源:DefaultIdGenerator.java

示例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;
}
 
开发者ID:sergioluigi,项目名称:B4zV4lidator,代码行数:15,代码来源:B4zV4lidatorUtil.java

示例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;
}
 
开发者ID:RUB-NDS,项目名称:ModifiableVariable,代码行数:37,代码来源:ModifiableVariableAnalyzer.java

示例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;
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:16,代码来源:AnnotationUtils.java


注:本文中的java.lang.reflect.Field.getAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。