private void feed(Object ref, Person hlo) { try { Method feed = ReflectionUtils.requireMethod(Reformatory.class, "feed", Person.class); ReflectionUtils.invokeMethod(void.class, feed, ref, hlo); } catch (Throwable t) { } }
private int totalWeightsMeasured(Object ref) { try { Method totalWeightsMeasured = ReflectionUtils.requireMethod(Reformatory.class, "totalWeightsMeasured"); return ReflectionUtils.invokeMethod(int.class, totalWeightsMeasured, ref); } catch (Throwable t) { } return -1; }
private void callMain(Class kl) { try { kl = ReflectionUtils.newInstanceOfClass(kl); String x[] = new String[0]; Method m = ReflectionUtils.requireMethod(kl, "main", x.getClass()); ReflectionUtils.invokeMethod(Void.TYPE, m, null, (Object) x); } catch (NoSuchElementException e) { fail("use Integer.parseInt( reader.nextline() ) to read the numbers"); } catch (Throwable e) { fail("something unexpected happened " + e); } }
private void saniteettitarkastus() throws SecurityException { Field[] kentat = ReflectionUtils.findClass(luokanNimi).getDeclaredFields(); for (Field field : kentat) { assertFalse( "does not need \"static variables\", remove " + kentta(field.toString()), field.toString().contains("static") && !field.toString().contains("final")); assertTrue( "all the object variables should be private, please change " + kentta(field.toString()), field.toString().contains("private")); } if (kentat.length > 1) { int var = 0; for (Field field : kentat) { if (!field.toString().contains("final")) { var++; } } assertTrue( "The class " + luokanNimi + " needs only instance variable for the amount of weightings, remove the extra " + "", var < 2); } }
private void saniteettitarkastus(int n, String m) throws SecurityException { Field[] kentat = ReflectionUtils.findClass(luokanNimi).getDeclaredFields(); for (Field field : kentat) { assertFalse( "does not need \"static variables\", remove " + kentta(field.toString()), field.toString().contains("static") && !field.toString().contains("final")); assertTrue( "all the object variables should be private, please change " + kentta(field.toString()), field.toString().contains("private")); } if (kentat.length > 1) { int var = 0; for (Field field : kentat) { if (!field.toString().contains("final")) { var++; System.err.println("JAMO:fields"); } } String s = n > 1 ? "s" : ""; assertTrue( "The class " + klassName + " needs instance variable" + s + " only for " + m + ", remove the rest", var <= n); } }