本文整理匯總了Java中java.lang.reflect.Field.getAnnotationsByType方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.getAnnotationsByType方法的具體用法?Java Field.getAnnotationsByType怎麽用?Java Field.getAnnotationsByType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Field
的用法示例。
在下文中一共展示了Field.getAnnotationsByType方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: printRequiredFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
protected void printRequiredFields() {
print("## Required fields");
boolean hasRequiredFields = false;
for (final Field field : getClassForExample().getDeclaredFields()) {
final Required[] annotations = field.getAnnotationsByType(Required.class);
if (null != annotations && annotations.length > 0) {
if (!hasRequiredFields) {
hasRequiredFields = true;
print("The following fields are required: ");
}
final String name = field.getName();
print("- " + name);
}
}
if (!hasRequiredFields) {
print("No required fields");
}
print("\n");
}
示例2: buildFastLookupTable
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void buildFastLookupTable()
{
final Field[] fields = SystemMessageId.class.getDeclaredFields();
for (Field field : fields)
{
final int mod = field.getModifiers();
if (Modifier.isStatic(mod) && Modifier.isPublic(mod) && field.getType().equals(SystemMessageId.class) && field.isAnnotationPresent(ClientString.class))
{
try
{
final ClientString annotation = field.getAnnotationsByType(ClientString.class)[0];
final SystemMessageId smId = new SystemMessageId(annotation.id());
smId.setName(annotation.message());
smId.setParamCount(parseMessageParameters(field.getName()));
field.set(null, smId);
VALUES.put(smId.getId(), smId);
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "SystemMessageId: Failed field access for '" + field.getName() + "'", e);
}
}
}
}
示例3: buildFastLookupTable
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void buildFastLookupTable()
{
final Field[] fields = NpcStringId.class.getDeclaredFields();
for (Field field : fields)
{
final int mod = field.getModifiers();
if (Modifier.isStatic(mod) && Modifier.isPublic(mod) && field.getType().equals(NpcStringId.class) && field.isAnnotationPresent(ClientString.class))
{
try
{
final ClientString annotation = field.getAnnotationsByType(ClientString.class)[0];
final NpcStringId nsId = new NpcStringId(annotation.id());
nsId.setName(annotation.message());
nsId.setParamCount(parseMessageParameters(field.getName()));
field.set(null, nsId);
VALUES.put(nsId.getId(), nsId);
}
catch (Exception e)
{
_log.log(Level.WARNING, "NpcStringId: Failed field access for '" + field.getName() + "'", e);
}
}
}
}
示例4: bepaalIndicatieActueelEnGeldigSetter
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static IndicatieActueelEnGeldigSetter bepaalIndicatieActueelEnGeldigSetter(final Afleidbaar entiteit, final Field historieSetField)
throws ReflectiveOperationException {
final IndicatieActueelEnGeldig[] annotationsByType = historieSetField.getAnnotationsByType(IndicatieActueelEnGeldig.class);
if (annotationsByType.length > 0) {
final Field indicatieAgField = entiteit.getClass().getDeclaredField(annotationsByType[0].naam());
indicatieAgField.setAccessible(true);
return indicatieActueelEnGeldig -> {
try {
indicatieAgField.set(entiteit, indicatieActueelEnGeldig);
} catch (final ReflectiveOperationException e) {
throw new IllegalStateException("Er is iets mis gegaan tijdens afleiden A-laag (bepalen veld indicatie actueel en geldig)", e);
}
};
}
return null;
}
示例5: buildMappings
import java.lang.reflect.Field; //導入方法依賴的package包/類
private void buildMappings() {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
Attribute[] attributes = field.getAnnotationsByType(Attribute.class);
PartitionKey[] partitionKey = field.getAnnotationsByType(PartitionKey.class);
SortKey[] sortKey = field.getAnnotationsByType(SortKey.class);
if (attributes.length > 0) {
fieldNames.add(field.getName());
}
if (partitionKey.length > 0) {
fieldNames.add(field.getName());
padding.put(field.getName(), partitionKey[0].padding());
}
if (sortKey.length > 0) {
fieldNames.add(field.getName());
}
}
}
示例6: injectScopeIntoField
import java.lang.reflect.Field; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
static Object injectScopeIntoField(Field scopeField, Object viewModel, ContextImpl context)
throws IllegalAccessException {
Class<? extends Scope> scopeType = (Class<? extends Scope>) scopeField.getType();
// FIXME
final InjectScope[] annotations = scopeField.getAnnotationsByType(InjectScope.class);
if (annotations.length != 1) {
throw new RuntimeException("A field to inject a Scope into should have exactly one @InjectScope annotation "
+ "but the viewModel <" + viewModel + "> has a field that violates this rule.");
}
Object newScope = context.getScope(scopeType);
if (newScope == null) {
// TODO Modify Stacktrace to get the Injectionpoint of the Scope
throw new IllegalStateException(
"A scope was requested but no @ScopeProvider found in the hirarchy. Declare it like this: @ScopeProvider("
+ scopeType.getName() + ")");
}
if (!newScope.getClass().equals(scopeType)) {
throw new IllegalStateException("something went wrong...");
}
scopeField.set(viewModel, newScope);
return newScope;
}
示例7: getPartitionKey
import java.lang.reflect.Field; //導入方法依賴的package包/類
private Primary getPartitionKey(Entry entry) {
Field[] fields = entry.getClass().getDeclaredFields();
for (Field field : fields) {
try {
PartitionKey[] partitionKey = field.getAnnotationsByType(PartitionKey.class);
if (partitionKey.length > 0) {
return (Primary) field.get(entry);
}
} catch (IllegalAccessException e) {
throw new FieldAccessException(field.getName(), entry.getClass().getName(), e);
}
}
throw new NoFieldMatchingAnnotationException(PartitionKey.class.getName(), entry.getClass().getName());
}
示例8: getSortKey
import java.lang.reflect.Field; //導入方法依賴的package包/類
private Secondary getSortKey(Entry entry) {
Field[] fields = entry.getClass().getDeclaredFields();
for (Field field : fields) {
try {
SortKey[] sortKey = field.getAnnotationsByType(SortKey.class);
if (sortKey.length > 0) {
return (Secondary) field.get(entry);
}
} catch (IllegalAccessException e) {
throw new FieldAccessException(field.getName(), entry.getClass().getName(), e);
}
}
throw new NoFieldMatchingAnnotationException(SortKey.class.getName(), entry.getClass().getName());
}
示例9: isVeldNullable
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static boolean isVeldNullable(final Field rootEntiteitField) {
final Column[] columnAnnotation = rootEntiteitField.getAnnotationsByType(Column.class);
final JoinColumn[] joinColumnAnnotation = rootEntiteitField.getAnnotationsByType(JoinColumn.class);
return columnAnnotation.length > 0 && columnAnnotation[0].nullable() || joinColumnAnnotation.length > 0 && joinColumnAnnotation[0].nullable();
}