nkist88.object2source.0.0.1.source-code.common-methods.txt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of object2source Show documentation
Show all versions of object2source Show documentation
A library for generating the source code that creates an instance of the object that is submitted to the input.
-----------------
getCalendarInstance(, )
-----------------
public static java.util.GregorianCalendar getCalendarInstance(String tzId, long mTime) {
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.setTimeZone(java.util.TimeZone.getTimeZone(tzId));
cal.setTimeInMillis(mTime);
return (java.util.GregorianCalendar) cal;
}
-----------------
getClassWithMethodsHierarchy()
-----------------
public static java.util.List getClassWithMethodsHierarchy(Class> clazz){
java.util.List classesWithParent = new java.util.ArrayList<>();
Class> currentClass = clazz;
while (currentClass.getDeclaredFields().length > 0) {
classesWithParent.add(currentClass);
currentClass = currentClass.getSuperclass();
}
return classesWithParent;
}
-----------------
getAllFieldsOfObject()
-----------------
public static java.util.List getAllFieldsOfObject(Object obj) {
java.util.List allFields = new java.util.ArrayList<>();
for(Class c : getClassWithMethodsHierarchy(obj.getClass())) {
allFields.addAll(java.util.Arrays.asList(c.getDeclaredFields()));
}
return allFields;
}
-----------------
notPublicAssignment(, , )
-----------------
public static void notPublicAssignment(Object obj, String fieldName, Object value) throws IllegalAccessException {
for(java.lang.reflect.Field f : getAllFieldsOfObject(obj)) {
if(f.getName().equals(fieldName)) {
boolean currentAccessible = f.isAccessible();
f.setAccessible(true);
f.set(obj, value);
f.setAccessible(currentAccessible);
}
}
}
-----------------
newInstanceHard()
-----------------
public static Object newInstanceHard(Class type) {
try {
java.lang.reflect.Constructor mungedConstructor = newConstructorForSerialization(type, getJavaLangObjectConstructor());
mungedConstructor.setAccessible(true);
return mungedConstructor.newInstance((Object[]) null);
} catch(Exception e) {
throw new IllegalStateException(e);
}
}
-----------------
getJavaLangObjectConstructor()
-----------------
public static java.lang.reflect.Constructor