本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}