use of org.codehaus.groovy.ast.expr.ListExpression in project groovy-core by groovy.
the class NewifyASTTransformation method determineClasses.
/**
* allow non-strict mode in scripts because parsing not complete at that point
*/
private ListExpression determineClasses(Expression expr, boolean searchSourceUnit) {
ListExpression list = new ListExpression();
if (expr instanceof ClassExpression) {
list.addExpression(expr);
} else if (expr instanceof VariableExpression && searchSourceUnit) {
VariableExpression ve = (VariableExpression) expr;
ClassNode fromSourceUnit = getSourceUnitClass(ve);
if (fromSourceUnit != null) {
ClassExpression found = classX(fromSourceUnit);
found.setSourcePosition(ve);
list.addExpression(found);
} else {
addError(BASE_BAD_PARAM_ERROR + "an unresolvable reference to '" + ve.getName() + "'.", expr);
}
} else if (expr instanceof ListExpression) {
list = (ListExpression) expr;
final List<Expression> expressions = list.getExpressions();
for (int i = 0; i < expressions.size(); i++) {
Expression next = expressions.get(i);
if (next instanceof VariableExpression && searchSourceUnit) {
VariableExpression ve = (VariableExpression) next;
ClassNode fromSourceUnit = getSourceUnitClass(ve);
if (fromSourceUnit != null) {
ClassExpression found = classX(fromSourceUnit);
found.setSourcePosition(ve);
expressions.set(i, found);
} else {
addError(BASE_BAD_PARAM_ERROR + "a list containing an unresolvable reference to '" + ve.getName() + "'.", next);
}
} else if (!(next instanceof ClassExpression)) {
addError(BASE_BAD_PARAM_ERROR + "a list containing type: " + next.getType().getName() + ".", next);
}
}
checkDuplicateNameClashes(list);
} else if (expr != null) {
addError(BASE_BAD_PARAM_ERROR + "a type: " + expr.getType().getName() + ".", expr);
}
return list;
}
use of org.codehaus.groovy.ast.expr.ListExpression in project groovy-core by groovy.
the class NewifyASTTransformation method newifyMethodOrField.
private void newifyMethodOrField(AnnotatedNode parent, boolean autoFlag, ListExpression list) {
final ListExpression oldClassesToNewify = classesToNewify;
final boolean oldAuto = auto;
checkClassLevelClashes(list);
checkAutoClash(autoFlag, parent);
classesToNewify = list;
auto = autoFlag;
if (parent instanceof FieldNode) {
super.visitField((FieldNode) parent);
} else {
super.visitMethod((MethodNode) parent);
}
classesToNewify = oldClassesToNewify;
auto = oldAuto;
}
use of org.codehaus.groovy.ast.expr.ListExpression in project groovy-core by groovy.
the class NewifyASTTransformation method newifyClass.
private void newifyClass(ClassNode cNode, boolean autoFlag, ListExpression list) {
String cName = cNode.getName();
if (cNode.isInterface()) {
addError("Error processing interface '" + cName + "'. @" + MY_NAME + " not allowed for interfaces.", cNode);
}
final ListExpression oldClassesToNewify = classesToNewify;
final boolean oldAuto = auto;
classesToNewify = list;
auto = autoFlag;
super.visitClass(cNode);
classesToNewify = oldClassesToNewify;
auto = oldAuto;
}
use of org.codehaus.groovy.ast.expr.ListExpression in project groovy-core by groovy.
the class AbstractASTTransformation method getMemberList.
public List<String> getMemberList(AnnotationNode anno, String name) {
List<String> list;
Expression expr = anno.getMember(name);
if (expr != null && expr instanceof ListExpression) {
list = new ArrayList<String>();
final ListExpression listExpression = (ListExpression) expr;
for (Expression itemExpr : listExpression.getExpressions()) {
if (itemExpr != null && itemExpr instanceof ConstantExpression) {
Object value = ((ConstantExpression) itemExpr).getValue();
if (value != null)
list.add(value.toString());
}
}
} else {
list = tokenize(getMemberStringValue(anno, name));
}
return list;
}
use of org.codehaus.groovy.ast.expr.ListExpression in project groovy-core by groovy.
the class AbstractASTTransformation method getClassList.
public List<ClassNode> getClassList(AnnotationNode anno, String name) {
List<ClassNode> list = new ArrayList<ClassNode>();
Expression expr = anno.getMember(name);
if (expr != null && expr instanceof ListExpression) {
final ListExpression listExpression = (ListExpression) expr;
for (Expression itemExpr : listExpression.getExpressions()) {
if (itemExpr != null && itemExpr instanceof ClassExpression) {
ClassNode cn = itemExpr.getType();
if (cn != null)
list.add(cn);
}
}
} else if (expr != null && expr instanceof ClassExpression) {
ClassNode cn = expr.getType();
if (cn != null)
list.add(cn);
}
return list;
}
Aggregations