use of org.codehaus.groovy.ast.GenericsType in project gradle by gradle.
the class GradleResolveVisitor method resolveGenericsHeader.
private void resolveGenericsHeader(GenericsType[] types) {
if (types == null) {
return;
}
currentClass.setUsingGenerics(true);
for (GenericsType type : types) {
ClassNode classNode = type.getType();
String name = type.getName();
ClassNode[] bounds = type.getUpperBounds();
if (bounds != null) {
boolean nameAdded = false;
for (ClassNode upperBound : bounds) {
if (!nameAdded && upperBound != null || !resolve(classNode)) {
genericParameterNames.put(name, type);
type.setPlaceholder(true);
classNode.setRedirect(upperBound);
nameAdded = true;
}
resolveOrFail(upperBound, classNode);
}
} else {
genericParameterNames.put(name, type);
classNode.setRedirect(ClassHelper.OBJECT_TYPE);
type.setPlaceholder(true);
}
}
}
use of org.codehaus.groovy.ast.GenericsType in project gradle by gradle.
the class GradleResolveVisitor method visitClass.
public void visitClass(ClassNode node) {
ClassNode oldNode = currentClass;
if (node instanceof InnerClassNode) {
if (Modifier.isStatic(node.getModifiers())) {
genericParameterNames = new HashMap<String, GenericsType>();
}
} else {
genericParameterNames = new HashMap<String, GenericsType>();
}
currentClass = node;
resolveGenericsHeader(node.getGenericsTypes());
ModuleNode module = node.getModule();
if (!module.hasImportsResolved()) {
for (ImportNode importNode : module.getImports()) {
currImportNode = importNode;
ClassNode type = importNode.getType();
if (resolve(type, false, false, true)) {
currImportNode = null;
continue;
}
currImportNode = null;
addError("unable to resolve class " + type.getName(), type);
}
for (ImportNode importNode : module.getStaticStarImports().values()) {
ClassNode type = importNode.getType();
if (resolve(type, false, false, true)) {
continue;
}
// Try with the node's package too. If still not found, revert to original type name.
if (type.getPackageName() == null && node.getPackageName() != null) {
String oldTypeName = type.getName();
type.setName(node.getPackageName() + "." + oldTypeName);
if (resolve(type, false, false, true)) {
continue;
}
type.setName(oldTypeName);
}
addError("unable to resolve class " + type.getName(), type);
}
for (ImportNode importNode : module.getStaticImports().values()) {
ClassNode type = importNode.getType();
if (resolve(type, true, true, true)) {
continue;
}
addError("unable to resolve class " + type.getName(), type);
}
for (ImportNode importNode : module.getStaticStarImports().values()) {
ClassNode type = importNode.getType();
if (resolve(type, true, true, true)) {
continue;
}
addError("unable to resolve class " + type.getName(), type);
}
module.setImportsResolved(true);
}
ClassNode sn = node.getUnresolvedSuperClass();
if (sn != null) {
resolveOrFail(sn, node, true);
}
for (ClassNode anInterface : node.getInterfaces()) {
resolveOrFail(anInterface, node, true);
}
checkCyclicInheritence(node, node.getUnresolvedSuperClass(), node.getInterfaces());
super.visitClass(node);
currentClass = oldNode;
}
use of org.codehaus.groovy.ast.GenericsType in project gradle by gradle.
the class GradleResolveVisitor method resolveGenericsType.
private boolean resolveGenericsType(GenericsType genericsType) {
if (genericsType.isResolved()) {
return true;
}
currentClass.setUsingGenerics(true);
ClassNode type = genericsType.getType();
// save name before redirect
String name = type.getName();
ClassNode[] bounds = genericsType.getUpperBounds();
if (!genericParameterNames.containsKey(name)) {
if (bounds != null) {
for (ClassNode upperBound : bounds) {
resolveOrFail(upperBound, genericsType);
type.setRedirect(upperBound);
resolveGenericsTypes(upperBound.getGenericsTypes());
}
} else if (genericsType.isWildcard()) {
type.setRedirect(ClassHelper.OBJECT_TYPE);
} else {
resolveOrFail(type, genericsType);
}
} else {
GenericsType gt = genericParameterNames.get(name);
type.setRedirect(gt.getType());
genericsType.setPlaceholder(true);
}
if (genericsType.getLowerBound() != null) {
resolveOrFail(genericsType.getLowerBound(), genericsType);
}
if (resolveGenericsTypes(type.getGenericsTypes())) {
genericsType.setResolved(genericsType.getType().isResolved());
}
return genericsType.isResolved();
}
use of org.codehaus.groovy.ast.GenericsType in project grails-core by grails.
the class DefaultGrailsDomainClassInjector method findPropertyType.
/**
* Finds the type of the generated property. The type will be a {@link Set} that is parameterized
* by the type of the expression passed in.
* @param expression the expression used to parameterize the {@link Set}. Only used if a {@link ClassExpression}. Otherwise ignored.
* @return A {@link ClassNode} of type {@link Set} that is possibly parameterized by the expression that is passed in.
*/
private ClassNode findPropertyType(Expression expression) {
ClassNode setNode = ClassHelper.make(Set.class).getPlainNodeReference();
if (expression instanceof ClassExpression) {
GenericsType[] genericsTypes = new GenericsType[1];
genericsTypes[0] = new GenericsType(GrailsASTUtils.nonGeneric(expression.getType()));
setNode.setGenericsTypes(genericsTypes);
}
return setNode;
}
use of org.codehaus.groovy.ast.GenericsType in project groovy-core by groovy.
the class GenericsVisitor method checkWildcard.
private boolean checkWildcard(ClassNode cn) {
ClassNode sn = cn.getUnresolvedSuperClass(false);
if (sn == null)
return false;
GenericsType[] generics = sn.getGenericsTypes();
if (generics == null)
return false;
boolean error = false;
for (int i = 0; i < generics.length; i++) {
if (generics[i].isWildcard()) {
addError("A supertype may not specify a wildcard type", sn);
error = true;
}
}
return error;
}
Aggregations