public FieldPropertyHandler(Field field) { super(field.getType(), true, true); this.field = field; }
@Override public Class<?> getObjectType() { return (this.fieldObject != null ? this.fieldObject.getType() : null); }
/** Returns a Class object that identifies the declared type for the field. */ public Class getType () { return field.getType(); }
/** Returns a Class object that identifies the declared type for the field. */ public Class getType () { return field.getType(); }
@Override public Class<?> getPropertyType() { if (this.member instanceof Method) { return ((Method) this.member).getReturnType(); } else { return ((Field) this.member).getType(); } }
protected final Class<?> getResourceType() { if (this.isField) { return ((Field) this.member).getType(); } else if (this.pd != null) { return this.pd.getPropertyType(); } else { return ((Method) this.member).getParameterTypes()[0]; } }
private static void ensureSpringRulesAreNotPresent(Class<?> testClass) { for (Field field : testClass.getFields()) { Assert.state(!SpringClassRule.class.isAssignableFrom(field.getType()), () -> String.format( "Detected SpringClassRule field in test class [%s], " + "but SpringClassRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName())); Assert.state(!SpringMethodRule.class.isAssignableFrom(field.getType()), () -> String.format( "Detected SpringMethodRule field in test class [%s], " + "but SpringMethodRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName())); } }
private void addDefaultValue(JadxCLIArgs args, Field f, StringBuilder opt) { Class<?> fieldType = f.getType(); if (fieldType == int.class) { try { int val = f.getInt(args); opt.append(" (default: ").append(val).append(")"); } catch (Exception e) { // ignore } } }
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); } }
/** * Return the type declared by the underlying field or method/constructor parameter, * indicating the injection type. */ public Class<?> getDeclaredType() { return (this.field != null ? this.field.getType() : obtainMethodParameter().getParameterType()); }
@Override protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable { Class<?> referenceClass = field.getType(); referenceBean = buildReferenceBean(reference, referenceClass); ReflectionUtils.makeAccessible(field); field.set(bean, referenceBean.getObject()); }
@Override protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable { Class<?> referenceClass = field.getType(); referenceBean = buildReferenceBean(reference, referenceClass); ReflectionUtils.makeAccessible(field); field.set(bean, referenceBean.getObject()); }
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 void deserialize(AbstractHessianInput in, Object obj) throws IOException { Object value = null; try { value = in.readObject(_field.getType()); _field.set(obj, value); } catch (Exception e) { logDeserializeError(_field, obj, value, e); } } }
@Override void deserialize(AbstractHessianInput in, Object obj) throws IOException { Object value = null; try { Type[] types = ((ParameterizedType)_field.getGenericType()).getActualTypeArguments(); value = in.readObject(_field.getType(), isPrimitive(types[0]) ? (Class<?>)types[0] : null ); _field.set(obj, value); } catch (Exception e) { logDeserializeError(_field, obj, value, e); } } }
@Override void deserialize(AbstractHessianInput in, Object obj) throws IOException { Object value = null; try { Type[] types = ((ParameterizedType)_field.getGenericType()).getActualTypeArguments(); value = in.readObject(_field.getType(), isPrimitive(types[0]) ? (Class<?>)types[0] : null, isPrimitive(types[1]) ? (Class<?>)types[1] : null ); _field.set(obj, value); } catch (Exception e) { logDeserializeError(_field, obj, value, e); } } }
public static MockitoException fieldInitialisationThrewException(Field field, Throwable details) { return new InjectMocksException(join( "Cannot instantiate @InjectMocks field named '" + field.getName() + "' of type '" + field.getType() + "'.", "You haven't provided the instance at field declaration so I tried to construct the instance.", "However the constructor or the initialization block threw an exception : " + details.getMessage(), ""), details); }
/** * Create a new type descriptor from a {@link Field}. * <p>Use this constructor when a source or target conversion point is a field. * @param field the field */ public TypeDescriptor(Field field) { this.resolvableType = ResolvableType.forField(field); this.type = this.resolvableType.resolve(field.getType()); this.annotatedElement = new AnnotatedElementAdapter(field.getAnnotations()); }
@Override public boolean apply(Field input) { int modifiers = input.getModifiers(); return isPublic(modifiers) && isStatic(modifiers) && isFinal(modifiers) && MediaType.class.equals(input.getType()); } });
static ImmutableSet<Field> relevantFields(Class<?> cls) { ImmutableSet.Builder<Field> builder = ImmutableSet.builder(); for (Field field : cls.getDeclaredFields()) { /* * Coverage mode generates synthetic fields. If we ever add private * fields, they will cause similar problems, and we may want to switch * this check to isAccessible(). */ if (!field.isSynthetic() && field.getType() == String.class) { builder.add(field); } } return builder.build(); }