当前位置: 首页>>代码示例>>Java>>正文


Java Statement类代码示例

本文整理汇总了Java中org.codehaus.groovy.ast.stmt.Statement的典型用法代码示例。如果您正苦于以下问题:Java Statement类的具体用法?Java Statement怎么用?Java Statement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Statement类属于org.codehaus.groovy.ast.stmt包,在下文中一共展示了Statement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractBareMethodCall

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:19,代码来源:AstUtils.java

示例2: mayHaveAnEffect

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:25,代码来源:AstUtils.java

示例3: call

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
@Override
public void call(SourceUnit source) throws CompilationFailedException {
    BlockStatement statementBlock = source.getAST().getStatementBlock();
    List<Statement> statements = statementBlock.getStatements();
    for (Statement statement : statements) {
        if (!AstUtils.mayHaveAnEffect(statement)) {
            continue;
        }
        ScriptBlock scriptBlock = AstUtils.detectScriptBlock(statement);
        if (scriptBlock != null && scriptBlock.getName().equals(ModelBlockTransformer.MODEL)) {
            continue;
        }
        imperativeStatementDetected = true;
        break;
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:17,代码来源:ImperativeStatementDetectingTransformer.java

示例4: transformClosureExpression

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
protected Expression transformClosureExpression(ClosureExpression ce) {
    boolean oldInClosure = inClosure;
    inClosure = true;
    Parameter[] paras = ce.getParameters();
    if (paras != null) {
        for (Parameter para : paras) {
            ClassNode t = para.getType();
            resolveOrFail(t, ce);
            visitAnnotations(para);
            if (para.hasInitialExpression()) {
                Object initialVal = para.getInitialExpression();
                if (initialVal instanceof Expression) {
                    para.setInitialExpression(transform((Expression) initialVal));
                }
            }
            visitAnnotations(para);
        }
    }
    Statement code = ce.getCode();
    if (code != null) {
        code.visit(this);
    }
    inClosure = oldInClosure;
    return ce;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:GradleResolveVisitor.java

示例5: call

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
@Override
public void call(final SourceUnit source) throws CompilationFailedException {
    // currently we only look in script code; could extend this to build script classes
    AstUtils.visitScriptCode(source, new ClassCodeVisitorSupport() {
        @Override
        protected SourceUnit getSourceUnit() {
            return source;
        }

        @Override
        protected void visitStatement(Statement statement) {
            if (statement.getStatementLabel() != null) {
                String message = String.format("Statement labels may not be used in build scripts.%nIn case you tried to configure a property named '%s', replace ':' with '=' or ' ', otherwise it will not have the desired effect.",
                        statement.getStatementLabel());
                addError(message, statement);
            }
        }
    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:20,代码来源:StatementLabelsScriptTransformer.java

示例6: transformationOfAnnotationOnLocalVariable

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的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

示例7: visitClosureExpression

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
@Override
public void visitClosureExpression(final ClosureExpression expression) {
    super.visitClosureExpression(expression);
    if (inBuilderMethod) {
        Statement oldCode = expression.getCode();
        BlockStatement block = oldCode instanceof BlockStatement?
                ((BlockStatement)oldCode):
                new BlockStatement(Arrays.asList(oldCode), new VariableScope());
        List<Statement> statements = block.getStatements();
        if (!statements.isEmpty()) {
            Statement first = statements.get(0);
            Statement last = statements.get(statements.size()-1);
            if (expression.getLineNumber()<first.getLineNumber()) {
                // there's a new line between { -> ... and the first statement
                statements.add(0,createNewLine(expression));
            }
            if (expression.getLastLineNumber()>last.getLastLineNumber()) {
                // there's a new line between { -> ... and the first statement
                statements.add(createNewLine(expression));
            }
        }
        expression.setCode(block);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:AutoNewLineTransformer.java

示例8: addInitialization

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
protected void addInitialization(final ClassNode node) {
    boolean addSwapInit = moveOptimizedConstantsInitialization(node);

    for (ConstructorNode cn : node.getDeclaredConstructors()) {
        addInitialization(node, cn);
    }

    if (addSwapInit) {
        BytecodeSequence seq = new BytecodeSequence(
                new BytecodeInstruction() {
                    @Override
                    public void visit(MethodVisitor mv) {
                        mv.visitMethodInsn(INVOKESTATIC, BytecodeHelper.getClassInternalName(node), SWAP_INIT, "()V", false);
                    }
                });

        List<Statement> swapCall = new ArrayList<Statement>(1);
        swapCall.add(seq);
        node.addStaticInitializerStatements(swapCall, true);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:Verifier.java

示例9: visitIfElseStatement

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
@Override
public IfStatement visitIfElseStatement(IfElseStatementContext ctx) {
    Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar());
    BooleanExpression booleanExpression =
            configureAST(
                    new BooleanExpression(conditionExpression), conditionExpression);

    Statement ifBlock =
            this.unpackStatement(
                    (Statement) this.visit(ctx.tb));
    Statement elseBlock =
            this.unpackStatement(
                    asBoolean(ctx.ELSE())
                            ? (Statement) this.visit(ctx.fb)
                            : EmptyStatement.INSTANCE);

    return configureAST(new IfStatement(booleanExpression, ifBlock, elseBlock), ctx);
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:AstBuilder.java

示例10: visitDoWhileStmtAlt

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
@Override
public DoWhileStatement visitDoWhileStmtAlt(DoWhileStmtAltContext ctx) {
    Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar());

    BooleanExpression booleanExpression =
            configureAST(
                    new BooleanExpression(conditionExpression),
                    conditionExpression
            );

    Statement loopBlock = this.unpackStatement((Statement) this.visit(ctx.statement()));

    return configureAST(
            new DoWhileStatement(booleanExpression, asBoolean(loopBlock) ? loopBlock : EmptyStatement.INSTANCE),
            ctx);
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:AstBuilder.java

示例11: addProperty

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
public PropertyNode addProperty(String name,
                                int modifiers,
                                ClassNode type,
                                Expression initialValueExpression,
                                Statement getterBlock,
                                Statement setterBlock) {
    for (PropertyNode pn : getProperties()) {
        if (pn.getName().equals(name)) {
            if (pn.getInitialExpression() == null && initialValueExpression != null)
                pn.getField().setInitialValueExpression(initialValueExpression);

            if (pn.getGetterBlock() == null && getterBlock != null)
                pn.setGetterBlock(getterBlock);

            if (pn.getSetterBlock() == null && setterBlock != null)
                pn.setSetterBlock(setterBlock);

            return pn;
        }
    }
    PropertyNode node =
            new PropertyNode(name, modifiers, type, redirect(), initialValueExpression, getterBlock, setterBlock);
    addProperty(node);
    return node;
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:ClassNode.java

示例12: createConstructorOrMethodNodeForClass

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
private MethodNode createConstructorOrMethodNodeForClass(MethodDeclarationContext ctx, ModifierManager modifierManager, String methodName, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code, ClassNode classNode) {
    MethodNode methodNode;
    String className = classNode.getNodeMetaData(CLASS_NAME);
    int modifiers = modifierManager.getClassMemberModifiersOpValue();

    boolean hasReturnType = asBoolean(ctx.returnType());
    boolean hasMethodBody = asBoolean(ctx.methodBody());

    if (!hasReturnType
            && hasMethodBody
            && methodName.equals(className)) { // constructor declaration

        methodNode = createConstructorNodeForClass(methodName, parameters, exceptions, code, classNode, modifiers);
    } else { // class memeber method declaration
        if (!hasReturnType && hasMethodBody && (0 == modifierManager.getModifierCount())) {
            throw createParsingFailedException("Invalid method declaration: " + methodName, ctx);
        }

        methodNode = createMethodNodeForClass(ctx, modifierManager, methodName, returnType, parameters, exceptions, code, classNode, modifiers);
    }

    modifierManager.attachAnnotations(methodNode);
    return methodNode;
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:AstBuilder.java

示例13: visitBlockStatement

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
@Override
public Statement visitBlockStatement(BlockStatementContext ctx) {
    if (asBoolean(ctx.localVariableDeclaration())) {
        return configureAST(this.visitLocalVariableDeclaration(ctx.localVariableDeclaration()), ctx);
    }

    if (asBoolean(ctx.statement())) {
        Object astNode = this.visit(ctx.statement()); //this.configureAST((Statement) this.visit(ctx.statement()), ctx);

        if (astNode instanceof MethodNode) {
            throw createParsingFailedException("Method definition not expected here", ctx);
        } else {
            return (Statement) astNode;
        }
    }

    throw createParsingFailedException("Unsupported block statement: " + ctx.getText(), ctx);
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:AstBuilder.java

示例14: positionStmtsAfterEnumInitStmts

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的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);
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:ClassNode.java

示例15: configureScriptClassNode

import org.codehaus.groovy.ast.stmt.Statement; //导入依赖的package包/类
/**
 * set the script source position
 */
private void configureScriptClassNode() {
    ClassNode scriptClassNode = moduleNode.getScriptClassDummy();

    if (!asBoolean(scriptClassNode)) {
        return;
    }

    List<Statement> statements = moduleNode.getStatementBlock().getStatements();
    if (!statements.isEmpty()) {
        Statement firstStatement = statements.get(0);
        Statement lastStatement = statements.get(statements.size() - 1);

        scriptClassNode.setSourcePosition(firstStatement);
        scriptClassNode.setLastColumnNumber(lastStatement.getLastColumnNumber());
        scriptClassNode.setLastLineNumber(lastStatement.getLastLineNumber());
    }

}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AstBuilder.java


注:本文中的org.codehaus.groovy.ast.stmt.Statement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。