use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.
the class Traits method findHelpers.
static TraitHelpersTuple findHelpers(final ClassNode trait) {
ClassNode helperClassNode = null;
ClassNode fieldHelperClassNode = null;
Iterator<InnerClassNode> innerClasses = trait.redirect().getInnerClasses();
if (innerClasses != null && innerClasses.hasNext()) {
// trait defined in same source unit
while (innerClasses.hasNext()) {
ClassNode icn = innerClasses.next();
if (icn.getName().endsWith(Traits.FIELD_HELPER)) {
fieldHelperClassNode = icn;
} else if (icn.getName().endsWith(Traits.TRAIT_HELPER)) {
helperClassNode = icn;
}
}
} else {
// precompiled trait
try {
final ClassLoader classLoader = trait.getTypeClass().getClassLoader();
String helperClassName = Traits.helperClassName(trait);
helperClassNode = ClassHelper.make(classLoader.loadClass(helperClassName));
try {
fieldHelperClassNode = ClassHelper.make(classLoader.loadClass(Traits.fieldHelperClassName(trait)));
} catch (ClassNotFoundException e) {
// not a problem, the field helper may be absent
}
} catch (ClassNotFoundException e) {
throw new GroovyBugError("Couldn't find trait helper classes on compile classpath!", e);
}
}
return new TraitHelpersTuple(helperClassNode, fieldHelperClassNode);
}
use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.
the class Java5 method configureTypeArguments.
private GenericsType[] configureTypeArguments(Type[] ta) {
if (ta.length == 0)
return null;
GenericsType[] gts = new GenericsType[ta.length];
for (int i = 0; i < ta.length; i++) {
ClassNode t = configureType(ta[i]);
if (ta[i] instanceof WildcardType) {
GenericsType[] gen = t.getGenericsTypes();
gts[i] = gen[0];
} else {
gts[i] = new GenericsType(t);
}
}
return gts;
}
use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.
the class Java5 method configureWildcardType.
private ClassNode configureWildcardType(WildcardType wildcardType) {
ClassNode base = ClassHelper.makeWithoutCaching("?");
base.setRedirect(ClassHelper.OBJECT_TYPE);
//TODO: more than one lower bound for wildcards?
ClassNode[] lowers = configureTypes(wildcardType.getLowerBounds());
ClassNode lower = null;
// TODO: is it safe to remove this? What was the original intention?
if (lowers != null)
lower = lowers[0];
ClassNode[] upper = configureTypes(wildcardType.getUpperBounds());
GenericsType t = new GenericsType(base, upper, lower);
t.setWildcard(true);
ClassNode ref = ClassHelper.makeWithoutCaching(Object.class, false);
ref.setGenericsTypes(new GenericsType[] { t });
return ref;
}
use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.
the class Java5 method makeClassNode.
private ClassNode makeClassNode(CompileUnit cu, Type t, Class c) {
ClassNode back = null;
if (cu != null)
back = cu.getClass(c.getName());
if (back == null)
back = ClassHelper.make(c);
if (!(t instanceof Class)) {
ClassNode front = configureType(t);
front.setRedirect(back);
return front;
}
return back.getPlainNodeReference();
}
use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.
the class Java5 method configureTypeVariableDefinition.
public static GenericsType configureTypeVariableDefinition(ClassNode base, ClassNode[] cBounds) {
ClassNode redirect = base.redirect();
base.setRedirect(null);
GenericsType gt;
if (cBounds == null || cBounds.length == 0) {
gt = new GenericsType(base);
} else {
gt = new GenericsType(base, cBounds, null);
gt.setName(base.getName());
gt.setPlaceholder(true);
}
base.setRedirect(redirect);
return gt;
}
Aggregations