Search in sources :

Example 56 with PropertyExpression

use of org.codehaus.groovy.ast.expr.PropertyExpression in project gradle by gradle.

the class GradleResolveVisitor method correctClassClassChain.

// iterate from the inner most to the outer and check for classes
// this check will ignore a .class property, for Example Integer.class will be
// a PropertyExpression with the ClassExpression of Integer as objectExpression
// and class as property
private Expression correctClassClassChain(PropertyExpression pe) {
    LinkedList<Expression> stack = new LinkedList<Expression>();
    ClassExpression found = null;
    for (Expression it = pe; it != null; it = ((PropertyExpression) it).getObjectExpression()) {
        if (it instanceof ClassExpression) {
            found = (ClassExpression) it;
            break;
        } else if (!(it.getClass() == PropertyExpression.class)) {
            return pe;
        }
        stack.addFirst(it);
    }
    if (found == null) {
        return pe;
    }
    if (stack.isEmpty()) {
        return pe;
    }
    Object stackElement = stack.removeFirst();
    if (!(stackElement.getClass() == PropertyExpression.class)) {
        return pe;
    }
    PropertyExpression classPropertyExpression = (PropertyExpression) stackElement;
    String propertyNamePart = classPropertyExpression.getPropertyAsString();
    if (propertyNamePart == null || !propertyNamePart.equals("class")) {
        return pe;
    }
    found.setSourcePosition(classPropertyExpression);
    if (stack.isEmpty()) {
        return found;
    }
    stackElement = stack.removeFirst();
    if (!(stackElement.getClass() == PropertyExpression.class)) {
        return pe;
    }
    PropertyExpression classPropertyExpressionContainer = (PropertyExpression) stackElement;
    classPropertyExpressionContainer.setObjectExpression(found);
    return pe;
}
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) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) CastExpression(org.codehaus.groovy.ast.expr.CastExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) SpreadMapExpression(org.codehaus.groovy.ast.expr.SpreadMapExpression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) AnnotationConstantExpression(org.codehaus.groovy.ast.expr.AnnotationConstantExpression) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) LinkedList(java.util.LinkedList)

Aggregations

PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)56 Expression (org.codehaus.groovy.ast.expr.Expression)46 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)44 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)42 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)35 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)31 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)30 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)30 ClassNode (org.codehaus.groovy.ast.ClassNode)25 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)25 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)22 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)21 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)19 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)18 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)13 AnnotationConstantExpression (org.codehaus.groovy.ast.expr.AnnotationConstantExpression)11 MapEntryExpression (org.codehaus.groovy.ast.expr.MapEntryExpression)11 FieldNode (org.codehaus.groovy.ast.FieldNode)10 BooleanExpression (org.codehaus.groovy.ast.expr.BooleanExpression)10 CastExpression (org.codehaus.groovy.ast.expr.CastExpression)10