本文整理汇总了Java中org.apache.commons.lang3.reflect.FieldUtils.writeStaticField方法的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils.writeStaticField方法的具体用法?Java FieldUtils.writeStaticField怎么用?Java FieldUtils.writeStaticField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.FieldUtils
的用法示例。
在下文中一共展示了FieldUtils.writeStaticField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeAllStaticFieldsOfType
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
public static <T> void writeAllStaticFieldsOfType(Class d, T t, Class c) throws IllegalAccessException
{
boolean wroteSomething = false;
for (Field f : FieldUtils.getAllFields(d))
{
if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
{
FieldUtils.writeStaticField(f, t, true);
wroteSomething = true;
}
}
if (!wroteSomething)
throw new IllegalAccessException();
}
示例2: apply
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
System.setProperty(Constants.LOG4J_LOG_EVENT_FACTORY, TestLogEventFactory.class.getName());
resetLogEventFactory(new TestLogEventFactory());
try {
base.evaluate();
} finally {
System.clearProperty(Constants.LOG4J_LOG_EVENT_FACTORY);
resetLogEventFactory(new DefaultLogEventFactory());
}
}
private void resetLogEventFactory(final LogEventFactory logEventFactory) throws IllegalAccessException {
final Field field = FieldUtils.getField(LoggerConfig.class, "LOG_EVENT_FACTORY", true);
FieldUtils.removeFinalModifier(field, true);
FieldUtils.writeStaticField(field, logEventFactory, false);
}
};
}
示例3: writeStaticFieldOfType
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
public static <T> void writeStaticFieldOfType(Class d, T t, Class<T> c) throws IllegalAccessException
{
for (Field f : FieldUtils.getAllFields(d))
{
if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
{
FieldUtils.writeStaticField(f, t, true);
return;
}
}
throw new IllegalAccessException();
}
示例4: setUp
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
FieldUtils.writeStaticField(CommandUtils.class, "logger", loggerMock, true);
commandStr = ArgumentCaptor.forClass(String.class);
config = new DockerComposeConfiguration(TEST_YAML);
}
示例5: writeStatic
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Write static final field on given class.
*
* @param klass The class.
* @param name The field name.
* @param value The new field value.
* @param <T> Type of value to write.
*/
public static <T> void writeStatic(Class<?> klass, String name, T value) {
try {
Field field = FieldUtils.getField(klass, name, true);
FieldUtils.removeFinalModifier(field);
FieldUtils.writeStaticField(field, value, true);
} catch (Exception ex) {
throw new AssertionError(ex);
}
}
示例6: writeStaticFinal
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Write value on given static final field.
*
* @param klass The class.
* @param name The field name.
* @param value The new field value.
*/
public static void writeStaticFinal(Class<?> klass, String name, Object value) {
Field field = FieldUtils.getDeclaredField(klass, name, true);
FieldUtils.removeFinalModifier(field);
try {
FieldUtils.writeStaticField(field, value, true);
} catch (IllegalAccessException ex) {
throw new AssertionError(ex);
}
}
示例7: setUp
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
FieldUtils.writeStaticField(DockerCommandUtils.class, "logger", loggerMock, true);
FieldUtils.writeStaticField(CommandUtils.class, "logger", loggerMock, true);
logArgStr = ArgumentCaptor.forClass(String.class);
}
示例8: tearDown
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
FieldUtils.writeStaticField(DockerCommandUtils.class, "logger",
LoggerFactory.getLogger(DockerCommandUtils.LOGGER_LABEL), true);
}
示例9: resetClock
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static void resetClock(final Class<?> clazz) throws IllegalAccessException {
System.clearProperty(ClockFactory.PROPERTY_NAME);
final Field field = FieldUtils.getField(clazz, "CLOCK", true);
FieldUtils.removeFinalModifier(field, true);
FieldUtils.writeStaticField(field, ClockFactory.getClock(), false);
}