當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。