本文整理匯總了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);
}