continue; if (Modifier.isAbstract(subClazz.getModifiers())) { if (!TestClusterUtils.hasStaticGenerator(subClazz)) continue; } else { if (!TestClusterUtils.checkIfCanUse(subClazz.getCanonicalName())) { continue;
for (Method m : getMethods(clazz.getSuperclass())) { helper.put(m.getName() + org.objectweb.asm.Type.getMethodDescriptor(m), m); for (Method m : getMethods(in)) { helper.put(m.getName() + org.objectweb.asm.Type.getMethodDescriptor(m), m);
/** {@inheritDoc} */ @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, access, name, signature, superName, interfaces); if (superName.equals("java/lang/Enum")) isEnum = true; if(TestClusterUtils.isAnonymousClass(name)) isAnonymous = true; }
int distance = TestClusterUtils.getPackageDistance(subClass, name); classDistance.put(subClass, distance); maxDistance = Math.max(distance, maxDistance); logger.debug(" Current distance: " + distance); for (String subClass : subClasses) { if (TestClusterUtils.isAnonymousClass(subClass)) { continue; continue; if (Modifier.isAbstract(subClazz.getModifiers())) { if(!TestClusterUtils.hasStaticGenerator(subClazz)) continue; } else { if (!TestClusterUtils.checkIfCanUse(subClazz.getCanonicalName())) { continue; if(TestClusterUtils.hasStaticGenerator(clazz)) { actualClasses.add(clazz);
for (Constructor<?> constructor : TestClusterUtils.getConstructors(clazz)) { logger.info("Checking target constructor " + constructor); String name = "<init>" + org.objectweb.asm.Type.getConstructorDescriptor(constructor); for (Method method : TestClusterUtils.getMethods(clazz)) { logger.info("Checking target method " + method); String name = method.getName() + org.objectweb.asm.Type.getMethodDescriptor(method); for (Field field : TestClusterUtils.getFields(clazz)) { logger.info("Checking target field " + field); try { Sandbox.goingToExecuteUnsafeCodeOnSameThread(); clazz = TestClusterUtils.getClass(className); } catch (ExceptionInInitializerError ex) { logger.debug("Class class init caused exception " + className); for (Field field : TestClusterUtils.getFields(clazz)) { if (!TestUsageChecker.canUse(field, clazz)) continue; Class<?> clazz = TestClusterUtils.getClass(methodId.getClassName()); if (clazz == null) continue; continue; Method method = TestClusterUtils.getMethod(clazz, methodId.getMethodName(), methodId.getDesc());
for (Constructor<?> constructor : TestClusterUtils.getConstructors(clazz.getRawClass())) { String name = "<init>" + org.objectweb.asm.Type.getConstructorDescriptor(constructor); for (Method method : TestClusterUtils.getMethods(clazz.getRawClass())) { String name = method.getName() + org.objectweb.asm.Type.getMethodDescriptor(method); for (Field field : TestClusterUtils.getFields(clazz.getRawClass())) { logger.debug("Checking field " + field); if (TestUsageChecker.canUse(field, clazz.getRawClass())) {
return false; if (TestClusterUtils.isEvoSuiteClass(c) && !MockList.isAMockClass(c.getCanonicalName())) { return false; if(TestClusterUtils.isAnonymousClass(c.getName())) { String message = c + " looks like an anonymous class, ignoring it (although reflection says "+c.isAnonymousClass()+") "+c.getSimpleName(); LoggingUtils.logWarnAtMostOnce(logger, message);
@Test public void test_checkIfCanUse_withVFS(){ RuntimeSettings.useVFS = true; boolean canUse = TestClusterUtils.checkIfCanUse(File.class.getCanonicalName()); Assert.assertFalse(canUse); } }
private void addFields(List<VariableReference> variables, VariableReference var, Type type) { if (!var.isPrimitive() && !(var instanceof NullReference)) { // add fields of this object to list for (Field field : TestClusterUtils.getAccessibleFields(var.getVariableClass())) { Type fieldType = field.getType(); try { fieldType = field.getGenericType(); } catch (java.lang.reflect.GenericSignatureFormatError e) { // Ignore fieldType = field.getType(); } FieldReference f = new FieldReference(this, new GenericField(field, var.getGenericClass()), fieldType, var); if (f.getDepth() <= 2) { if (type != null) { if (f.isAssignableTo(type) && !variables.contains(f)) { variables.add(f); } } else if (!variables.contains(f)) { variables.add(f); } } } } }
/** * Get the set of fields defined in this class and its superclasses * * @param clazz * @return */ public static Set<Field> getFields(Class<?> clazz) { // TODO: Helper not necessary here! Map<String, Field> helper = new TreeMap<>(); Set<Field> fields = new LinkedHashSet<>(); if (clazz.getSuperclass() != null) { for (Field f : getFields(clazz.getSuperclass())) { helper.put(f.toGenericString(), f); } } for (Class<?> in : Reflection.getInterfaces(clazz)) { for (Field f : getFields(in)) { helper.put(f.toGenericString(), f); } } for (Field f : Reflection.getDeclaredFields(clazz)) { helper.put(f.toGenericString(), f); } fields.addAll(helper.values()); return fields; }
continue; for (Method method : TestClusterUtils.getClass(className).getDeclaredMethods()) { String methodName = method.getName() + Type.getMethodDescriptor(method); if (!TestUsageChecker.canUse(method))
Class<?> oldClass = constructor.getDeclaringClass(); Class<?> newClass = loader.loadClass(oldClass.getName()); for (Constructor<?> newConstructor : TestClusterUtils.getConstructors(newClass)) { boolean equals = true; Class<?>[] oldParameters = this.constructor.getParameterTypes();
@Test public void test_checkIfCanUse_noVFS(){ RuntimeSettings.useVFS = false; boolean canUse = TestClusterUtils.checkIfCanUse(File.class.getCanonicalName()); Assert.assertTrue(canUse); }
if (!value.isPrimitive() && !(value instanceof NullReference)) { for (Field field : TestClusterUtils.getAccessibleFields(value.getVariableClass())) { if(TestClusterGenerator.isFinalField(field)) continue;
ReplaceVariable.class.getClassLoader()); for (Field field : TestClusterUtils.getFields(clazz)) {
continue; for (Method method : TestClusterUtils.getClass(className).getDeclaredMethods()) { String methodName = method.getName() + Type.getMethodDescriptor(method); if (!TestUsageChecker.canUse(method) || methodName.equals("hashCode()I"))
@Test public void testIsAnonymousWithVAnonymousClassName() { Object o = new Object() { // ... }; assertTrue(TestClusterUtils.isAnonymousClass(o.getClass().getName())); }
Class<?> oldClass = method.getDeclaringClass(); Class<?> newClass = loader.loadClass(oldClass.getName()); for (Method newMethod : TestClusterUtils.getMethods(newClass)) { if (newMethod.getName().equals(this.method.getName())) { boolean equals = true;
} else { if (!TestClusterUtils.checkIfCanUse(clazz.getClassName())) { return;
@Test public void testIsAnonymousWithNameEndingWithDollar() { assertFalse(TestClusterUtils.isAnonymousClass("Option$None$")); } }