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;
}
Aggregations