use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class VariableExpressionTest method testPrimitiveOriginType.
public void testPrimitiveOriginType() {
VariableExpression boolExpression = new VariableExpression("fo", ClassHelper.boolean_TYPE);
VariableExpression intExpression = new VariableExpression("foo", ClassHelper.int_TYPE);
assertEquals(boolExpression.getOriginType().getName(), "boolean");
assertEquals(intExpression.getOriginType().getName(), "int");
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class StaticImportVisitor method transformPropertyExpression.
protected Expression transformPropertyExpression(PropertyExpression pe) {
if (currentMethod != null && currentMethod.isStatic() && pe.getObjectExpression() instanceof VariableExpression && ((VariableExpression) pe.getObjectExpression()).isSuperExpression()) {
PropertyExpression pexp = new PropertyExpression(new ClassExpression(currentClass.getSuperClass()), transform(pe.getProperty()));
pexp.setSourcePosition(pe);
return pexp;
}
boolean oldInPropertyExpression = inPropertyExpression;
Expression oldFoundArgs = foundArgs;
Expression oldFoundConstant = foundConstant;
inPropertyExpression = true;
foundArgs = null;
foundConstant = null;
Expression objectExpression = transform(pe.getObjectExpression());
boolean candidate = false;
if (objectExpression instanceof MethodCallExpression) {
candidate = ((MethodCallExpression) objectExpression).isImplicitThis();
}
if (foundArgs != null && foundConstant != null && candidate) {
Expression result = findStaticMethodImportFromModule(foundConstant, foundArgs);
if (result != null) {
objectExpression = result;
objectExpression.setSourcePosition(pe);
}
}
inPropertyExpression = oldInPropertyExpression;
foundArgs = oldFoundArgs;
foundConstant = oldFoundConstant;
pe.setObjectExpression(objectExpression);
return pe;
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class StaticImportVisitor method transformBinaryExpression.
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;
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class StaticVerifier method visitConstructorOrMethod.
@Override
public void visitConstructorOrMethod(MethodNode node, boolean isConstructor) {
MethodNode oldCurrentMethod = currentMethod;
currentMethod = node;
super.visitConstructorOrMethod(node, isConstructor);
if (isConstructor) {
final Set<String> exceptions = new HashSet<String>();
for (final Parameter param : node.getParameters()) {
exceptions.add(param.getName());
if (param.hasInitialExpression()) {
param.getInitialExpression().visit(new CodeVisitorSupport() {
@Override
public void visitVariableExpression(VariableExpression ve) {
if (exceptions.contains(ve.getName()))
return;
Variable av = ve.getAccessedVariable();
if (av instanceof DynamicVariable || !av.isInStaticContext()) {
addVariableError(ve);
}
}
@Override
public void visitMethodCallExpression(MethodCallExpression call) {
Expression objectExpression = call.getObjectExpression();
if (objectExpression instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) objectExpression;
if (ve.isThisExpression()) {
addError("Can't access instance method '" + call.getMethodAsString() + "' for a constructor parameter default value", param);
return;
}
}
super.visitMethodCallExpression(call);
}
@Override
public void visitClosureExpression(ClosureExpression expression) {
//skip contents, because of dynamic scope
}
});
}
}
}
currentMethod = oldCurrentMethod;
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class TraitReceiverTransformer method createArgumentList.
private ArgumentListExpression createArgumentList(final Expression origCallArgs) {
ArgumentListExpression newArgs = new ArgumentListExpression();
newArgs.addExpression(new VariableExpression(weaved));
if (origCallArgs instanceof ArgumentListExpression) {
List<Expression> expressions = ((ArgumentListExpression) origCallArgs).getExpressions();
for (Expression expression : expressions) {
newArgs.addExpression(transform(expression));
}
} else {
newArgs.addExpression(origCallArgs);
}
return newArgs;
}
Aggregations