/** Returns the name of the field. */ public String getName () { return field.getName(); }
public FieldTypeProvider(Field field) { this.fieldName = field.getName(); this.declaringClass = field.getDeclaringClass(); this.field = field; }
@Override public String toString() { return (this.field != null ? "field '" + this.field.getName() + "'" : String.valueOf(this.methodParameter)); }
/** * Create a new descriptor for a field. * @param field the field to wrap * @param required whether the dependency is required * @param eager whether this dependency is 'eager' in the sense of * eagerly resolving potential target beans for type matching */ public DependencyDescriptor(Field field, boolean required, boolean eager) { super(field); this.declaringClass = field.getDeclaringClass(); this.fieldName = field.getName(); this.required = required; this.eager = eager; }
/** * We need to detect this as "code-style" AspectJ aspects should not be * interpreted by Spring AOP. */ private boolean compiledByAjc(Class<?> clazz) { // The AJTypeSystem goes to great lengths to provide a uniform appearance between code-style and // annotation-style aspects. Therefore there is no 'clean' way to tell them apart. Here we rely on // an implementation detail of the AspectJ compiler. for (Field field : clazz.getDeclaredFields()) { if (field.getName().startsWith(AJC_MAGIC)) { return true; } } return false; }
private void readAndroidRStyleClass() { try { Class<?> rStyleCls = Class.forName(ANDROID_R_STYLE_CLS); for (Field f : rStyleCls.getFields()) { styleMap.put(f.getInt(f.getType()), f.getName()); } } catch (Exception th) { LOG.error("Android R class loading failed", th); } }
public static Map<String, Field> getBeanPropertyFields(Class cl) { Map<String, Field> properties = new HashMap<String, Field>(); for (; cl != null; cl = cl.getSuperclass()) { Field[] fields = cl.getDeclaredFields(); for (Field field : fields) { if (Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) { continue; } field.setAccessible(true); properties.put(field.getName(), field); } } return properties; }
public static Map<String, Field> getBeanPropertyFields(Class cl) { Map<String, Field> properties = new HashMap<String, Field>(); for (; cl != null; cl = cl.getSuperclass()) { Field[] fields = cl.getDeclaredFields(); for (Field field : fields) { if (Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) { continue; } field.setAccessible(true); properties.put(field.getName(), field); } } return properties; }
private static FieldInfo getField(List<FieldInfo> fieldList, String propertyName) { for (FieldInfo item : fieldList) { if (item.name.equals(propertyName)) { return item; } Field field = item.field; if (field != null && item.getAnnotation() != null && field.getName().equals(propertyName)) { return item; } } return null; }
private static String[] calculateMatches(final String name, Class<?> clazz, final int maxDistance) { final List<String> candidates = new ArrayList<>(); ReflectionUtils.doWithFields(clazz, field -> { String possibleAlternative = field.getName(); if (calculateStringDistance(name, possibleAlternative) <= maxDistance) { candidates.add(possibleAlternative); } }); Collections.sort(candidates); return StringUtils.toStringArray(candidates); }
/** * Determine the name of the wrapped parameter/field. * @return the declared name (never {@code null}) */ @Nullable public String getDependencyName() { return (this.field != null ? this.field.getName() : obtainMethodParameter().getParameterName()); }
static void logDeserializeError(Field field, Object obj, Object value, Throwable e) throws IOException { String fieldName = (field.getDeclaringClass().getName() + "." + field.getName()); if (e instanceof HessianFieldException) throw (HessianFieldException) e; else if (e instanceof IOException) throw new HessianFieldException(fieldName + ": " + e.getMessage(), e); if (value != null) throw new HessianFieldException(fieldName + ": " + value.getClass().getName() + " (" + value + ")" + " cannot be assigned to '" + field.getType().getName() + "'", e); else throw new HessianFieldException(fieldName + ": " + field.getType().getName() + " cannot be assigned from null", e); }
@Override public void setValue(@Nullable Object value) throws Exception { try { ReflectionUtils.makeAccessible(this.field); this.field.set(getWrappedInstance(), value); } catch (IllegalAccessException ex) { throw new InvalidPropertyException(getWrappedClass(), this.field.getName(), "Field is not accessible", ex); } } }
@Override @Nullable public Object getValue() throws Exception { try { ReflectionUtils.makeAccessible(this.field); return this.field.get(getWrappedInstance()); } catch (IllegalAccessException ex) { throw new InvalidPropertyException(getWrappedClass(), this.field.getName(), "Field is not accessible", ex); } }
private void writeDefinition20(AbstractHessianOutput out) throws IOException { out.writeClassFieldLength(_fields.length); for (int i = 0; i < _fields.length; i++) { Field field = _fields[i]; out.writeString(field.getName()); } }
private void writeObject10(Object obj, AbstractHessianOutput out) throws IOException { for (int i = 0; i < _fields.length; i++) { Field field = _fields[i]; out.writeString(field.getName()); _fieldSerializers[i].serialize(out, obj, field); } out.writeMapEnd(); }
@GwtIncompatible // reflection public void testConstants_charset() throws Exception { for (Field field : getConstantFields()) { Optional<Charset> charset = ((MediaType) field.get(null)).charset(); if (field.getName().endsWith("_UTF_8")) { assertThat(charset).hasValue(UTF_8); } else { assertThat(charset).isAbsent(); } } }
static void assertConstantNameMatchesString( Class<?> clazz, ImmutableBiMap<String, String> specialCases, ImmutableSet<String> uppercaseAcronyms) throws IllegalAccessException { for (Field field : relevantFields(clazz)) { assertEquals( upperToHttpHeaderName(field.getName(), specialCases, uppercaseAcronyms), field.get(null)); } }
@GwtIncompatible // reflection public void testGetField() { Field foo = Enums.getField(AnEnum.FOO); assertEquals("FOO", foo.getName()); assertTrue(foo.isAnnotationPresent(ExampleAnnotation.class)); Field bar = Enums.getField(AnEnum.BAR); assertEquals("BAR", bar.getName()); assertFalse(bar.isAnnotationPresent(ExampleAnnotation.class)); }