本文整理汇总了Java中org.codehaus.groovy.ast.stmt.ExpressionStatement类的典型用法代码示例。如果您正苦于以下问题:Java ExpressionStatement类的具体用法?Java ExpressionStatement怎么用?Java ExpressionStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionStatement类属于org.codehaus.groovy.ast.stmt包,在下文中一共展示了ExpressionStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractBareMethodCall
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
@Nullable
public static MethodCallExpression extractBareMethodCall(Statement statement) {
if (!(statement instanceof ExpressionStatement)) {
return null;
}
ExpressionStatement expressionStatement = (ExpressionStatement) statement;
if (!(expressionStatement.getExpression() instanceof MethodCallExpression)) {
return null;
}
MethodCallExpression methodCall = (MethodCallExpression) expressionStatement.getExpression();
if (!targetIsThis(methodCall)) {
return null;
}
return methodCall;
}
示例2: mayHaveAnEffect
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
/**
* Returns true if the the given statement may have some effect as part of a script body.
* Returns false when the given statement may be ignored, provided all other statements in the script body may also be ignored.
*/
public static boolean mayHaveAnEffect(Statement statement) {
if (statement instanceof ReturnStatement) {
ReturnStatement returnStatement = (ReturnStatement) statement;
if (returnStatement.getExpression() instanceof ConstantExpression) {
return false;
}
} else if (statement instanceof ExpressionStatement) {
ExpressionStatement expressionStatement = (ExpressionStatement) statement;
if (expressionStatement.getExpression() instanceof ConstantExpression) {
return false;
}
if (expressionStatement.getExpression() instanceof DeclarationExpression) {
DeclarationExpression declarationExpression = (DeclarationExpression) expressionStatement.getExpression();
if (declarationExpression.getRightExpression() instanceof EmptyExpression || declarationExpression.getRightExpression() instanceof ConstantExpression) {
return false;
}
}
}
return true;
}
示例3: visitExpressionStatement
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
@Override
public void visitExpressionStatement(ExpressionStatement stat) {
if (nestingDepth == 0 && stat.getExpression() instanceof MethodCallExpression) {
MethodCallExpression call = (MethodCallExpression) stat.getExpression();
if (call.isImplicitThis() && call.getArguments() instanceof ArgumentListExpression) {
ArgumentListExpression arguments = (ArgumentListExpression) call.getArguments();
if (!arguments.getExpressions().isEmpty()) {
Expression lastArg = arguments.getExpression(arguments.getExpressions().size() - 1);
if (lastArg instanceof ClosureExpression) {
// This is a potential nested rule.
// Visit method parameters
for (int i = 0; i < arguments.getExpressions().size() - 1; i++) {
arguments.getExpressions().set(i, replaceExpr(arguments.getExpression(i)));
}
// Transform closure
ClosureExpression closureExpression = (ClosureExpression) lastArg;
visitRuleClosure(closureExpression, call, displayName(call));
Expression replaced = new StaticMethodCallExpression(RULE_FACTORY, "decorate", new ArgumentListExpression(new VariableExpression(RULE_FACTORY_FIELD_NAME), closureExpression));
arguments.getExpressions().set(arguments.getExpressions().size() - 1, replaced);
return;
}
}
}
}
super.visitExpressionStatement(stat);
}
示例4: getClosure
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
/**
* Extract a top-level {@code name} closure from inside this block if there is one,
* optionally removing it from the block at the same time.
* @param block a block statement (class definition)
* @param name the name to look for
* @param remove whether or not the extracted closure should be removed
* @return a beans Closure if one can be found, null otherwise
*/
public static ClosureExpression getClosure(BlockStatement block, String name,
boolean remove) {
for (ExpressionStatement statement : getExpressionStatements(block)) {
Expression expression = statement.getExpression();
if (expression instanceof MethodCallExpression) {
ClosureExpression closure = getClosure(name,
(MethodCallExpression) expression);
if (closure != null) {
if (remove) {
block.getStatements().remove(statement);
}
return closure;
}
}
}
return null;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:AstUtils.java
示例5: transformationOfAnnotationOnLocalVariable
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
@Test
public void transformationOfAnnotationOnLocalVariable() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
DeclarationExpression declarationExpression = new DeclarationExpression(
new VariableExpression("test"), null, new ConstantExpression("test"));
declarationExpression.addAnnotation(this.grabAnnotation);
BlockStatement code = new BlockStatement(
Arrays.asList((Statement) new ExpressionStatement(declarationExpression)),
new VariableScope());
MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
new Parameter[0], new ClassNode[0], code);
classNode.addMethod(methodNode);
assertGrabAnnotationHasBeenTransformed();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:ResolveDependencyCoordinatesTransformationTests.java
示例6: createConstructor
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
private void createConstructor(final ClassNode classNode) {
Parameter[] params = new Parameter[]{
new Parameter(MarkupTemplateEngine.MARKUPTEMPLATEENGINE_CLASSNODE, "engine"),
new Parameter(ClassHelper.MAP_TYPE.getPlainNodeReference(), "model"),
new Parameter(ClassHelper.MAP_TYPE.getPlainNodeReference(), "modelTypes"),
new Parameter(TEMPLATECONFIG_CLASSNODE, "tplConfig")
};
List<Expression> vars = new LinkedList<Expression>();
for (Parameter param : params) {
vars.add(new VariableExpression(param));
}
ExpressionStatement body = new ExpressionStatement(
new ConstructorCallExpression(ClassNode.SUPER, new ArgumentListExpression(vars)));
ConstructorNode ctor = new ConstructorNode(Opcodes.ACC_PUBLIC, params, ClassNode.EMPTY_ARRAY, body);
classNode.addConstructor(ctor);
}
示例7: makeVariableDeclarationFinal
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
private ExpressionStatement makeVariableDeclarationFinal(ExpressionStatement variableDeclaration) {
if (!asBoolean(variableDeclaration)) {
return variableDeclaration;
}
if (!(variableDeclaration.getExpression() instanceof DeclarationExpression)) {
throw new IllegalArgumentException("variableDeclaration is not a declaration statement");
}
DeclarationExpression declarationExpression = (DeclarationExpression) variableDeclaration.getExpression();
if (!(declarationExpression.getLeftExpression() instanceof VariableExpression)) {
throw astBuilder.createParsingFailedException("The expression statement is not a variable delcaration statement", variableDeclaration);
}
VariableExpression variableExpression = (VariableExpression) declarationExpression.getLeftExpression();
variableExpression.setModifiers(variableExpression.getModifiers() | Opcodes.ACC_FINAL);
return variableDeclaration;
}
示例8: createCatchBlockForOuterNewTryCatchStatement
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
private CatchStatement createCatchBlockForOuterNewTryCatchStatement(String primaryExcName) {
// { ... }
BlockStatement blockStatement = new BlockStatement();
String tExcName = this.genTExcName();
// #primaryExc = #t;
ExpressionStatement primaryExcAssignStatement =
new ExpressionStatement(
new BinaryExpression(
new VariableExpression(primaryExcName),
org.codehaus.groovy.syntax.Token.newSymbol(Types.ASSIGN, -1, -1),
new VariableExpression(tExcName)));
astBuilder.appendStatementsToBlockStatement(blockStatement, primaryExcAssignStatement);
// throw #t;
ThrowStatement throwTExcStatement = new ThrowStatement(new VariableExpression(tExcName));
astBuilder.appendStatementsToBlockStatement(blockStatement, throwTExcStatement);
// Throwable #t
Parameter tExcParameter = new Parameter(ClassHelper.make(Throwable.class), tExcName);
return new CatchStatement(tExcParameter, blockStatement);
}
示例9: checkThisAndSuperConstructorCall
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
private ConstructorCallExpression checkThisAndSuperConstructorCall(Statement statement) {
if (!(statement instanceof BlockStatement)) { // method code must be a BlockStatement
return null;
}
BlockStatement blockStatement = (BlockStatement) statement;
List<Statement> statementList = blockStatement.getStatements();
for (int i = 0, n = statementList.size(); i < n; i++) {
Statement s = statementList.get(i);
if (s instanceof ExpressionStatement) {
Expression expression = ((ExpressionStatement) s).getExpression();
if ((expression instanceof ConstructorCallExpression) && 0 != i) {
return (ConstructorCallExpression) expression;
}
}
}
return null;
}
示例10: createMethodNodeForClass
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
private MethodNode createMethodNodeForClass(MethodDeclarationContext ctx, ModifierManager modifierManager, String methodName, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code, ClassNode classNode, int modifiers) {
MethodNode methodNode;
if (asBoolean(ctx.elementValue())) { // the code of annotation method
code = configureAST(
new ExpressionStatement(
this.visitElementValue(ctx.elementValue())),
ctx.elementValue());
}
modifiers |= !modifierManager.contains(STATIC) && (classNode.isInterface() || (isTrue(classNode, IS_INTERFACE_WITH_DEFAULT_METHODS) && !modifierManager.contains(DEFAULT))) ? Opcodes.ACC_ABSTRACT : 0;
checkWhetherMethodNodeWithSameSignatureExists(classNode, methodName, parameters, ctx);
methodNode = classNode.addMethod(methodName, modifiers, returnType, parameters, exceptions, code);
methodNode.setAnnotationDefault(asBoolean(ctx.elementValue()));
return methodNode;
}
示例11: visitGstringValue
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
@Override
public Expression visitGstringValue(GstringValueContext ctx) {
if (asBoolean(ctx.gstringPath())) {
return configureAST(this.visitGstringPath(ctx.gstringPath()), ctx);
}
if (asBoolean(ctx.LBRACE())) {
if (asBoolean(ctx.statementExpression())) {
return configureAST(((ExpressionStatement) this.visit(ctx.statementExpression())).getExpression(), ctx.statementExpression());
} else { // e.g. "${}"
return configureAST(new ConstantExpression(null), ctx);
}
}
if (asBoolean(ctx.closure())) {
return configureAST(this.visitClosure(ctx.closure()), ctx);
}
throw createParsingFailedException("Unsupported gstring value: " + ctx.getText(), ctx);
}
示例12: getDeclarationStatements
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
public List<ExpressionStatement> getDeclarationStatements() {
List<String> declarationListStatementLabels = this.getStatementLabels();
this.declarationStatements.forEach(e -> {
if (null != declarationListStatementLabels) {
// clear existing statement labels before setting labels
if (null != e.getStatementLabels()) {
e.getStatementLabels().clear();
}
declarationListStatementLabels.forEach(e::addStatementLabel);
}
});
return this.declarationStatements;
}
示例13: positionStmtsAfterEnumInitStmts
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
public void positionStmtsAfterEnumInitStmts(List<Statement> staticFieldStatements) {
MethodNode method = getOrAddStaticConstructorNode();
Statement statement = method.getCode();
if (statement instanceof BlockStatement) {
BlockStatement block = (BlockStatement) statement;
// add given statements for explicitly declared static fields just after enum-special fields
// are found - the $VALUES binary expression marks the end of such fields.
List<Statement> blockStatements = block.getStatements();
ListIterator<Statement> litr = blockStatements.listIterator();
while (litr.hasNext()) {
Statement stmt = litr.next();
if (stmt instanceof ExpressionStatement &&
((ExpressionStatement) stmt).getExpression() instanceof BinaryExpression) {
BinaryExpression bExp = (BinaryExpression) ((ExpressionStatement) stmt).getExpression();
if (bExp.getLeftExpression() instanceof FieldExpression) {
FieldExpression fExp = (FieldExpression) bExp.getLeftExpression();
if (fExp.getFieldName().equals("$VALUES")) {
for (Statement tmpStmt : staticFieldStatements) {
litr.add(tmpStmt);
}
}
}
}
}
}
}
示例14: copyStatementsWithSuperAdjustment
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
public static boolean copyStatementsWithSuperAdjustment(ClosureExpression pre, BlockStatement body) {
Statement preCode = pre.getCode();
boolean changed = false;
if (preCode instanceof BlockStatement) {
BlockStatement block = (BlockStatement) preCode;
List<Statement> statements = block.getStatements();
for (int i = 0; i < statements.size(); i++) {
Statement statement = statements.get(i);
// adjust the first statement if it's a super call
if (i == 0 && statement instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) statement;
Expression preExp = es.getExpression();
if (preExp instanceof MethodCallExpression) {
MethodCallExpression mce = (MethodCallExpression) preExp;
String name = mce.getMethodAsString();
if ("super".equals(name)) {
es.setExpression(new ConstructorCallExpression(ClassNode.SUPER, mce.getArguments()));
changed = true;
}
}
}
body.addStatement(statement);
}
}
return changed;
}
示例15: setPropertySetterDispatcher
import org.codehaus.groovy.ast.stmt.ExpressionStatement; //导入依赖的package包/类
protected static void setPropertySetterDispatcher(BlockStatement block, Expression thiz, Parameter[] parameters) {
List<ConstantExpression> gStringStrings = new ArrayList<ConstantExpression>();
gStringStrings.add(new ConstantExpression(""));
gStringStrings.add(new ConstantExpression(""));
List<Expression> gStringValues = new ArrayList<Expression>();
gStringValues.add(new VariableExpression(parameters[0]));
block.addStatement(
new ExpressionStatement(
new BinaryExpression(
new PropertyExpression(
thiz,
new GStringExpression("$name", gStringStrings, gStringValues)
),
Token.newSymbol(Types.ASSIGN, -1, -1),
new VariableExpression(parameters[1])
)
)
);
}