本文整理汇总了Java中org.codehaus.groovy.ast.expr.VariableExpression.getAccessedVariable方法的典型用法代码示例。如果您正苦于以下问题:Java VariableExpression.getAccessedVariable方法的具体用法?Java VariableExpression.getAccessedVariable怎么用?Java VariableExpression.getAccessedVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.VariableExpression
的用法示例。
在下文中一共展示了VariableExpression.getAccessedVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
};
}
示例2: saveVariableExpressionMetadata
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
protected void saveVariableExpressionMetadata(final Set<VariableExpression> closureSharedExpressions, final Map<VariableExpression, ListHashMap> typesBeforeVisit) {
for (VariableExpression ve : closureSharedExpressions) {
// GROOVY-6921: We must force a call to getType in order to update closure shared variable whose
// types are inferred thanks to closure parameter type inference
getType(ve);
ListHashMap<StaticTypesMarker, Object> metadata = new ListHashMap<StaticTypesMarker, Object>();
for (StaticTypesMarker marker : StaticTypesMarker.values()) {
Object value = ve.getNodeMetaData(marker);
if (value != null) {
metadata.put(marker, value);
}
}
typesBeforeVisit.put(ve, metadata);
Variable accessedVariable = ve.getAccessedVariable();
if (accessedVariable != ve && accessedVariable instanceof VariableExpression) {
saveVariableExpressionMetadata(Collections.singleton((VariableExpression) accessedVariable), typesBeforeVisit);
}
}
}
示例3: visitVariableExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
@Override
public void visitVariableExpression(final VariableExpression expression) {
super.visitVariableExpression(expression);
Map<Variable, VariableState> state = getState();
Variable key = expression.getAccessedVariable();
if (key == null) {
fixVar(expression);
key = expression.getAccessedVariable();
}
if (key != null && !key.isClosureSharedVariable() && callback != null) {
VariableState variableState = state.get(key);
if (inAssignment && variableState == VariableState.is_uninitialized) {
callback.variableNotAlwaysInitialized(expression);
}
}
}
示例4: 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);
}
示例5: resolveType
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
public ClassNode resolveType(final Expression exp, final ClassNode current) {
if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type;
OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
ClassNode type = null;
if (meta != null) type = meta.type;
if (type != null) return type;
if (exp instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) exp;
if (ve.isClosureSharedVariable()) return ve.getType();
type = ve.getOriginType();
if (ve.getAccessedVariable() instanceof FieldNode) {
FieldNode fn = (FieldNode) ve.getAccessedVariable();
if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType();
}
} else if (exp instanceof Variable) {
Variable v = (Variable) exp;
type = v.getOriginType();
} else {
type = exp.getType();
}
return type.redirect();
}
示例6: doAssignmentToLocalVariable
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private boolean doAssignmentToLocalVariable(String method, BinaryExpression binExp) {
Expression left = binExp.getLeftExpression();
if (left instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) left;
Variable v = ve.getAccessedVariable();
if (v instanceof DynamicVariable) return false;
if (v instanceof PropertyExpression) return false;
/* field and declaration we don't return false */
} else {
return false;
}
evaluateBinaryExpression(method, binExp);
getController().getOperandStack().dup();
getController().getCompileStack().pushLHS(true);
binExp.getLeftExpression().visit(getController().getAcg());
getController().getCompileStack().popLHS();
return true;
}
示例7: transformVariableExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
protected Expression transformVariableExpression(VariableExpression ve) {
Variable v = ve.getAccessedVariable();
if (v != null && v instanceof DynamicVariable) {
Expression result = findStaticFieldOrPropAccessorImportFromModule(v.getName());
if (result != null) {
setSourcePosition(result, ve);
if (inAnnotation) {
result = transformInlineConstants(result);
}
return result;
}
}
return ve;
}
示例8: visitVariableExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
@Override
public void visitVariableExpression(VariableExpression ve) {
Variable v = ve.getAccessedVariable();
if (v != null && v instanceof DynamicVariable) {
if (!inPropertyExpression || inSpecialConstructorCall) addStaticVariableError(ve);
}
}
示例9: addStaticVariableError
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private void addStaticVariableError(VariableExpression ve) {
// closures are always dynamic
// propertyExpressions will handle the error a bit differently
if (!inSpecialConstructorCall && (inClosure || !ve.isInStaticContext())) return;
if (ve.isThisExpression() || ve.isSuperExpression()) return;
Variable v = ve.getAccessedVariable();
if (currentMethod != null && currentMethod.isStatic()) {
FieldNode fieldNode = getDeclaredOrInheritedField(currentMethod.getDeclaringClass(), ve.getName());
if (fieldNode != null && fieldNode.isStatic()) return;
}
if (v != null && !(v instanceof DynamicVariable) && v.isInStaticContext()) return;
addVariableError(ve);
}
示例10: findTargetVariable
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
/**
* Given a variable expression, returns the ultimately accessed variable.
* @param ve a variable expression
* @return the target variable
*/
protected static Variable findTargetVariable(VariableExpression ve) {
final Variable accessedVariable = ve.getAccessedVariable() != null ? ve.getAccessedVariable() : ve;
if (accessedVariable != ve) {
if (accessedVariable instanceof VariableExpression)
return findTargetVariable((VariableExpression) accessedVariable);
}
return accessedVariable;
}
示例11: isTraitSelf
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
public static ClassNode isTraitSelf(VariableExpression vexp) {
if (Traits.THIS_OBJECT.equals(vexp.getName())) {
Variable accessedVariable = vexp.getAccessedVariable();
ClassNode type = accessedVariable!=null?accessedVariable.getType():null;
if (accessedVariable instanceof Parameter
&& Traits.isTrait(type)) {
return type;
}
}
return null;
}
示例12: checkFinalFieldAccess
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private void checkFinalFieldAccess(Expression expression) {
if (!(expression instanceof VariableExpression) && !(expression instanceof PropertyExpression)) return;
Variable v = null;
if (expression instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) expression;
v = ve.getAccessedVariable();
} else {
PropertyExpression propExp = ((PropertyExpression) expression);
Expression objectExpression = propExp.getObjectExpression();
if (objectExpression instanceof VariableExpression) {
VariableExpression varExp = (VariableExpression) objectExpression;
if (varExp.isThisExpression()) {
v = currentClass.getDeclaredField(propExp.getPropertyAsString());
}
}
}
if (v instanceof FieldNode) {
FieldNode fn = (FieldNode) v;
/*
* if it is static final but not accessed inside a static constructor, or,
* if it is an instance final but not accessed inside a instance constructor, it is an error
*/
boolean isFinal = fn.isFinal();
boolean isStatic = fn.isStatic();
boolean error = isFinal && ((isStatic && !inStaticConstructor) || (!isStatic && !inConstructor));
if (error) addError("cannot modify" + (isStatic ? " static" : "") + " final field '" + fn.getName() +
"' outside of " + (isStatic ? "static initialization block." : "constructor."), expression);
}
}
示例13: checkForFinal
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private void checkForFinal(final Expression expression, VariableExpression ve) {
Variable v = ve.getAccessedVariable();
if (v != null) {
boolean isFinal = isFinal(v.getModifiers());
boolean isParameter = v instanceof Parameter;
if (isFinal && isParameter) {
addError("Cannot assign a value to final variable '" + v.getName() + "'", expression);
}
}
}
示例14: visitConstructorCallExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
public void visitConstructorCallExpression(ConstructorCallExpression call) {
isSpecialConstructorCall = call.isSpecialCall();
super.visitConstructorCallExpression(call);
isSpecialConstructorCall = false;
if (!call.isUsingAnonymousInnerClass()) return;
pushState();
InnerClassNode innerClass = (InnerClassNode) call.getType();
innerClass.setVariableScope(currentScope);
for (MethodNode method : innerClass.getMethods()) {
Parameter[] parameters = method.getParameters();
if (parameters.length == 0) parameters = null; // null means no implicit "it"
ClosureExpression cl = new ClosureExpression(parameters, method.getCode());
visitClosureExpression(cl);
}
for (FieldNode field : innerClass.getFields()) {
final Expression expression = field.getInitialExpression();
pushState(field.isStatic());
if (expression != null) {
if (expression instanceof VariableExpression) {
VariableExpression vexp = (VariableExpression) expression;
if (vexp.getAccessedVariable() instanceof Parameter) {
// workaround for GROOVY-6834: accessing a parameter which is not yet seen in scope
popState();
continue;
}
}
expression.visit(this);
}
popState();
}
for (Statement statement : innerClass.getObjectInitializerStatements()) {
statement.visit(this);
}
markClosureSharedVariables();
popState();
}
示例15: transform
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
@Override
public Expression transform(final Expression exp) {
if (exp instanceof BinaryExpression) {
return transformBinaryExpression((BinaryExpression) exp);
}
if (exp instanceof MethodCallExpression) {
return transformMethodCall((MethodCallExpression) exp);
}
if (exp instanceof ClosureExpression) {
ClosureExpression cl = (ClosureExpression) exp;
cl.getCode().visit(this);
return cl;
}
if (exp instanceof VariableExpression) {
VariableExpression var = (VariableExpression) exp;
if (var.getAccessedVariable() instanceof DynamicVariable) {
MethodCallExpression callGetModel = new MethodCallExpression(
new VariableExpression("this"),
"getModel",
ArgumentListExpression.EMPTY_ARGUMENTS
);
callGetModel.setImplicitThis(true);
callGetModel.setSourcePosition(exp);
String varName = var.getName();
if ("model".equals(varName) || "unescaped".equals(varName)) {
return callGetModel;
}
MethodCallExpression mce = new MethodCallExpression(
callGetModel,
"get",
new ArgumentListExpression(new ConstantExpression(varName))
);
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
MethodCallExpression yield = new MethodCallExpression(
new VariableExpression("this"),
"tryEscape",
new ArgumentListExpression(mce)
);
yield.setImplicitThis(true);
yield.setSourcePosition(exp);
yield.putNodeMetaData(TARGET_VARIABLE, varName);
return autoEscape?yield:mce;
}
}
return super.transform(exp);
}