@Override public void process(CtInvocation element) { if(element.getParent() instanceof CtBlock){ if(!element.toString().equals("super()")) super.add((CtStatement)element); } }
private List<CtInvocation> getInvocations(CtMethod<?> method) { List<CtInvocation> statements = Query.getElements(method, new TypeFilter(CtInvocation.class)); return statements.stream() .filter(invocation -> invocation.getParent() instanceof CtBlock) //.filter(stmt -> stmt.getExecutable().getDeclaringType().getQualifiedName().startsWith(filter)) // filter on the name for amplify a specific type .collect(Collectors.toList()); }
CtType<?> aType = invocation.getParent(CtType.class); CtTypeReference<?> execDeclaringType = invocation.getExecutable().getDeclaringType();
private static void removeExpectedException(Configuration configuration, Launcher spoon, String fullQualifiedName, String testCaseName, String cp, CtMethod<?> clone) { final CtTry ctTry = clone.getElements(new TypeFilter<>(CtTry.class)).get(0); ctTry.replace(ctTry.getBody()); final CtInvocation failToRemove = clone.getElements(new TypeFilter<>(CtInvocation.class)).stream() .filter(Util.isFail) .findFirst() .orElseThrow(RuntimeException::new); final boolean remove = failToRemove.getParent(CtBlock.class).getStatements().remove(failToRemove); if (!remove) { throw new RuntimeException(); } TestRunner.runTest(configuration, spoon, fullQualifiedName, testCaseName); }
CtType<?> parentType; try { parentType = invocation.getParent(CtType.class); } catch (ParentNotInitializedException e) { parentType = null;
static List<Integer> replaceByLogStatement(CtMethod<?> clone) { final List<CtInvocation> assertionsToBeReplaced = clone.getElements(new TypeFilter<CtInvocation>(CtInvocation.class) { @Override public boolean matches(CtInvocation element) { return Util.isAssert.test(element) && super.matches(element); } }).stream() .sorted(Comparator.comparingInt(ctInvocation -> ctInvocation.getPosition().getLine())) .collect(Collectors.toList()); final List<Integer> indices = new ArrayList<>(); assertionsToBeReplaced.forEach(assertionToBeReplaced -> { final int index = assertionToBeReplaced.getParent(CtBlock.class).getStatements().indexOf(assertionToBeReplaced); indices.add(index); String snippet = "eu.stamp.project.assertfixer.asserts.log.Logger.log("; if (assertionToBeReplaced.getExecutable().getSimpleName().endsWith("True") || assertionToBeReplaced.getExecutable().getSimpleName().endsWith("False")) { assertionToBeReplaced.replace( clone.getFactory().createCodeSnippetStatement(snippet + index + "," + assertionToBeReplaced.getArguments().get(0) + ")") ); } else { assertionToBeReplaced.replace( clone.getFactory().createCodeSnippetStatement(snippet + index + "," + assertionToBeReplaced.getArguments().get(1) + ")") ); } }); return indices; }
@Override public boolean isToBeProcessed(CtInvocation<?> candidate) { if (!candidate.getExecutable().getSimpleName().contains("assert")) { return false; } CtExecutableReference<?> executable = candidate.getExecutable(); CtPackageReference executablePackage = executable.getDeclaringType() .getPackage(); if (executablePackage == null || !executablePackage.getSimpleName().contains("junit")) { return false; } CtMethod<?> parentMethod = candidate.getParent(CtMethod.class); if (parentMethod == null) { return false; } createExecutionMethod(candidate); return super.isToBeProcessed(candidate); /* * boolean found = false; for (TestCase testCase : faillingTest) { if * (testCase.className().equals(parentClass.getQualifiedName())) { if * (testCase.testName().equals(parentMethod.getSimpleName())) { found = * true; break; } } } * * return found; */ }
failInvocation.get(0).getParent(CtTry.class) .getCatchers().contains(catches.get(0)) ) {
invocation.getParent(CtStatementList.class).insertBefore(statementTypeFilter, (CtStatement) clone); } else if (!(clone instanceof CtLiteral || clone instanceof CtVariableRead)) { CtTypeReference<?> typeOfParameter = clone.getType(); clone ); invocation.getParent(CtStatementList.class).insertBefore(statementTypeFilter, localVariable); } else if (clone instanceof CtVariableRead && !(clone instanceof CtFieldRead)) { final CtVariableReference variable = ((CtVariableRead) clone).getVariable(); final List<CtLocalVariable> assertedVariables = invocation.getParent(CtBlock.class).getElements( localVariable -> localVariable.getSimpleName().equals(variable.getSimpleName())
private void createExecutionMethod(CtInvocation<?> ctInvocation) { CtClass<?> parent = ctInvocation.getParent(CtClass.class); if (!parent.isTopLevel()) { return;
CtType<?> parentType = invocation.getParent(CtType.class); if (parentType != null && parentType.getQualifiedName() != null && parentType.getQualifiedName().equals(invocation.getExecutable().getDeclaringType().getQualifiedName())) { write("this");