Search in sources :

Example 86 with ListExpression

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;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression)

Example 87 with ListExpression

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;
}
Also used : FieldNode(org.codehaus.groovy.ast.FieldNode) ListExpression(org.codehaus.groovy.ast.expr.ListExpression)

Example 88 with ListExpression

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;
}
Also used : ListExpression(org.codehaus.groovy.ast.expr.ListExpression)

Example 89 with ListExpression

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;
}
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 90 with ListExpression

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;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) 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) ArrayList(java.util.ArrayList) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression)

Aggregations

ListExpression (org.codehaus.groovy.ast.expr.ListExpression)103 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)77 Expression (org.codehaus.groovy.ast.expr.Expression)77 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)70 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)53 ClassNode (org.codehaus.groovy.ast.ClassNode)49 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)43 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)42 MapExpression (org.codehaus.groovy.ast.expr.MapExpression)38 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)38 ArrayExpression (org.codehaus.groovy.ast.expr.ArrayExpression)37 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)32 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)32 ArrayList (java.util.ArrayList)31 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)30 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)28 AnnotationConstantExpression (org.codehaus.groovy.ast.expr.AnnotationConstantExpression)25 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)25 MapEntryExpression (org.codehaus.groovy.ast.expr.MapEntryExpression)23 CastExpression (org.codehaus.groovy.ast.expr.CastExpression)22