Search in sources :

Example 56 with ListExpression

use of org.codehaus.groovy.ast.expr.ListExpression in project groovy by apache.

the class AbstractASTTransformation method getMemberList.

@Deprecated
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;
}
Also used : ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Expression(org.codehaus.groovy.ast.expr.Expression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression)

Example 57 with ListExpression

use of org.codehaus.groovy.ast.expr.ListExpression in project groovy by apache.

the class ImmutableASTTransformation method getKnownImmutables.

private List<String> getKnownImmutables(AnnotationNode node) {
    final List<String> immutables = new ArrayList<String>();
    final Expression expression = node.getMember(MEMBER_KNOWN_IMMUTABLES);
    if (expression == null)
        return immutables;
    if (!(expression instanceof ListExpression)) {
        addError("Use the Groovy list notation [el1, el2] to specify known immutable property names via \"" + MEMBER_KNOWN_IMMUTABLES + "\"", node);
        return immutables;
    }
    final ListExpression listExpression = (ListExpression) expression;
    for (Expression listItemExpression : listExpression.getExpressions()) {
        if (listItemExpression instanceof ConstantExpression) {
            immutables.add((String) ((ConstantExpression) listItemExpression).getValue());
        }
    }
    return immutables;
}
Also used : ListExpression(org.codehaus.groovy.ast.expr.ListExpression) MapExpression(org.codehaus.groovy.ast.expr.MapExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ArrayExpression(org.codehaus.groovy.ast.expr.ArrayExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ArrayList(java.util.ArrayList) ToStringASTTransformation.createToString(org.codehaus.groovy.transform.ToStringASTTransformation.createToString)

Example 58 with ListExpression

use of org.codehaus.groovy.ast.expr.ListExpression in project groovy by apache.

the class ImmutableASTTransformation method getKnownImmutableClasses.

private List<String> getKnownImmutableClasses(AnnotationNode node) {
    final List<String> immutableClasses = new ArrayList<String>();
    final Expression expression = node.getMember(MEMBER_KNOWN_IMMUTABLE_CLASSES);
    if (expression == null)
        return immutableClasses;
    if (!(expression instanceof ListExpression)) {
        addError("Use the Groovy list notation [el1, el2] to specify known immutable classes via \"" + MEMBER_KNOWN_IMMUTABLE_CLASSES + "\"", node);
        return immutableClasses;
    }
    final ListExpression listExpression = (ListExpression) expression;
    for (Expression listItemExpression : listExpression.getExpressions()) {
        if (listItemExpression instanceof ClassExpression) {
            immutableClasses.add(listItemExpression.getType().getName());
        }
    }
    return immutableClasses;
}
Also used : ListExpression(org.codehaus.groovy.ast.expr.ListExpression) MapExpression(org.codehaus.groovy.ast.expr.MapExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ArrayExpression(org.codehaus.groovy.ast.expr.ArrayExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ArrayList(java.util.ArrayList) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ToStringASTTransformation.createToString(org.codehaus.groovy.transform.ToStringASTTransformation.createToString)

Aggregations

ListExpression (org.codehaus.groovy.ast.expr.ListExpression)58 Expression (org.codehaus.groovy.ast.expr.Expression)42 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)39 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)35 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)25 ClassNode (org.codehaus.groovy.ast.ClassNode)24 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)19 ArrayList (java.util.ArrayList)16 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)13 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)13 ArrayExpression (org.codehaus.groovy.ast.expr.ArrayExpression)12 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)12 MapExpression (org.codehaus.groovy.ast.expr.MapExpression)10 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)9 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)5 FieldNode (org.codehaus.groovy.ast.FieldNode)5 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)5 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)5 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)5 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)5