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


Java VariableExpression类代码示例

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


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

示例1: changeBaseScriptTypeFromDeclaration

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
private void changeBaseScriptTypeFromDeclaration(final SourceUnit source, final DeclarationExpression de, final AnnotationNode node) {
    if (de.isMultipleAssignmentDeclaration()) {
        addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
        return;
    }

    if (!(de.getRightExpression() instanceof EmptyExpression)) {
        addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
        return;
    }
    Expression value = node.getMember("value");
    if (value != null) {
        addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
        return;
    }

    ClassNode cNode = de.getDeclaringClass();
    ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
    de.setRightExpression(new VariableExpression("this"));

    changeBaseScriptType(source, de, cNode, baseScriptType, node);
}
 
开发者ID:remkop,项目名称:picocli,代码行数:23,代码来源:PicocliScriptASTTransformation.java

示例2: handleUnresolvedVariableExpression

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
@Override
public boolean handleUnresolvedVariableExpression(final VariableExpression vexp) {

    if ("resource".equals(vexp.getName())) {
        makeDynamic(vexp, ClassHelper.makeCached(ResourceHandler.class));
        setHandled(true);
        return true;
    }
    if ("subject".equals(vexp.getName())) {
        makeDynamic(vexp, ClassHelper.makeCached(SubjectHandler.class));
        setHandled(true);
        return true;
    }
    if ("match".equals(vexp.getName())) {
        makeDynamic(vexp, ClassHelper.makeCached(AttributeMatcher.class));
        setHandled(true);
        return true;
    }

    return false;
}
 
开发者ID:eclipse,项目名称:keti,代码行数:22,代码来源:GroovySecureExtension.java

示例3: transformationOfAnnotationOnLocalVariable

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

示例4: getArgsModifiers

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
public static YMap<String, YSet<String>> getArgsModifiers(MethodNode methodNode, YMap<String, YSet<String>> result) {

        for (Parameter parameter : methodNode.getParameters()) if (!isPrimitive(translateType(parameter.getText()))) {

            YList<Boolean> rewritten = al(false);
            CodeVisitorSupport detectRewrittenVisitor = new CodeVisitorSupport() {

                @Override
                public void visitBinaryExpression(BinaryExpression expression) {
                    if (expression.getOperation().getText().equals("=")) {
                        Expression left = expression.getLeftExpression();
                        if (left instanceof VariableExpression) {
                            if (((VariableExpression) left).getName().equals(parameter.getName())) {
                                rewritten.set(0, true);
                            }
                        }
                    }
                    super.visitBinaryExpression(expression);
                }
            };
            detectRewrittenVisitor.visitBlockStatement((BlockStatement) methodNode.getCode());
            if (rewritten.get(0)) System.out.println(parameter.getName() + " rewritten!");
        }
        return result;
    }
 
开发者ID:kravchik,项目名称:senjin,代码行数:26,代码来源:Visitors.java

示例5: createConstructor

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

示例6: createCatchBlockForOuterNewTryCatchStatement

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

示例7: visitVariableDeclarator

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
@Override
public DeclarationExpression visitVariableDeclarator(VariableDeclaratorContext ctx) {
    ClassNode variableType = ctx.getNodeMetaData(VARIABLE_DECLARATION_VARIABLE_TYPE);
    Objects.requireNonNull(variableType, "variableType should not be null");

    org.codehaus.groovy.syntax.Token token;
    if (asBoolean(ctx.ASSIGN())) {
        token = createGroovyTokenByType(ctx.ASSIGN().getSymbol(), Types.ASSIGN);
    } else {
        token = new org.codehaus.groovy.syntax.Token(Types.ASSIGN, ASSIGN_STR, ctx.start.getLine(), 1);
    }

    return configureAST(
            new DeclarationExpression(
                    configureAST(
                            new VariableExpression(
                                    this.visitVariableDeclaratorId(ctx.variableDeclaratorId()).getName(),
                                    variableType
                            ),
                            ctx.variableDeclaratorId()),
                    token,
                    this.visitVariableInitializer(ctx.variableInitializer())),
            ctx);
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:AstBuilder.java

示例8: visitMapEntryLabel

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
@Override
public Expression visitMapEntryLabel(MapEntryLabelContext ctx) {
    if (asBoolean(ctx.keywords())) {
        return configureAST(this.visitKeywords(ctx.keywords()), ctx);
    } else if (asBoolean(ctx.primary())) {
        Expression expression = (Expression) this.visit(ctx.primary());

        // if the key is variable and not inside parentheses, convert it to a constant, e.g. [a:1, b:2]
        if (expression instanceof VariableExpression && !isInsideParentheses(expression)) {
            expression =
                    configureAST(
                            new ConstantExpression(((VariableExpression) expression).getName()),
                            expression);
        }

        return configureAST(expression, ctx);
    }

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

示例9: transformBinaryExpression

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
protected Expression transformBinaryExpression(BinaryExpression be) {
    int type = be.getOperation().getType();
    boolean oldInLeftExpression;
    Expression right = transform(be.getRightExpression());
    be.setRightExpression(right);
    Expression left;
    if (type == Types.EQUAL && be.getLeftExpression() instanceof VariableExpression) {
        oldInLeftExpression = inLeftExpression;
        inLeftExpression = true;
        left = transform(be.getLeftExpression());
        inLeftExpression = oldInLeftExpression;
        if (left instanceof StaticMethodCallExpression) {
            StaticMethodCallExpression smce = (StaticMethodCallExpression) left;
            StaticMethodCallExpression result = new StaticMethodCallExpression(smce.getOwnerType(), smce.getMethod(), right);
            setSourcePosition(result, be);
            return result;
        }
    } else {
        left = transform(be.getLeftExpression());
    }
    be.setLeftExpression(left);
    return be;
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:StaticImportVisitor.java

示例10: transform

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
public Expression transform(Expression exp) {
    if (exp == null) return null;
    Expression ret = null;
    if (exp instanceof VariableExpression) {
        ret = transformVariableExpression((VariableExpression) exp);
    } else if (exp.getClass() == PropertyExpression.class) {
        ret = transformPropertyExpression((PropertyExpression) exp);
    } else if (exp instanceof DeclarationExpression) {
        ret = transformDeclarationExpression((DeclarationExpression) exp);
    } else if (exp instanceof BinaryExpression) {
        ret = transformBinaryExpression((BinaryExpression) exp);
    } else if (exp instanceof MethodCallExpression) {
        ret = transformMethodCallExpression((MethodCallExpression) exp);
    } else if (exp instanceof ClosureExpression) {
        ret = transformClosureExpression((ClosureExpression) exp);
    } else if (exp instanceof ConstructorCallExpression) {
        ret = transformConstructorCallExpression((ConstructorCallExpression) exp);
    } else if (exp instanceof AnnotationConstantExpression) {
        ret = transformAnnotationConstantExpression((AnnotationConstantExpression) exp);
    } else {
        resolveOrFail(exp.getType(), exp);
        ret = exp.transformExpression(this);
    }
    if (ret!=null && ret!=exp) ret.setSourcePosition(exp);
    return ret;
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:ResolveVisitor.java

示例11: setMethodDispatcherCode

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
protected static void setMethodDispatcherCode(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 ReturnStatement(
                    new MethodCallExpression(
                            thiz,
                            new GStringExpression("$name", gStringStrings, gStringValues),
                            new ArgumentListExpression(
                                    new SpreadExpression(new VariableExpression(parameters[1]))
                            )
                    )
            )
    );
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:InnerClassVisitorHelper.java

示例12: makeMapTypedArgsTransformer

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
private static ClassCodeExpressionTransformer makeMapTypedArgsTransformer() {
    return new ClassCodeExpressionTransformer() {
        @Override
        public Expression transform(Expression exp) {
            if (exp instanceof ClosureExpression) {
                ClosureExpression ce = (ClosureExpression) exp;
                ce.getCode().visit(this);
            } else if (exp instanceof VariableExpression) {
                VariableExpression ve = (VariableExpression) exp;
                if (ve.getName().equals("args") && ve.getAccessedVariable() instanceof DynamicVariable) {
                    VariableExpression newVe = new VariableExpression(new Parameter(MAP_TYPE, "args"));
                    newVe.setSourcePosition(ve);
                    return newVe;
                }
            }
            return exp.transformExpression(this);
        }

        @Override
        protected SourceUnit getSourceUnit() {
            return null;
        }
    };
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:MapConstructorASTTransformation.java

示例13: addDoubleCheckedLockingBody

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
private static void addDoubleCheckedLockingBody(BlockStatement body, FieldNode fieldNode, Expression initExpr) {
    final Expression fieldExpr = varX(fieldNode);
    final VariableExpression localVar = varX(fieldNode.getName() + "_local");
    body.addStatement(declS(localVar, fieldExpr));
    body.addStatement(ifElseS(
            notNullX(localVar),
            returnS(localVar),
            new SynchronizedStatement(
                    syncTarget(fieldNode),
                    ifElseS(
                            notNullX(fieldExpr),
                            returnS(fieldExpr),
                            returnS(assignX(fieldExpr, initExpr))
                    )
            )
    ));
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:LazyASTTransformation.java

示例14: tryVariableExpressionAsProperty

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
private boolean tryVariableExpressionAsProperty(final VariableExpression vexp, final String dynName) {
    VariableExpression implicitThis = varX("this");
    PropertyExpression pe = new PropertyExpression(implicitThis, dynName);
    pe.setImplicitThis(true);
    if (visitPropertyExpressionSilent(pe, vexp)) {
        ClassNode previousIt = vexp.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
        vexp.copyNodeMetaData(implicitThis);
        vexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, previousIt);
        storeType(vexp, getType(pe));
        Object val = pe.getNodeMetaData(StaticTypesMarker.READONLY_PROPERTY);
        if (val!=null) vexp.putNodeMetaData(StaticTypesMarker.READONLY_PROPERTY,val);
        val = pe.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
        if (val!=null) vexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER,val);
        return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:StaticTypeCheckingVisitor.java

示例15: makeSingleArgumentCall

import org.codehaus.groovy.ast.expr.VariableExpression; //导入依赖的package包/类
@Override
public void makeSingleArgumentCall(final Expression receiver, final String message, final Expression arguments, boolean safe) {
    TypeChooser typeChooser = controller.getTypeChooser();
    ClassNode classNode = controller.getClassNode();
    ClassNode rType = typeChooser.resolveType(receiver, classNode);
    ClassNode aType = typeChooser.resolveType(arguments, classNode);
    if (trySubscript(receiver, message, arguments, rType, aType, safe)) {
        return;
    }
    // now try with flow type instead of declaration type
    rType = receiver.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
    if (receiver instanceof VariableExpression && rType == null) {
        // TODO: can STCV be made smarter to avoid this check?
        VariableExpression ve = (VariableExpression) ((VariableExpression)receiver).getAccessedVariable();
        rType = ve.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
    }
    if (rType!=null && trySubscript(receiver, message, arguments, rType, aType, safe)) {
        return;
    }
    // todo: more cases
    throw new GroovyBugError(
            "At line " + receiver.getLineNumber() + " column " + receiver.getColumnNumber() + "\n" +
            "On receiver: " + receiver.getText() + " with message: " + message + " and arguments: " + arguments.getText() + "\n" +
            "This method should not have been called. Please try to create a simple example reproducing\n" +
            "this error and file a bug report at https://issues.apache.org/jira/browse/GROOVY");
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:StaticTypesCallSiteWriter.java


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