
com.atlassian.clover.instr.java.RewriteLambdaToBlockMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clover Show documentation
Show all versions of clover Show documentation
Clover is an award winning code coverage and testing tool for Java and Groovy.
It integrates easily with Maven, Ant, Grails, Eclipse and IntelliJ IDEA
as well as with continuous integration servers such as Bamboo, Jenkins or Hudson.
Note: before Clover 4.0 this artifact was named com.cenqua.clover:clover.
The newest version!
package com.atlassian.clover.instr.java;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.Set;
public class RewriteLambdaToBlockMatcher {
private static final Set TO_REWRITE_CALLEE_METHODS = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(
"min",
"map",
"generate",
"iterate",
"reduce",
"max",
"concat",
"peek",
"filter",
"flatMap",
"collect",
"transform",
"compose",
"from",
"transformValues",
"thenApply",
"thenCompose"
)));
public static boolean shouldRewriteAsBlock(Deque> currentStack) {
ArrayDeque> stack = new ArrayDeque<>(currentStack);
return !stack.isEmpty() && isCalleeMethodOnStack(stack);
}
private static boolean isCalleeMethodOnStack(ArrayDeque> stack) {
stack.pop(); // additional empty stack since Lambda is expression and creates new stack
if (stack.isEmpty()) {
return false; // it's lambda expression like Runnable run = () -> sth();
}
final Deque lambdaCallStack = stack.pop();
if (lambdaCallStack.isEmpty()) {
return false; // it's lambda expression like Callable run = () -> () -> sth();
}
final String callee = lambdaCallStack.pop();
return TO_REWRITE_CALLEE_METHODS.contains(callee);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy