use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class FinalVariableAnalyzer method visitBlockStatement.
@Override
public void visitBlockStatement(final BlockStatement block) {
Set<VariableExpression> old = declaredFinalVariables;
declaredFinalVariables = new HashSet<VariableExpression>();
super.visitBlockStatement(block);
if (callback != null) {
Map<Variable, VariableState> state = getState();
for (VariableExpression declaredFinalVariable : declaredFinalVariables) {
VariableState variableState = state.get(declaredFinalVariable.getAccessedVariable());
if (variableState == null || variableState != VariableState.is_final) {
callback.variableNotAlwaysInitialized(declaredFinalVariable);
}
}
}
declaredFinalVariables = old;
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class ForTest method testNonLoop.
public void testNonLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
Parameter[] parameters = { new Parameter(ClassHelper.OBJECT_TYPE, "coll") };
Statement statement = createPrintlnStatement(new VariableExpression("coll"));
classNode.addMethod(new MethodNode("oneParamDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
Object bean = fooClass.newInstance();
assertTrue("Managed to create bean", bean != null);
System.out.println("################ Now about to invoke a method without looping");
Object value = new Integer(10000);
try {
InvokerHelper.invokeMethod(bean, "oneParamDemo", new Object[] { value });
} catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
}
System.out.println("################ Done");
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class ForTest method testManyParam.
public void testManyParam() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
Parameter[] parameters = { new Parameter(ClassHelper.OBJECT_TYPE, "coll1"), new Parameter(ClassHelper.OBJECT_TYPE, "coll2"), new Parameter(ClassHelper.OBJECT_TYPE, "coll3") };
BlockStatement statement = new BlockStatement();
statement.addStatement(createPrintlnStatement(new VariableExpression("coll1")));
statement.addStatement(createPrintlnStatement(new VariableExpression("coll2")));
statement.addStatement(createPrintlnStatement(new VariableExpression("coll3")));
classNode.addMethod(new MethodNode("manyParamDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
Object bean = fooClass.newInstance();
assertTrue("Managed to create bean", bean != null);
System.out.println("################ Now about to invoke a method with many parameters");
Object[] array = { new Integer(1000 * 1000), "foo-", "bar~" };
try {
InvokerHelper.invokeMethod(bean, "manyParamDemo", array);
} catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
}
System.out.println("################ Done");
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class VariableExpressionTest method testIsDynamicTyped_DYNMAMIC_TYPE.
public void testIsDynamicTyped_DYNMAMIC_TYPE() {
VariableExpression intExpression = new VariableExpression("foo", ClassHelper.DYNAMIC_TYPE);
assertTrue(intExpression.isDynamicTyped());
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy by apache.
the class VariableExpressionTest method testIsDynamicTypedExplicitObject.
public void testIsDynamicTypedExplicitObject() {
VariableExpression intExpression = new VariableExpression("foo", new ClassNode(Object.class));
assertFalse(intExpression.isDynamicTyped());
}
Aggregations