當前位置: 首頁>>代碼示例>>Java>>正文


Java Field.getDeclaredAnnotation方法代碼示例

本文整理匯總了Java中java.lang.reflect.Field.getDeclaredAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.getDeclaredAnnotation方法的具體用法?Java Field.getDeclaredAnnotation怎麽用?Java Field.getDeclaredAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Field的用法示例。


在下文中一共展示了Field.getDeclaredAnnotation方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ColumnStructure

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Constructor for field based table columns
 */
public ColumnStructure(TableStructure table, Field dataField, DataColumn anno) {
    if (anno == null) throw new IllegalArgumentException();
    this.table = table;
    String name = anno.value();
    if ("".equals(name)) name = dataField.getName();
    this.name = name;
    this.isPrimary = dataField.getDeclaredAnnotation(PrimaryKey.class) != null;
    dataField.setAccessible(true);
    field = dataField;
    fieldType = field.getType();
    setter = null;
    getter = null;
    fieldParser = getParserMethod(dataField.getType());
    if (fieldParser == null) {
        accessMethod = ColumnAccessMethod.FIELD;
        columnType = ColumnType.getType(ColumnAccessMethod.FIELD, field.getType());
    } else {
        accessMethod = ColumnAccessMethod.FIELD_PARSE;
        columnType = ColumnType.getType(ColumnAccessMethod.FIELD_PARSE, field.getType());
    }
}
 
開發者ID:NyaaCat,項目名稱:NyaaCore,代碼行數:25,代碼來源:ColumnStructure.java

示例2: getAnnotatedFields

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static List<AnnotatedField> getAnnotatedFields(Class<?> containerClass)
        throws Asn1DecodingException {
    Field[] declaredFields = containerClass.getDeclaredFields();
    List<AnnotatedField> result = new ArrayList<>(declaredFields.length);
    for (Field field : declaredFields) {
        Asn1Field annotation = field.getDeclaredAnnotation(Asn1Field.class);
        if (annotation == null) {
            continue;
        }
        if (Modifier.isStatic(field.getModifiers())) {
            throw new Asn1DecodingException(
                    Asn1Field.class.getName() + " used on a static field: "
                            + containerClass.getName() + "." + field.getName());
        }

        AnnotatedField annotatedField;
        try {
            annotatedField = new AnnotatedField(field, annotation);
        } catch (Asn1DecodingException e) {
            throw new Asn1DecodingException(
                    "Invalid ASN.1 annotation on "
                            + containerClass.getName() + "." + field.getName(),
                    e);
        }
        result.add(annotatedField);
    }
    return result;
}
 
開發者ID:F8LEFT,項目名稱:FApkSigner,代碼行數:29,代碼來源:Asn1BerParser.java

示例3: getAnnotatedFields

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static List<AnnotatedField> getAnnotatedFields(Object container)
        throws Asn1EncodingException {
    Class<?> containerClass = container.getClass();
    Field[] declaredFields = containerClass.getDeclaredFields();
    List<AnnotatedField> result = new ArrayList<>(declaredFields.length);
    for (Field field : declaredFields) {
        Asn1Field annotation = field.getDeclaredAnnotation(Asn1Field.class);
        if (annotation == null) {
            continue;
        }
        if (Modifier.isStatic(field.getModifiers())) {
            throw new Asn1EncodingException(
                    Asn1Field.class.getName() + " used on a static field: "
                            + containerClass.getName() + "." + field.getName());
        }

        AnnotatedField annotatedField;
        try {
            annotatedField = new AnnotatedField(container, field, annotation);
        } catch (Asn1EncodingException e) {
            throw new Asn1EncodingException(
                    "Invalid ASN.1 annotation on "
                            + containerClass.getName() + "." + field.getName(),
                    e);
        }
        result.add(annotatedField);
    }
    return result;
}
 
開發者ID:F8LEFT,項目名稱:FApkSigner,代碼行數:30,代碼來源:Asn1DerEncoder.java

示例4: FieldSearchFieldMetadata

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Create a new instance.
 *
 * @param entityType        Entity class.
 * @param field             For this field.
 * @param indexTypeRegistry Determine the index type with this lookup.
 */
public FieldSearchFieldMetadata(Class<?> entityType, Field field, IndexTypeRegistry indexTypeRegistry) {
    this.entityType = entityType;
    this.field = field;
    this.indexName = NAME_CALCULATOR.apply(field);
    this.encodedName = NAME_ENCODER.apply(indexName);

    SearchIndex annotation = field.getDeclaredAnnotation(SearchIndex.class);
    if (annotation == null || annotation.type() == IndexType.AUTO) {
        this.indexType = indexTypeRegistry.apply(field.getGenericType());
    } else {
        this.indexType = annotation.type();
    }
}
 
開發者ID:n15g,項目名稱:spring-boot-gae,代碼行數:21,代碼來源:FieldSearchFieldMetadata.java

示例5: registerFoods

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Load
public void registerFoods() {
    for (Field field : FCRFoods.class.getFields()) {
        field.setAccessible(true);
        try {
            RegFood anno = field.getDeclaredAnnotation(RegFood.class);
            if (anno == null) {
                Object food = field.get(null);
                if (food instanceof ItemPorridge)
                    registerPorridge((ItemPorridge) food);
                else if (food instanceof ItemSoup)
                    registerSoup((ItemSoup) food);
                else if (food instanceof ItemNoodles)
                    registerNoodles((ItemNoodles) food);
                else if (food instanceof ItemLiqueur)
                    registerLiqueur((ItemLiqueur) food);
                continue;
            }

            ItemPFood item = (ItemPFood) field.get(null);
            if (ArrayUtils.isNotEmpty(anno.modifier()))
                item.setProperties(anno.modifier());
            if (anno.amount() == Integer.MIN_VALUE)
                item.calcHealAmount();
            else
                item.setHealAmount(anno.amount());
            ForgeRegistries.ITEMS.register(item.setRegistryName(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(anno.name())).setUnlocalizedName(NameBuilder.buildUnlocalizedName(anno.name())));
            Arrays.asList(anno.oreDict()).forEach(s -> OreDictionary.registerOre(s, item));
            OreDictionary.registerOre("listAllfoods", item);
        } catch (IllegalAccessException | NullPointerException e) {
            FoodCraftReloaded.getLogger().warn("Un-able to register food " + field.toGenericString(), e);
        }
    }
}
 
開發者ID:LasmGratel,項目名稱:FoodCraft-Reloaded,代碼行數:35,代碼來源:PropertiedFoodLoader.java

示例6: getObject

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static <T1, T2> T2 getObject(T1 object, Class<T2> adaptedClass) {

    try {
      Map<String, Field> objectFieldsMap = getAllFields(object.getClass());

      T2 adaptedObject = (T2) ConstructorUtils.invokeConstructor(adaptedClass, null);
      List<String> target = getFields(adaptedClass);
      for (String field : target) {

        // get The field of the adapted object
        Field targetField = adaptedClass.getDeclaredField(field);
        targetField.setAccessible(true);

        if (targetField.isAnnotationPresent(NestedField.class)) {

          NestedField annotation = targetField.getDeclaredAnnotation(NestedField.class);
          String[] hierarchy = StringUtils.split(annotation.src(), ".");
          Field nestedField = objectFieldsMap.get(hierarchy[0]);
          nestedField.setAccessible(true);
          Object fieldValue = nestedField.get(object);

          for (int i = 1; i < hierarchy.length; i++) {
            nestedField = nestedField.getType().getDeclaredField(hierarchy[i]);
            nestedField.setAccessible(true);
            fieldValue = nestedField.get(fieldValue);
          }

          // Set the last level value from hierarchy
          targetField.set(adaptedObject, fieldValue);

        } else {

          // Non nested field process as normal
          Field sourceField;
          if (targetField.isAnnotationPresent(StringDate.class)) {

            // Process date fields
            sourceField = objectFieldsMap.get(field);
            sourceField.setAccessible(true);

            if (sourceField.get(object) != null) {

              // Value is not null
              DateTime time = new DateTime(sourceField.get(object), DateTimeZone.UTC);
              targetField.set(adaptedObject, time.toString());
            } else {

              targetField.set(adaptedObject, "");
            }


          } else if (targetField.isAnnotationPresent(IgnoreAdaptation.class)) {
            // Leave field as it is. no processing.
          } else {

            sourceField = objectFieldsMap.get(field);
            sourceField.setAccessible(true);

            targetField.set(adaptedObject, sourceField.get(object));
          }
        }
      }

      return adaptedObject;

    } catch (Exception e) {
      logger.error(ExceptionUtils.getRootCauseMessage(e));
      return null;
    }


  }
 
開發者ID:pinterest,項目名稱:soundwave,代碼行數:73,代碼來源:ObjectAdapter.java

示例7: printConfig

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void printConfig(Class configClass) throws IllegalAccessException, InstantiationException {
    Field[] fields = configClass.getDeclaredFields();
    System.out.println();
    System.out.println("### " + configClass.getSimpleName());
    System.out.println();
    Object defaultConfig = configClass.newInstance();

    System.out.println("|Name|Default|Description|");
    System.out.println("|---|---|---|");
    try {
        for (Field field : fields) {
            field.setAccessible(true);
            StringBuilder sb = new StringBuilder();
            sb.append("|");
            Parameter param = field.getDeclaredAnnotation(Parameter.class);

            if (param != null) {
                String names = Stream.of(param.names())
                        .collect(Collectors.joining(", "));
                // name
                sb.append(names).append("|");

                // default
                sb.append(param.required() ? "**required**" : field.get(defaultConfig) + " ").append("|");

                // description
                sb.append(param.description()).append("|");

                System.out.println(sb.toString());
            }

            ParametersDelegate delegate = field.getDeclaredAnnotation(ParametersDelegate.class);

            if (delegate != null) {
                printConfig(field.getType());
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Merck,項目名稱:rdf2x,代碼行數:42,代碼來源:ReadmeUtils.java


注:本文中的java.lang.reflect.Field.getDeclaredAnnotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。