|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.cli.compiler;
|
|
|
|
package org.springframework.boot.cli.compiler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
@ -25,6 +26,14 @@ import org.codehaus.groovy.ast.AnnotationNode;
|
|
|
|
import org.codehaus.groovy.ast.ClassNode;
|
|
|
|
import org.codehaus.groovy.ast.ClassNode;
|
|
|
|
import org.codehaus.groovy.ast.FieldNode;
|
|
|
|
import org.codehaus.groovy.ast.FieldNode;
|
|
|
|
import org.codehaus.groovy.ast.MethodNode;
|
|
|
|
import org.codehaus.groovy.ast.MethodNode;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.expr.ArgumentListExpression;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.expr.ClosureExpression;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.expr.ConstantExpression;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.expr.Expression;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.expr.MethodCallExpression;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.stmt.BlockStatement;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
|
|
|
|
|
|
|
|
import org.codehaus.groovy.ast.stmt.Statement;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* General purpose AST utilities.
|
|
|
|
* General purpose AST utilities.
|
|
|
@ -101,4 +110,52 @@ public abstract class AstUtils {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean hasAtLeastOneInterface(ClassNode classNode, String... types) {
|
|
|
|
|
|
|
|
Set<String> typesSet = new HashSet<String>(Arrays.asList(types));
|
|
|
|
|
|
|
|
for (ClassNode inter : classNode.getInterfaces()) {
|
|
|
|
|
|
|
|
if (typesSet.contains(inter.getName())) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Extract a top-level <code>name</code> closure from inside this block if there is
|
|
|
|
|
|
|
|
* one. Removes it from the block at the same time.
|
|
|
|
|
|
|
|
* @param block a block statement (class definition)
|
|
|
|
|
|
|
|
* @return a beans Closure if one can be found, null otherwise
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static ClosureExpression getClosure(BlockStatement block, String name,
|
|
|
|
|
|
|
|
boolean remove) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Statement statement : new ArrayList<Statement>(block.getStatements())) {
|
|
|
|
|
|
|
|
if (statement instanceof ExpressionStatement) {
|
|
|
|
|
|
|
|
Expression expression = ((ExpressionStatement) statement).getExpression();
|
|
|
|
|
|
|
|
if (expression instanceof MethodCallExpression) {
|
|
|
|
|
|
|
|
MethodCallExpression call = (MethodCallExpression) expression;
|
|
|
|
|
|
|
|
Expression methodCall = call.getMethod();
|
|
|
|
|
|
|
|
if (methodCall instanceof ConstantExpression) {
|
|
|
|
|
|
|
|
ConstantExpression method = (ConstantExpression) methodCall;
|
|
|
|
|
|
|
|
if (name.equals(method.getValue())) {
|
|
|
|
|
|
|
|
ArgumentListExpression arguments = (ArgumentListExpression) call
|
|
|
|
|
|
|
|
.getArguments();
|
|
|
|
|
|
|
|
if (remove) {
|
|
|
|
|
|
|
|
block.getStatements().remove(statement);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ClosureExpression closure = (ClosureExpression) arguments
|
|
|
|
|
|
|
|
.getExpression(0);
|
|
|
|
|
|
|
|
return closure;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ClosureExpression getClosure(BlockStatement block, String name) {
|
|
|
|
|
|
|
|
return getClosure(block, name, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|