/** See doc in {@link CtMethod#copyMethod()} */ public static CtMethod<?> copyMethod(final CtMethod<?> method) { CtMethod<?> clone = method.clone(); StringBuilder tentativeTypeName = new StringBuilder(method.getSimpleName() + "Copy"); CtType parent = method.getParent(CtType.class); while (!parent.getMethodsByName(tentativeTypeName.toString()).isEmpty()) { tentativeTypeName.append("X"); } final String cloneMethodName = tentativeTypeName.toString(); clone.setSimpleName(cloneMethodName); parent.addMethod(clone); new CtScanner() { @Override public <T> void visitCtExecutableReference(CtExecutableReference<T> reference) { CtExecutable<T> declaration = reference.getDeclaration(); if (declaration == null) { return; } if (declaration == method) { reference.setSimpleName(cloneMethodName); } if (reference.getDeclaration() != clone) { throw new SpoonException("post condition broken " + reference); } super.visitCtExecutableReference(reference); } }.scan(clone); return clone; }
public static boolean isInterfaceMethod(CtMethod<?> method) { return isInterface(method.getParent()); }
public void process(CtMethod<?> element) { element.getParent(CtClass.class).removeMethod(element); }
@Override protected boolean isATest(CtMethod<?> candidate) { // checkEnum that the current test class inherit from TestCase final CtType<?> testClass = candidate.getParent(CtType.class); if (testClass == null) { return false; } final CtTypeReference<?> superclassReference = testClass.getSuperclass(); if (superclassReference == null) { return false; } return superclassReference.getQualifiedName().equals(this.qualifiedNameOfAssertClass) && candidate.getAnnotations().isEmpty() && candidate.getSimpleName().startsWith("test"); }
return factoryMethod.stream() .map(method -> factory.createInvocation(factory.createTypeAccess(method.getParent(CtType.class).getReference(), true), method.getReference(), method.getParameters().stream()