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


Java VariableExpression.setAccessedVariable方法代码示例

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


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

示例1: correctAccessedVariable

import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static void correctAccessedVariable(final InnerClassNode closureClass, ClosureExpression ce) {
    CodeVisitorSupport visitor = new CodeVisitorSupport() {
        @Override
        public void visitVariableExpression(VariableExpression expression) {
            Variable v = expression.getAccessedVariable(); 
            if (v==null) return;
            if (!(v instanceof FieldNode)) return;
            String name = expression.getName();
            FieldNode fn = closureClass.getDeclaredField(name);
            if (fn != null) { // only overwrite if we find something more specific
                expression.setAccessedVariable(fn);
            }
        }  
    };
    visitor.visitClosureExpression(ce);
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ClosureWriter.java

示例2: transform

import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
@Override
public Expression transform(Expression expr) {
    if (expr == null) return null;
    if (expr instanceof DeclarationExpression) {
        DeclarationExpression de = (DeclarationExpression) expr;
        if (de.getLeftExpression() == candidate.getLeftExpression()) {
            if (insideScriptBody) {
                // TODO make EmptyExpression work
                // partially works but not if only thing in script
                // return EmptyExpression.INSTANCE;
                return new ConstantExpression(null);
            }
            addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script body.", expr);
            return expr;
        }
    } else if (insideScriptBody && expr instanceof VariableExpression && currentClosure != null) {
        VariableExpression ve = (VariableExpression) expr;
        if (ve.getName().equals(variableName)) {
            // we may only check the variable name because the Groovy compiler
            // already fails if a variable with the same name already exists in the scope.
            // this means that a closure cannot shadow a class variable
            ve.setAccessedVariable(fieldNode);
            final VariableScope variableScope = currentClosure.getVariableScope();
            final Iterator<Variable> iterator = variableScope.getReferencedLocalVariablesIterator();
            while (iterator.hasNext()) {
                Variable next = iterator.next();
                if (next.getName().equals(variableName)) iterator.remove();
            }
            variableScope.putReferencedClassVariable(fieldNode);
            return ve;
        }
    }
    return expr.transformExpression(this);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:35,代码来源:VolatileFieldASTTransformation.java

示例3: adjustToClassVar

import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private void adjustToClassVar(VariableExpression expr) {
    // we only need to check the variable name because the Groovy compiler
    // already fails if a variable with the same name already exists in the scope.
    // this means that a closure cannot shadow a class variable
    expr.setAccessedVariable(fieldNode);
    final VariableScope variableScope = currentClosure.getVariableScope();
    final Iterator<Variable> iterator = variableScope.getReferencedLocalVariablesIterator();
    while (iterator.hasNext()) {
        Variable next = iterator.next();
        if (next.getName().equals(variableName)) iterator.remove();
    }
    variableScope.putReferencedClassVariable(fieldNode);
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:FieldASTTransformation.java

示例4: doAddConstructor

import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static void doAddConstructor(final ClassNode cNode, final ConstructorNode constructorNode) {
    cNode.addConstructor(constructorNode);
    // GROOVY-5814: Immutable is not compatible with @CompileStatic
    Parameter argsParam = null;
    for (Parameter p : constructorNode.getParameters()) {
        if ("args".equals(p.getName())) {
            argsParam = p;
            break;
        }
    }
    if (argsParam!=null) {
        final Parameter arg = argsParam;
        ClassCodeVisitorSupport variableExpressionFix = new ClassCodeVisitorSupport() {
            @Override
            protected SourceUnit getSourceUnit() {
                return cNode.getModule().getContext();
            }

            @Override
            public void visitVariableExpression(final VariableExpression expression) {
                super.visitVariableExpression(expression);
                if ("args".equals(expression.getName())) {
                    expression.setAccessedVariable(arg);
                }
            }
        };
        variableExpressionFix.visitConstructor(constructorNode);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:ImmutableASTTransformation.java

示例5: visitVariableExpression

import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
public void visitVariableExpression(VariableExpression expression) {
    String name = expression.getName();
    Variable v = checkVariableNameForDeclaration(name, expression);
    if (v == null) return;
    expression.setAccessedVariable(v);
    checkVariableContextAccess(v, expression);
}
 
开发者ID:apache,项目名称:groovy,代码行数:8,代码来源:VariableScopeVisitor.java

示例6: declare

import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private void declare(VariableExpression vex) {
    vex.setInStaticContext(currentScope.isInStaticContext());
    declare(vex, vex);
    vex.setAccessedVariable(vex);
}
 
开发者ID:apache,项目名称:groovy,代码行数:6,代码来源:VariableScopeVisitor.java


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