use of java.lang.reflect.Field in project dex2jar by pxb1988.
the class BaseCmd method initOptionFromClass.
protected void initOptionFromClass(Class<?> clz) {
if (clz == null) {
return;
} else {
initOptionFromClass(clz.getSuperclass());
}
Syntax syntax = clz.getAnnotation(Syntax.class);
if (syntax != null) {
this.cmdLineSyntax = syntax.syntax();
this.cmdName = syntax.cmd();
this.desc = syntax.desc();
this.onlineHelp = syntax.onlineHelp();
}
Field[] fs = clz.getDeclaredFields();
for (Field f : fs) {
Opt opt = f.getAnnotation(Opt.class);
if (opt != null) {
f.setAccessible(true);
Option option = new Option();
option.field = f;
option.description = opt.description();
option.hasArg = opt.hasArg();
option.required = opt.required();
if ("".equals(opt.longOpt()) && "".equals(opt.opt())) {
// into automode
option.longOpt = fromCamel(f.getName());
if (f.getType().equals(boolean.class)) {
option.hasArg = false;
try {
if (f.getBoolean(this)) {
throw new RuntimeException("the value of " + f + " must be false, as it is declared as no args");
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
checkConflict(option, "--" + option.longOpt);
continue;
}
if (!opt.hasArg()) {
if (!f.getType().equals(boolean.class)) {
throw new RuntimeException("the type of " + f + " must be boolean, as it is declared as no args");
}
try {
if (f.getBoolean(this)) {
throw new RuntimeException("the value of " + f + " must be false, as it is declared as no args");
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
boolean haveLongOpt = false;
if (!"".equals(opt.longOpt())) {
option.longOpt = opt.longOpt();
checkConflict(option, "--" + option.longOpt);
haveLongOpt = true;
}
if (!"".equals(opt.argName())) {
option.argName = opt.argName();
}
if (!"".equals(opt.opt())) {
option.opt = opt.opt();
checkConflict(option, "-" + option.opt);
} else {
if (!haveLongOpt) {
throw new RuntimeException("opt or longOpt is not set in @Opt(...) " + f);
}
}
}
}
}
use of java.lang.reflect.Field in project spring-loaded by spring-projects.
the class ClassReflectionTests method assertField.
private void assertField(String expectedSignature, Result r) {
Assert.assertEquals(Field.class, r.returnValue.getClass());
Field f = (Field) r.returnValue;
Assert.assertEquals(expectedSignature, f.toString());
}
use of java.lang.reflect.Field in project spring-loaded by spring-projects.
the class SpringLoadedTests method getFieldAccessor.
protected ISMgr getFieldAccessor(Object o) {
Class<?> clazz = o.getClass();
try {
Field f = clazz.getDeclaredField(Constants.fInstanceFieldsName);
f.setAccessible(true);
return (ISMgr) f.get(o);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of java.lang.reflect.Field in project spring-loaded by spring-projects.
the class GenerativeSpringLoadedTest method targetFieldFrom.
/**
* Select a field from given class's declared field as a test target.
*
* @throws RejectedChoice If class has no fields to choose from.
*/
protected Field targetFieldFrom(Class<?> clazz, FieldGetMethod howToGet) throws RejectedChoice {
Field[] fields = null;
switch(howToGet) {
case GET_DECLARED_FIELD:
case GET_DECLARED_FIELDS:
fields = ReflectiveInterceptor.jlClassGetDeclaredFields(clazz);
break;
case GET_FIELD:
case GET_FIELDS:
fields = ReflectiveInterceptor.jlClassGetFields(clazz);
break;
}
//To be deterministic we must sort these in a predictable fashion!
// Arrays.sort(fields, new ToStringComparator());
sort(fields);
Field f = choice(fields);
toStringValue.append(f.getName());
try {
switch(howToGet) {
case GET_DECLARED_FIELDS:
case GET_FIELDS:
return f;
case GET_DECLARED_FIELD:
return ReflectiveInterceptor.jlClassGetDeclaredField(clazz, f.getName());
case GET_FIELD:
return ReflectiveInterceptor.jlClassGetField(clazz, f.getName());
}
} catch (Exception e) {
throw new Error(e);
}
return f;
}
use of java.lang.reflect.Field in project platform_frameworks_base by android.
the class ContentProviderOperationTest method operationGetValues.
private ContentValues operationGetValues(ContentProviderOperation operation) throws NoSuchFieldException, IllegalAccessException {
final Field field = CLASS_OPERATION.getDeclaredField("mValues");
field.setAccessible(true);
return (ContentValues) field.get(operation);
}
Aggregations