use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy-core by groovy.
the class JavaStubGenerator method getConstructorArgumentType.
private ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) {
if (!(arg instanceof VariableExpression))
return arg.getType();
VariableExpression vexp = (VariableExpression) arg;
String name = vexp.getName();
for (Parameter param : node.getParameters()) {
if (param.getName().equals(name)) {
return param.getType();
}
}
return vexp.getType();
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy-core by groovy.
the class FieldASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
sourceUnit = source;
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode()))
return;
if (parent instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) parent;
ClassNode cNode = de.getDeclaringClass();
if (!cNode.isScript()) {
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
return;
}
candidate = de;
// GROOVY-4548: temp fix to stop CCE until proper support is added
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", parent);
return;
}
VariableExpression ve = de.getVariableExpression();
variableName = ve.getName();
// set owner null here, it will be updated by addField
fieldNode = new FieldNode(variableName, ve.getModifiers(), ve.getType(), null, de.getRightExpression());
fieldNode.setSourcePosition(de);
cNode.addField(fieldNode);
// GROOVY-4833 : annotations that are not Groovy transforms should be transferred to the generated field
// GROOVY-6112 : also copy acceptable Groovy transforms
final List<AnnotationNode> annotations = de.getAnnotations();
for (AnnotationNode annotation : annotations) {
// GROOVY-6337 HACK: in case newly created field is @Lazy
if (annotation.getClassNode().equals(LAZY_TYPE)) {
LazyASTTransformation.visitField(annotation, fieldNode);
}
final ClassNode annotationClassNode = annotation.getClassNode();
if (notTransform(annotationClassNode) || acceptableTransform(annotation)) {
fieldNode.addAnnotation(annotation);
}
}
super.visitClass(cNode);
// GROOVY-5207 So that Closures can see newly added fields
// (not super efficient for a very large class with many @Fields but we chose simplicity
// and understandability of this solution over more complex but efficient alternatives)
VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(source);
scopeVisitor.visitClass(cNode);
}
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy-core by groovy.
the class BaseScriptASTTransformation method changeBaseScriptTypeFromDeclaration.
private void changeBaseScriptTypeFromDeclaration(final DeclarationExpression de, final AnnotationNode node) {
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
return;
}
if (!(de.getRightExpression() instanceof EmptyExpression)) {
addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
return;
}
Expression value = node.getMember("value");
if (value != null) {
addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
return;
}
ClassNode cNode = de.getDeclaringClass();
ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
de.setRightExpression(new VariableExpression("this"));
changeBaseScriptType(de, cNode, baseScriptType);
}
use of org.codehaus.groovy.ast.expr.VariableExpression in project groovy-core by groovy.
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-core by groovy.
the class AutoNewLineTransformer method createNewLine.
private Statement createNewLine(final ASTNode node) {
MethodCallExpression mce = new MethodCallExpression(new VariableExpression("this"), "newLine", ArgumentListExpression.EMPTY_ARGUMENTS);
mce.setImplicitThis(true);
mce.setSourcePosition(node);
ExpressionStatement stmt = new ExpressionStatement(mce);
stmt.setSourcePosition(node);
return stmt;
}
Aggregations