use of org.codehaus.groovy.ast.expr.ClassExpression in project gradle by gradle.
the class GradleResolveVisitor method transformVariableExpression.
protected Expression transformVariableExpression(VariableExpression ve) {
visitAnnotations(ve);
Variable v = ve.getAccessedVariable();
if (!(v instanceof DynamicVariable) && !checkingVariableTypeInDeclaration) {
/*
* GROOVY-4009: when a normal variable is simply being used, there is no need to try to
* resolve its type. Variable type resolve should proceed only if the variable is being declared.
*/
return ve;
}
if (v instanceof DynamicVariable) {
String name = ve.getName();
ClassNode t = ClassHelper.make(name);
// asking isResolved here allows to check if a primitive
// type name like "int" was used to make t. In such a case
// we have nothing left to do.
boolean isClass = t.isResolved();
if (!isClass) {
// compiler skip the resolving at several places in this class.
if (Character.isLowerCase(name.charAt(0))) {
t = new LowerCaseClass(name);
}
isClass = resolve(t);
if (!isClass) {
isClass = resolveToNestedOfCurrent(t);
}
}
if (isClass) {
// for each parentscope too
for (VariableScope scope = currentScope; scope != null && !scope.isRoot(); scope = scope.getParent()) {
if (scope.isRoot()) {
break;
}
if (scope.removeReferencedClassVariable(ve.getName()) == null) {
break;
}
}
ClassExpression ce = new ClassExpression(t);
ce.setSourcePosition(ve);
return ce;
}
}
resolveOrFail(ve.getType(), ve);
ClassNode origin = ve.getOriginType();
if (origin != ve.getType()) {
resolveOrFail(origin, ve);
}
return ve;
}
use of org.codehaus.groovy.ast.expr.ClassExpression in project gradle by gradle.
the class RulesVisitor method visitMethodCallExpression.
@Override
public void visitMethodCallExpression(MethodCallExpression call) {
ClosureExpression closureExpression = AstUtils.getSingleClosureArg(call);
if (closureExpression != null) {
// path { ... }
rewriteAction(call, extractModelPathFromMethodTarget(call), closureExpression, RuleVisitor.displayName(call));
return;
}
Pair<ClassExpression, ClosureExpression> args = AstUtils.getClassAndClosureArgs(call);
if (args != null) {
// path(Type) { ... }
rewriteCreator(call, extractModelPathFromMethodTarget(call), args.getRight(), args.getLeft(), RuleVisitor.displayName(call));
return;
}
ClassExpression classArg = AstUtils.getClassArg(call);
if (classArg != null) {
// path(Type)
String displayName = RuleVisitor.displayName(call);
List<Statement> statements = Lists.newLinkedList();
statements.add(new EmptyStatement());
BlockStatement block = new BlockStatement(statements, new VariableScope());
closureExpression = new ClosureExpression(Parameter.EMPTY_ARRAY, block);
closureExpression.setVariableScope(block.getVariableScope());
String modelPath = extractModelPathFromMethodTarget(call);
rewriteCreator(call, modelPath, closureExpression, classArg, displayName);
return;
}
restrict(call, INVALID_RULE_SIGNATURE);
}
Aggregations