org.springframework.util.ReflectionUtils.findField()

Here are the examples of the java api org.springframework.util.ReflectionUtils.findField() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

164 Examples 7

19 Source : BeanFactoryAwareFunctionRegistryTests.java
with Apache License 2.0
from spring-cloud

@Test
public void SCF_GH_429ConfigurationTests() throws Exception {
    FunctionCatalog catalog = this.configureCatalog(MyFunction.clreplaced);
    FunctionInvocationWrapper function = catalog.lookup("beanFactoryAwareFunctionRegistryTests.MyFunction");
    replacedertThat(function).isNotNull();
    Field f = ReflectionUtils.findField(FunctionInvocationWrapper.clreplaced, "composed");
    f.setAccessible(true);
    boolean composed = (boolean) f.get(function);
    replacedertThat(composed).isFalse();
}

19 Source : DoubleConfigurationResolverTest.java
with MIT License
from pchudzik

private static Field getField(String fieldName) {
    try {
        return ReflectionUtils.findField(WithConfigurationTestCase.clreplaced, fieldName);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

19 Source : DatabaseInitialization.java
with Apache License 2.0
from open-hand

@Override
public void doExec() {
    /**
     * 多数据源的情况
     */
    if (dataSource instanceof AbstractRoutingDataSource) {
        @SuppressWarnings("unchecked")
        Map<Object, Object> targetDataSources = (Map<Object, Object>) ReflectionUtils.getField(ReflectionUtils.findField(dataSource.getClreplaced(), "targetDataSources"), dataSource);
        if (targetDataSources != null) {
            for (Map.Entry<Object, Object> entry : targetDataSources.entrySet()) {
                if (!(entry.getValue() instanceof DataSource)) {
                    LOGGER.warn("find non-datasource object, ignore it.");
                    continue;
                }
                init((DataSource) entry.getValue());
            }
        }
        Object defaultTargetDataSource = ReflectionUtils.getField(ReflectionUtils.findField(dataSource.getClreplaced(), "defaultTargetDataSource"), dataSource);
        if (!(defaultTargetDataSource instanceof DataSource)) {
            LOGGER.warn("find non-datasource object, ignore it.");
            return;
        }
        init((DataSource) defaultTargetDataSource);
    } else {
        // 单数据源的情况
        init(dataSource);
    }
}

18 Source : QualifierDefinitionTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void forElementWhenElementIsFieldWithNoQualifiersShouldReturnNull() {
    QualifierDefinition definition = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigA.clreplaced, "noQualifier"));
    replacedertThat(definition).isNull();
}

18 Source : QualifierDefinitionTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void hashCodeAndEqualsShouldWorkOnDifferentClreplacedes() {
    QualifierDefinition directQualifier1 = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigA.clreplaced, "directQualifier"));
    QualifierDefinition directQualifier2 = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigB.clreplaced, "directQualifier"));
    QualifierDefinition differentDirectQualifier1 = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigA.clreplaced, "differentDirectQualifier"));
    QualifierDefinition differentDirectQualifier2 = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigB.clreplaced, "differentDirectQualifier"));
    QualifierDefinition customQualifier1 = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigA.clreplaced, "customQualifier"));
    QualifierDefinition customQualifier2 = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigB.clreplaced, "customQualifier"));
    replacedertThat(directQualifier1.hashCode()).isEqualTo(directQualifier2.hashCode());
    replacedertThat(differentDirectQualifier1.hashCode()).isEqualTo(differentDirectQualifier2.hashCode());
    replacedertThat(customQualifier1.hashCode()).isEqualTo(customQualifier2.hashCode());
    replacedertThat(differentDirectQualifier1).isEqualTo(differentDirectQualifier1).isEqualTo(differentDirectQualifier2).isNotEqualTo(directQualifier2);
    replacedertThat(directQualifier1).isEqualTo(directQualifier1).isEqualTo(directQualifier2).isNotEqualTo(differentDirectQualifier1);
    replacedertThat(customQualifier1).isEqualTo(customQualifier1).isEqualTo(customQualifier2).isNotEqualTo(differentDirectQualifier1);
}

18 Source : QualifierDefinitionTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void forElementWhenElementIsFieldWithQualifierShouldReturnDefinition() {
    QualifierDefinition definition = QualifierDefinition.forElement(ReflectionUtils.findField(ConfigA.clreplaced, "directQualifier"));
    replacedertThat(definition).isNotNull();
}

18 Source : DefinitionsParserTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void parseMockBeanOnClreplacedAndField() {
    this.parser.parse(MockBeanOnClreplacedAndField.clreplaced);
    replacedertThat(getDefinitions()).hreplacedize(2);
    MockDefinition clreplacedDefinition = getMockDefinition(0);
    replacedertThat(clreplacedDefinition.getTypeToMock().resolve()).isEqualTo(ExampleService.clreplaced);
    replacedertThat(clreplacedDefinition.getQualifier()).isNull();
    MockDefinition fieldDefinition = getMockDefinition(1);
    replacedertThat(fieldDefinition.getTypeToMock().resolve()).isEqualTo(ExampleServiceCaller.clreplaced);
    QualifierDefinition qualifier = QualifierDefinition.forElement(ReflectionUtils.findField(MockBeanOnClreplacedAndField.clreplaced, "caller"));
    replacedertThat(fieldDefinition.getQualifier()).isNotNull().isEqualTo(qualifier);
}

18 Source : DefinitionsParserTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void parseSpyBeanOnClreplacedAndField() {
    this.parser.parse(SpyBeanOnClreplacedAndField.clreplaced);
    replacedertThat(getDefinitions()).hreplacedize(2);
    SpyDefinition clreplacedDefinition = getSpyDefinition(0);
    replacedertThat(clreplacedDefinition.getQualifier()).isNull();
    replacedertThat(clreplacedDefinition.getTypeToSpy().resolve()).isEqualTo(RealExampleService.clreplaced);
    SpyDefinition fieldDefinition = getSpyDefinition(1);
    QualifierDefinition qualifier = QualifierDefinition.forElement(ReflectionUtils.findField(SpyBeanOnClreplacedAndField.clreplaced, "caller"));
    replacedertThat(fieldDefinition.getQualifier()).isNotNull().isEqualTo(qualifier);
    replacedertThat(fieldDefinition.getTypeToSpy().resolve()).isEqualTo(ExampleServiceCaller.clreplaced);
}

18 Source : BaseDtoService.java
with Apache License 2.0
from Yiuman

@Override
public void setKey(D enreplacedy, K key) throws Exception {
    Field field = ReflectionUtils.findField(dtoClreplaced, ekBaseService.getKeyProperty());
    field.setAccessible(true);
    field.set(enreplacedy, key);
}

18 Source : DefaultApiResultTransformer.java
with Apache License 2.0
from spring-avengers

private Object getStringValueFromField(Object o, String fieldName) {
    Field field = ReflectionUtils.findField(o.getClreplaced(), fieldName);
    if (field == null) {
        return null;
    }
    field.setAccessible(true);
    try {
        return field.get(o);
    } catch (IllegalAccessException e) {
        return null;
    }
}

18 Source : Property.java
with Apache License 2.0
from langtianya

private Field getField() {
    String name = getName();
    if (!StringUtils.hasLength(name)) {
        return null;
    }
    Clreplaced<?> declaringClreplaced = declaringClreplaced();
    Field field = ReflectionUtils.findField(declaringClreplaced, name);
    if (field == null) {
        // Same lenient fallback checking as in CachedIntrospectionResults...
        field = ReflectionUtils.findField(declaringClreplaced, name.substring(0, 1).toLowerCase() + name.substring(1));
        if (field == null) {
            field = ReflectionUtils.findField(declaringClreplaced, name.substring(0, 1).toUpperCase() + name.substring(1));
        }
    }
    return field;
}

18 Source : QuerydslR2dbcRepositoryFactory.java
with Apache License 2.0
from infobip

private RelationalPathBase<?> getRelationalPathBaseFromQueryClreplaced(Clreplaced<?> queryClreplaced) {
    String fieldName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, queryClreplaced.getSimpleName().substring(1));
    Field field = ReflectionUtils.findField(queryClreplaced, fieldName);
    if (field == null) {
        throw new IllegalArgumentException("Did not find a static field of the same type in " + queryClreplaced);
    }
    return (RelationalPathBase<?>) ReflectionUtils.getField(field, null);
}

18 Source : ConfigCenterPropertyPlaceholderConfigurerTest.java
with Apache License 2.0
from baidu

public static void setFieldValue(Object target, String fieldName, Object value) {
    if (target == null || !StringUtils.hasText(fieldName)) {
        return;
    }
    Clreplaced<?> targetClreplaced = target.getClreplaced();
    Field field = ReflectionUtils.findField(targetClreplaced, fieldName);
    if (field == null) {
        return;
    }
    boolean oldAccessible = field.isAccessible();
    field.setAccessible(true);
    ReflectionUtils.setField(field, target, value);
    field.setAccessible(oldAccessible);
}

18 Source : ConfigCenterPropertyPlaceholderConfigurer.java
with Apache License 2.0
from baidu

public static <T> T getFieldValue(Object target, String fieldName, Clreplaced<T> returnType) throws IllegalAccessException {
    if (target == null || !org.springframework.util.StringUtils.hasText(fieldName)) {
        return null;
    }
    Clreplaced<?> targetClreplaced = target.getClreplaced();
    Field field = ReflectionUtils.findField(targetClreplaced, fieldName);
    if (field == null) {
        return null;
    }
    boolean oldAccessible = field.isAccessible();
    boolean change = false;
    if (!oldAccessible) {
        field.setAccessible(true);
        change = true;
    }
    Object o = field.get(target);
    if (change) {
        field.setAccessible(oldAccessible);
    }
    return returnType.cast(o);
}

18 Source : CrudService.java
with Apache License 2.0
from 734839030

public int save(T t) {
    t.setCreateDate(new Date());
    t.setUpdateDate(t.getCreateDate());
    if (StringUtils.isEmpty(t.getCreateBy())) {
        t.setCreateBy(this.getOperatorUserId());
    }
    t.setUpdateBy(t.getCreateBy());
    // 自增主键的insert sql 不能出现插入id
    if (null == t.getId() || StringUtils.isEmpty(t.getId().toString())) {
        Clreplaced<?> clazz = t.getClreplaced();
        Type type = clazz.getGenericSuperclreplaced();
        ParameterizedType parameterizedType = (ParameterizedType) type;
        if (parameterizedType.getActualTypeArguments()[0].equals(String.clreplaced)) {
            // t.setId(IdGen.uuid()); 这个要是编译可以过去就不用这么麻烦去获取主键类型
            Field findField = ReflectionUtils.findField(clazz, "id");
            try {
                findField.setAccessible(true);
                findField.set(t, IdGen.uuid());
            } catch (Exception e) {
                logger.error("set id error:", e);
            }
        }
    }
    int cnt = d.insert(t);
    if (t.isNeedBak()) {
        this.saveBak(t.getId());
    }
    return cnt;
}

17 Source : QualifierDefinitionTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void matchesShouldCallBeanFactory() {
    Field field = ReflectionUtils.findField(ConfigA.clreplaced, "directQualifier");
    QualifierDefinition qualifierDefinition = QualifierDefinition.forElement(field);
    qualifierDefinition.matches(this.beanFactory, "bean");
    verify(this.beanFactory).isAutowireCandidate(eq("bean"), this.descriptorCaptor.capture());
    replacedertThat(this.descriptorCaptor.getValue().getAnnotatedElement()).isEqualTo(field);
}

17 Source : LiquibaseServiceLocatorApplicationListenerTests.java
with Apache License 2.0
from yuanmabiji

private Object getClreplacedResolver() throws IllegalAccessException {
    ServiceLocator instance = ServiceLocator.getInstance();
    Field field = ReflectionUtils.findField(ServiceLocator.clreplaced, "clreplacedResolver");
    field.setAccessible(true);
    return field.get(instance);
}

17 Source : UndertowWebServer.java
with Apache License 2.0
from yuanmabiji

private UndertowWebServer.Port getPortFromListener(Object listener) {
    Field typeField = ReflectionUtils.findField(listener.getClreplaced(), "type");
    ReflectionUtils.makeAccessible(typeField);
    String protocol = ReflectionUtils.getField(typeField, listener).toString();
    Field portField = ReflectionUtils.findField(listener.getClreplaced(), "port");
    ReflectionUtils.makeAccessible(portField);
    int port = (Integer) ReflectionUtils.getField(portField, listener);
    return new UndertowWebServer.Port(port, protocol);
}

17 Source : UndertowServletWebServer.java
with Apache License 2.0
from yuanmabiji

private Port getPortFromListener(Object listener) {
    Field typeField = ReflectionUtils.findField(listener.getClreplaced(), "type");
    ReflectionUtils.makeAccessible(typeField);
    String protocol = ReflectionUtils.getField(typeField, listener).toString();
    Field portField = ReflectionUtils.findField(listener.getClreplaced(), "port");
    ReflectionUtils.makeAccessible(portField);
    int port = (Integer) ReflectionUtils.getField(portField, listener);
    return new Port(port, protocol);
}

17 Source : ElasticsearchIndexServiceUnitTest.java
with Apache License 2.0
from xm-online

@SneakyThrows
private static <T> T createObject(Clreplaced<T> enreplacedyClreplaced) {
    T instance = enreplacedyClreplaced.newInstance();
    Field id = ReflectionUtils.findField(enreplacedyClreplaced, "id");
    id.setAccessible(true);
    ReflectionUtils.setField(ReflectionUtils.findField(enreplacedyClreplaced, "id"), instance, 777L);
    return instance;
}

17 Source : ReflectUtils.java
with GNU Lesser General Public License v3.0
from vision-consensus

public static <T> T getFieldValue(Object target, String fieldName) {
    Field field = ReflectionUtils.findField(target.getClreplaced(), fieldName);
    ReflectionUtils.makeAccessible(field);
    return (T) ReflectionUtils.getField(field, target);
}

17 Source : ReflectionTestUtils.java
with MIT License
from Vip-Augus

/**
 * Get the value of the {@linkplain Field field} with the given {@code name}
 * from the provided {@code targetObject}/{@code targetClreplaced}.
 * <p>If the supplied {@code targetObject} is a <em>proxy</em>, it will
 * be {@linkplain AopTestUtils#getUltimateTargetObject unwrapped} allowing
 * the field to be retrieved from the ultimate target of the proxy.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * field. In addition, an attempt will be made to make non-{@code public}
 * fields <em>accessible</em>, thus allowing one to get {@code protected},
 * {@code private}, and <em>package-private</em> fields.
 * @param targetObject the target object from which to get the field; may be
 * {@code null} if the field is static
 * @param targetClreplaced the target clreplaced from which to get the field; may
 * be {@code null} if the field is an instance field
 * @param name the name of the field to get; never {@code null}
 * @return the field's current value
 * @since 4.2
 * @see #getField(Object, String)
 * @see #getField(Clreplaced, String)
 * @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
 * @see ReflectionUtils#makeAccessible(Field)
 * @see ReflectionUtils#getField(Field, Object)
 * @see AopTestUtils#getUltimateTargetObject(Object)
 */
@Nullable
public static Object getField(@Nullable Object targetObject, @Nullable Clreplaced<?> targetClreplaced, String name) {
    replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
    if (targetObject != null && springAopPresent) {
        targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
    }
    if (targetClreplaced == null) {
        targetClreplaced = targetObject.getClreplaced();
    }
    Field field = ReflectionUtils.findField(targetClreplaced, name);
    if (field == null) {
        throw new IllegalArgumentException(String.format("Could not find field '%s' on %s or target clreplaced [%s]", name, safeToString(targetObject), targetClreplaced));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Getting field '%s' from %s or target clreplaced [%s]", name, safeToString(targetObject), targetClreplaced));
    }
    ReflectionUtils.makeAccessible(field);
    return ReflectionUtils.getField(field, targetObject);
}

17 Source : ReflectionTestUtils.java
with MIT License
from Vip-Augus

/**
 * Set the {@linkplain Field field} with the given {@code name}/{@code type}
 * on the provided {@code targetObject}/{@code targetClreplaced} to the supplied
 * {@code value}.
 * <p>If the supplied {@code targetObject} is a <em>proxy</em>, it will
 * be {@linkplain AopTestUtils#getUltimateTargetObject unwrapped} allowing
 * the field to be set on the ultimate target of the proxy.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * field. In addition, an attempt will be made to make non-{@code public}
 * fields <em>accessible</em>, thus allowing one to set {@code protected},
 * {@code private}, and <em>package-private</em> fields.
 * @param targetObject the target object on which to set the field; may be
 * {@code null} if the field is static
 * @param targetClreplaced the target clreplaced on which to set the field; may
 * be {@code null} if the field is an instance field
 * @param name the name of the field to set; may be {@code null} if
 * {@code type} is specified
 * @param value the value to set
 * @param type the type of the field to set; may be {@code null} if
 * {@code name} is specified
 * @since 4.2
 * @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
 * @see ReflectionUtils#makeAccessible(Field)
 * @see ReflectionUtils#setField(Field, Object, Object)
 * @see AopTestUtils#getUltimateTargetObject(Object)
 */
public static void setField(@Nullable Object targetObject, @Nullable Clreplaced<?> targetClreplaced, @Nullable String name, @Nullable Object value, @Nullable Clreplaced<?> type) {
    replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
    if (targetObject != null && springAopPresent) {
        targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
    }
    if (targetClreplaced == null) {
        targetClreplaced = targetObject.getClreplaced();
    }
    Field field = ReflectionUtils.findField(targetClreplaced, name, type);
    if (field == null) {
        throw new IllegalArgumentException(String.format("Could not find field '%s' of type [%s] on %s or target clreplaced [%s]", name, type, safeToString(targetObject), targetClreplaced));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Setting field '%s' of type [%s] on %s or target clreplaced [%s] to value [%s]", name, type, safeToString(targetObject), targetClreplaced, value));
    }
    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, targetObject, value);
}

17 Source : ProcessLauncherState.java
with Apache License 2.0
from spring-projects-experimental

public String getPid() {
    String pid = null;
    try {
        if (started != null) {
            Field field = ReflectionUtils.findField(started.getClreplaced(), "pid");
            ReflectionUtils.makeAccessible(field);
            pid = "" + ReflectionUtils.getField(field, started);
        }
    } catch (Exception e) {
    }
    return pid;
}

17 Source : ThinJarAppDeployer.java
with Apache License 2.0
from spring-projects-experimental

private Object findContext(ThinJarAppWrapper wrapper) {
    Object app = wrapper.getApp();
    Field field = ReflectionUtils.findField(app.getClreplaced(), "context");
    ReflectionUtils.makeAccessible(field);
    app = ReflectionUtils.getField(field, app);
    return app;
}

17 Source : StateMachineTests.java
with Apache License 2.0
from spring-cloud

private static void setId(Clreplaced<?> clazz, Object instance, String fieldName, Object value) {
    try {
        Field field = ReflectionUtils.findField(clazz, fieldName);
        field.setAccessible(true);
        int modifiers = field.getModifiers();
        Field modifierField = field.getClreplaced().getDeclaredField("modifiers");
        modifiers = modifiers & ~Modifier.FINAL;
        modifierField.setAccessible(true);
        modifierField.setInt(field, modifiers);
        ReflectionUtils.setField(field, instance, value);
    } catch (ReflectiveOperationException e) {
        throw new IllegalArgumentException(e);
    }
}

17 Source : FeignClientBuilderTests.java
with Apache License 2.0
from spring-cloud

private static void replacedertFactoryBeanField(final FeignClientBuilder.Builder builder, final String fieldName, final Object expectedValue) {
    final Field factoryBeanField = ReflectionUtils.findField(FeignClientBuilder.Builder.clreplaced, "feignClientFactoryBean");
    ReflectionUtils.makeAccessible(factoryBeanField);
    final FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) ReflectionUtils.getField(factoryBeanField, builder);
    final Field field = ReflectionUtils.findField(FeignClientFactoryBean.clreplaced, fieldName);
    ReflectionUtils.makeAccessible(field);
    final Object value = ReflectionUtils.getField(field, factoryBean);
    replacedertThat(value).as("Expected value for the field '" + fieldName + "':").isEqualTo(expectedValue);
}

17 Source : DeployerContextUtils.java
with Apache License 2.0
from spring-cloud

private static Object getField(Object target, String name) {
    Field field = ReflectionUtils.findField(target.getClreplaced(), name);
    if (field == null) {
        return null;
    }
    ReflectionUtils.makeAccessible(field);
    return ReflectionUtils.getField(field, target);
}

17 Source : WebapiApplicationRunListener.java
with Apache License 2.0
from spring-avengers

/**
 * 反射获取HandlerMethodReturnValueHandler集合
 */
private List<HandlerMethodReturnValueHandler> findHandlerMethodReturnValueHandlers(RequestMappingHandlerAdapter requestMappingHandlerAdapter) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Field returnValueHandlerCompositeField = ReflectionUtils.findField(RequestMappingHandlerAdapter.clreplaced, "returnValueHandlers");
    returnValueHandlerCompositeField.setAccessible(true);
    Field modifiersField = Field.clreplaced.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(returnValueHandlerCompositeField, returnValueHandlerCompositeField.getModifiers() & ~Modifier.FINAL);
    HandlerMethodReturnValueHandlerComposite returnValueHandlerComposite = (HandlerMethodReturnValueHandlerComposite) ReflectionUtils.getField(returnValueHandlerCompositeField, requestMappingHandlerAdapter);
    Field returnValueHandlersField = ReflectionUtils.findField(HandlerMethodReturnValueHandlerComposite.clreplaced, "returnValueHandlers");
    returnValueHandlersField.setAccessible(true);
    Field returnValueHandlerModifiersField = Field.clreplaced.getDeclaredField("modifiers");
    returnValueHandlerModifiersField.setAccessible(true);
    returnValueHandlerModifiersField.setInt(returnValueHandlersField, returnValueHandlersField.getModifiers() & ~Modifier.FINAL);
    List<HandlerMethodReturnValueHandler> returnValueHandlers = (List<HandlerMethodReturnValueHandler>) ReflectionUtils.getField(returnValueHandlersField, returnValueHandlerComposite);
    return returnValueHandlers;
}

17 Source : WebapiApplicationRunListener.java
with Apache License 2.0
from spring-avengers

@Override
public void started(ConfigurableApplicationContext context) {
    RequestMappingHandlerAdapter requestMappingHandlerAdapter = null;
    try {
        requestMappingHandlerAdapter = context.getBean(RequestMappingHandlerAdapter.clreplaced);
    } catch (Throwable e) {
    // igore
    }
    if (!Objects.isNull(requestMappingHandlerAdapter)) {
        try {
            List<HandlerMethodReturnValueHandler> returnValueHandlers = findHandlerMethodReturnValueHandlers(requestMappingHandlerAdapter);
            RequestResponseBodyMethodProcessor requestResponseBodyMethodProcessor = findRequestResponseBodyMethodProcessor(returnValueHandlers);
            if (!Objects.isNull(requestResponseBodyMethodProcessor)) {
                Field messageConvertersField = ReflectionUtils.findField(RequestMappingHandlerAdapter.clreplaced, "messageConverters");
                messageConvertersField.setAccessible(true);
                List<HttpMessageConverter<?>> messageConverters = (List<HttpMessageConverter<?>>) ReflectionUtils.getField(messageConvertersField, requestMappingHandlerAdapter);
                Field contentNegotiationManagerField = ReflectionUtils.findField(RequestMappingHandlerAdapter.clreplaced, "contentNegotiationManager");
                contentNegotiationManagerField.setAccessible(true);
                ContentNegotiationManager contentNegotiationManager = (ContentNegotiationManager) ReflectionUtils.getField(contentNegotiationManagerField, requestMappingHandlerAdapter);
                Field requestResponseBodyAdviceField = ReflectionUtils.findField(RequestMappingHandlerAdapter.clreplaced, "requestResponseBodyAdvice");
                requestResponseBodyAdviceField.setAccessible(true);
                List<Object> requestResponseBodyAdvice = (List<Object>) ReflectionUtils.getField(requestResponseBodyAdviceField, requestMappingHandlerAdapter);
                int index = returnValueHandlers.indexOf(requestResponseBodyMethodProcessor);
                returnValueHandlers.remove(requestResponseBodyMethodProcessor);
                returnValueHandlers.add(index, new AutoRequestBodyProcessor(messageConverters, contentNegotiationManager, requestResponseBodyAdvice));
            }
        } catch (IllegalAccessException | NoSuchFieldException e) {
            logger.warn(e.getMessage());
        }
    }
}

17 Source : TestLock.java
with Apache License 2.0
from spring-avengers

@Before
public void before() throws IllegalAccessException {
    replacedert.replacedertTrue(javaConcurrentLockFactory instanceof JavaConcurrentLockFactory);
    executor = Executors.newCachedThreadPool();
    for (String key : Arrays.asList("lockCache", "readWriteLockCache")) {
        Field field = ReflectionUtils.findField(JavaConcurrentLockFactory.clreplaced, key);
        field.setAccessible(true);
        ((ConcurrentHashMap) field.get(javaConcurrentLockFactory)).clear();
    }
}

17 Source : ReflectionTestUtils.java
with Apache License 2.0
from SourceHot

/**
 * Set the {@linkplain Field field} with the given {@code name}/{@code type}
 * on the provided {@code targetObject}/{@code targetClreplaced} to the supplied
 * {@code value}.
 * <p>If the supplied {@code targetObject} is a <em>proxy</em>, it will
 * be {@linkplain AopTestUtils#getUltimateTargetObject unwrapped} allowing
 * the field to be set on the ultimate target of the proxy.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * field. In addition, an attempt will be made to make non-{@code public}
 * fields <em>accessible</em>, thus allowing one to set {@code protected},
 * {@code private}, and <em>package-private</em> fields.
 * <p>This method does not support setting {@code static final} fields.
 * @param targetObject the target object on which to set the field; may be
 * {@code null} if the field is static
 * @param targetClreplaced the target clreplaced on which to set the field; may
 * be {@code null} if the field is an instance field
 * @param name the name of the field to set; may be {@code null} if
 * {@code type} is specified
 * @param value the value to set
 * @param type the type of the field to set; may be {@code null} if
 * {@code name} is specified
 * @since 4.2
 * @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
 * @see ReflectionUtils#makeAccessible(Field)
 * @see ReflectionUtils#setField(Field, Object, Object)
 * @see AopTestUtils#getUltimateTargetObject(Object)
 */
public static void setField(@Nullable Object targetObject, @Nullable Clreplaced<?> targetClreplaced, @Nullable String name, @Nullable Object value, @Nullable Clreplaced<?> type) {
    replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
    if (targetObject != null && springAopPresent) {
        targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
    }
    if (targetClreplaced == null) {
        targetClreplaced = targetObject.getClreplaced();
    }
    Field field = ReflectionUtils.findField(targetClreplaced, name, type);
    if (field == null) {
        throw new IllegalArgumentException(String.format("Could not find field '%s' of type [%s] on %s or target clreplaced [%s]", name, type, safeToString(targetObject), targetClreplaced));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Setting field '%s' of type [%s] on %s or target clreplaced [%s] to value [%s]", name, type, safeToString(targetObject), targetClreplaced, value));
    }
    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, targetObject, value);
}

17 Source : ConnectionPoolUnitTests.java
with Apache License 2.0
from r2dbc

private void addDestroyHandler(ConnectionPool pool, Runnable runnable) {
    Field field = ReflectionUtils.findField(ConnectionPool.clreplaced, "destroyHandlers");
    field.setAccessible(true);
    List<Runnable> destroyHandlers = (List<Runnable>) ReflectionUtils.getField(field, pool);
    destroyHandlers.add(runnable);
}

17 Source : AbstractTest.java
with Apache License 2.0
from OpenWiseSolutions

/**
 * Sets value of private field.
 *
 * @param target the target object
 * @param name   the field name
 * @param value  the value for setting to the field
 */
public static void setPrivateField(Object target, String name, Object value) {
    Field countField = ReflectionUtils.findField(target.getClreplaced(), name);
    ReflectionUtils.makeAccessible(countField);
    ReflectionUtils.setField(countField, target, value);
}

17 Source : AssetLineageClientTest.java
with Apache License 2.0
from odpi

@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    replacedetLineage = new replacedetLineage(SERVER_NAME, SERVER_URL);
    Field connectorField = ReflectionUtils.findField(replacedetLineage.clreplaced, "clientConnector");
    if (connectorField != null) {
        connectorField.setAccessible(true);
        ReflectionUtils.setField(connectorField, replacedetLineage, connector);
        connectorField.setAccessible(false);
    }
}

17 Source : AssetCatalogRelationshipServiceTest.java
with Apache License 2.0
from odpi

@Before
public void before() {
    MockitoAnnotations.initMocks(this);
    Field instanceHandlerField = ReflectionUtils.findField(replacedetCatalogRelationshipRESTService.clreplaced, "instanceHandler");
    instanceHandlerField.setAccessible(true);
    ReflectionUtils.setField(instanceHandlerField, replacedetCatalogRelationshipService, instanceHandler);
    instanceHandlerField.setAccessible(false);
    Field restExceptionHandlerField = ReflectionUtils.findField(replacedetCatalogRelationshipRESTService.clreplaced, "restExceptionHandler");
    restExceptionHandlerField.setAccessible(true);
    ReflectionUtils.setField(restExceptionHandlerField, replacedetCatalogRelationshipService, restExceptionHandler);
    restExceptionHandlerField.setAccessible(false);
    response = mockRelationshipResponse();
}

17 Source : SpringResultSetAutoMapper.java
with Apache License 2.0
from mhewedy

private Integer getRowIndex(Result<?> result) {
    Field rowIndexField = ReflectionUtils.findField(result.getClreplaced(), "rowIndex");
    rowIndexField.setAccessible(true);
    return (Integer) ReflectionUtils.getField(rowIndexField, result);
}

17 Source : AopProxyUtils.java
with Apache License 2.0
from leiyong0326

private static ProxyFactory findCglibProxyFactory(final Object proxy) {
    Field field = ReflectionUtils.findField(proxy.getClreplaced(), "CGLIB$CALLBACK_0");
    ReflectionUtils.makeAccessible(field);
    Object CGLIB$CALLBACK_0 = ReflectionUtils.getField(field, proxy);
    return (ProxyFactory) ReflectionUtils.getField(CglibAopProxy$DynamicAdvisedInterceptor_advised_FIELD, CGLIB$CALLBACK_0);
}

17 Source : BeanFactoryUtil.java
with Apache License 2.0
from learningtcc

private Object getFieldValue(Object obj, String fieldName) {
    Field field = ReflectionUtils.findField(obj.getClreplaced(), fieldName);
    if (field != null) {
        ReflectionUtils.makeAccessible(field);
        return ReflectionUtils.getField(field, obj);
    }
    return null;
}

17 Source : ReflectionTestUtils.java
with Apache License 2.0
from langtianya

/**
 * Set the {@linkplain Field field} with the given {@code name}/{@code type}
 * on the provided {@code targetObject}/{@code targetClreplaced} to the supplied
 * {@code value}.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * field. In addition, an attempt will be made to make non-{@code public}
 * fields <em>accessible</em>, thus allowing one to set {@code protected},
 * {@code private}, and <em>package-private</em> fields.
 * @param targetObject the target object on which to set the field; may be
 * {@code null} if the field is static
 * @param targetClreplaced the target clreplaced on which to set the field; may
 * be {@code null} if the field is an instance field
 * @param name the name of the field to set; may be {@code null} if
 * {@code type} is specified
 * @param value the value to set
 * @param type the type of the field to set; may be {@code null} if
 * {@code name} is specified
 * @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
 * @see ReflectionUtils#makeAccessible(Field)
 * @see ReflectionUtils#setField(Field, Object, Object)
 * @since 4.2
 */
public static void setField(Object targetObject, Clreplaced<?> targetClreplaced, String name, Object value, Clreplaced<?> type) {
    replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
    if (targetClreplaced == null) {
        targetClreplaced = targetObject.getClreplaced();
    }
    Field field = ReflectionUtils.findField(targetClreplaced, name, type);
    if (field == null) {
        throw new IllegalArgumentException(String.format("Could not find field '%s' of type [%s] on target object [%s] or target clreplaced [%s]", name, type, targetObject, targetClreplaced));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Setting field '%s' of type [%s] on target object [%s] or target clreplaced [%s] to value [%s]", name, type, targetObject, targetClreplaced, value));
    }
    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, targetObject, value);
}

17 Source : ReflectionTestUtils.java
with Apache License 2.0
from langtianya

/**
 * Get the value of the {@linkplain Field field} with the given {@code name}
 * from the provided {@code targetObject}/{@code targetClreplaced}.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * field. In addition, an attempt will be made to make non-{@code public}
 * fields <em>accessible</em>, thus allowing one to get {@code protected},
 * {@code private}, and <em>package-private</em> fields.
 * @param targetObject the target object from which to get the field; may be
 * {@code null} if the field is static
 * @param targetClreplaced the target clreplaced from which to get the field; may
 * be {@code null} if the field is an instance field
 * @param name the name of the field to get; never {@code null}
 * @return the field's current value
 * @since 4.2
 * @see #getField(Object, String)
 * @see #getField(Clreplaced, String)
 * @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
 * @see ReflectionUtils#makeAccessible(Field)
 * @see ReflectionUtils#getField(Field, Object)
 */
public static Object getField(Object targetObject, Clreplaced<?> targetClreplaced, String name) {
    replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
    if (targetClreplaced == null) {
        targetClreplaced = targetObject.getClreplaced();
    }
    Field field = ReflectionUtils.findField(targetClreplaced, name);
    if (field == null) {
        throw new IllegalArgumentException(String.format("Could not find field '%s' on target object [%s] or target clreplaced [%s]", name, targetObject, targetClreplaced));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Getting field '%s' from target object [%s] or target clreplaced [%s]", name, targetObject, targetClreplaced));
    }
    ReflectionUtils.makeAccessible(field);
    return ReflectionUtils.getField(field, targetObject);
}

17 Source : DirectFieldAccessor.java
with Apache License 2.0
from langtianya

@Override
protected FieldPropertyHandler getLocalPropertyHandler(String propertyName) {
    FieldPropertyHandler propertyHandler = this.fieldMap.get(propertyName);
    if (propertyHandler == null) {
        Field field = ReflectionUtils.findField(getWrappedClreplaced(), propertyName);
        if (field != null) {
            propertyHandler = new FieldPropertyHandler(field);
        }
        this.fieldMap.put(propertyName, propertyHandler);
    }
    return propertyHandler;
}

17 Source : ValidatorUtil.java
with Apache License 2.0
from landy8530

public static void setNullIfInvalid(CustomerRequestDetail detail, String columnName) {
    Field dataField = ReflectionUtils.findField(CustomerRequestDetail.clreplaced, columnName);
    ReflectionUtils.makeAccessible(dataField);
    ReflectionUtils.setField(dataField, detail, null);
}

17 Source : MybatisGeneratorPlugin.java
with Apache License 2.0
from jufeng98

public static void appendMethod(TopLevelClreplaced topLevelClreplaced, IntrospectedTable introspectedTable) {
    // 添加enreplacedy类注释
    String docLine = "/**\n" + " * %s,请勿手工改动此文件,请使用 mybatis generator\n" + " * \n" + " * @author mybatis generator\n" + " */";
    docLine = String.format(docLine, introspectedTable.getRemarks());
    topLevelClreplaced.addJavaDocLine(docLine);
    topLevelClreplaced.addImportedType("org.apache.commons.lang3.builder.EqualsBuilder");
    topLevelClreplaced.addImportedType("org.apache.commons.lang3.builder.HashCodeBuilder");
    topLevelClreplaced.addImportedType("org.apache.commons.lang3.builder.ToStringBuilder");
    topLevelClreplaced.addImportedType("org.apache.commons.lang3.builder.ToStringStyle");
    List<Method> newMethods = new ArrayList<>();
    Method toStringMethod = new Method();
    toStringMethod.addAnnotation("@Override");
    toStringMethod.setVisibility(JavaVisibility.PUBLIC);
    toStringMethod.setReturnType(FullyQualifiedJavaType.getStringInstance());
    toStringMethod.setName("toString");
    toStringMethod.addBodyLine("return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);");
    newMethods.add(toStringMethod);
    Method equalsMethod = new Method();
    equalsMethod.addAnnotation("@Override");
    equalsMethod.setVisibility(JavaVisibility.PUBLIC);
    equalsMethod.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    equalsMethod.setName("equals");
    equalsMethod.addParameter(0, new Parameter(FullyQualifiedJavaType.getObjectInstance(), "obj"));
    equalsMethod.addBodyLine("return EqualsBuilder.reflectionEquals(this, obj);");
    newMethods.add(equalsMethod);
    Method hashMethod = new Method();
    hashMethod.addAnnotation("@Override");
    hashMethod.setVisibility(JavaVisibility.PUBLIC);
    hashMethod.setReturnType(FullyQualifiedJavaType.getIntInstance());
    hashMethod.setName("hashCode");
    hashMethod.addBodyLine("return HashCodeBuilder.reflectionHashCode(this);");
    newMethods.add(hashMethod);
    newMethods.addAll(topLevelClreplaced.getMethods());
    try {
        java.lang.reflect.Field field = ReflectionUtils.findField(topLevelClreplaced.getClreplaced(), "methods");
        replacedert field != null;
        field.setAccessible(true);
        field.set(topLevelClreplaced, newMethods);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

17 Source : ReflectTest.java
with Apache License 2.0
from isstac

/**
 * @see Reflect#isSuperClreplaced(Type)
 */
@Test
public void isSuperClreplaced_shouldReturnTrueForAGenericWhoseBoundIsASubclreplaced() {
    Reflect reflect = new Reflect(OpenmrsObject.clreplaced);
    Field field = ReflectionUtils.findField(Visit.clreplaced, "attributes");
    ParameterizedType setOfAttr = (ParameterizedType) field.getGenericType();
    Type genericType = setOfAttr.getActualTypeArguments()[0];
    replacedert.replacedertTrue(reflect.isSuperClreplaced(genericType));
}

17 Source : ReflectTest.java
with Apache License 2.0
from isstac

/**
 * @see Reflect#isSuperClreplaced(Type)
 */
@Test
public void isSuperClreplaced_shouldReturnFalseForAGenericWhoseBoundIsNotASubclreplaced() {
    Reflect reflect = new Reflect(Number.clreplaced);
    Field field = ReflectionUtils.findField(Visit.clreplaced, "attributes");
    ParameterizedType setOfAttr = (ParameterizedType) field.getGenericType();
    Type genericType = setOfAttr.getActualTypeArguments()[0];
    replacedert.replacedertFalse(reflect.isSuperClreplaced(genericType));
}

17 Source : InterceptorFileService.java
with Apache License 2.0
from getheimdall

/*
     * Clears the loader cache
     */
private void clearLoaderCache() {
    FilterLoader filterLoader = FilterLoader.getInstance();
    Field field = ReflectionUtils.findField(FilterLoader.clreplaced, "hashFiltersByType");
    ReflectionUtils.makeAccessible(field);
    Map<?, ?> cache = (Map<?, ?>) ReflectionUtils.getField(field, filterLoader);
    cache.clear();
}

17 Source : ReferenceAnnotationBeanPostProcessor.java
with Apache License 2.0
from boomblog

private <T> T getFieldValue(Object object, String fieldName, Clreplaced<T> fieldType) {
    Field field = ReflectionUtils.findField(object.getClreplaced(), fieldName, fieldType);
    ReflectionUtils.makeAccessible(field);
    return (T) ReflectionUtils.getField(field, object);
}

17 Source : ReflectionSupport.java
with Apache License 2.0
from BlackPepperSoftware

private static Field getIdField(Clreplaced<?> clazz) {
    Method idAccessor = getIdAccessor(clazz);
    return ReflectionUtils.findField(clazz, HalSupport.toLinkName(idAccessor.getName()));
}

17 Source : AmazonEc2InstanceDataPropertySourceAwsTest.java
with Apache License 2.0
from awspring

private static void restContextInstanceDataCondition() throws IllegalAccessException {
    Field field = ReflectionUtils.findField(AwsCloudEnvironmentCheckUtils.clreplaced, "isCloudEnvironment");
    replacedertThat(field).isNotNull();
    ReflectionUtils.makeAccessible(field);
    field.set(null, null);
}

See More Examples