public void visitClassTypeSignature(ClassTypeSignature ct) {
// This method examines the pathname stored in ct, which has the form
// n1.n2...nk< targs >....
// where n1 ... nk-1 might not exist OR
// nk might not exist (but not both). It may be that k equals 1.
// The idea is that nk is the simple class type name that has
// any type parameters associated with it.
// We process this path in two phases.
// First, we scan until we reach nk (if it exists).
// If nk does not exist, this identifies a raw class n1 ... nk-1
// which we can return.
// if nk does exist, we begin the 2nd phase.
// Here nk defines a parameterized type. Every further step nj (j > k)
// down the path must also be represented as a parameterized type,
// whose owner is the representation of the previous step in the path,
// n{j-1}.
// extract iterator on list of simple class type sigs
List< SimpleClassTypeSignature > scts = ct.getPath();
assert(!scts.isEmpty());
Iterator< SimpleClassTypeSignature > iter = scts.iterator();
SimpleClassTypeSignature sc = iter.next();
StringBuilder n = new StringBuilder(sc.getName());
boolean dollar = sc.getDollar();
// phase 1: iterate over simple class types until
// we are either done or we hit one with non-empty type parameters
while (iter.hasNext() && sc.getTypeArguments().length == 0) {
sc = iter.next();
dollar = sc.getDollar();
n.append(dollar?"$":".").append(sc.getName());
}
// Now, either sc is the last element of the list, or
// it has type arguments (or both)
assert(!(iter.hasNext()) || (sc.getTypeArguments().length > 0));
// Create the raw type
Type c = getFactory().makeNamedType(n.toString());
// if there are no type arguments
if (sc.getTypeArguments().length == 0) {
//we have surely reached the end of the path
assert(!iter.hasNext());
resultType = c; // the result is the raw type
} else {
assert(sc.getTypeArguments().length > 0);
// otherwise, we have type arguments, so we create a parameterized
// type, whose declaration is the raw type c, and whose owner is
// the declaring class of c (if any). This latter fact is indicated
// by passing null as the owner.
// First, we reify the type arguments
Type[] pts = reifyTypeArguments(sc.getTypeArguments());
Type owner = getFactory().makeParameterizedType(c, pts, null);
// phase 2: iterate over remaining simple class types
dollar =false;
while (iter.hasNext()) {
sc = iter.next();
dollar = sc.getDollar();
n.append(dollar?"$":".").append(sc.getName()); // build up raw class name
c = getFactory().makeNamedType(n.toString()); // obtain raw class
pts = reifyTypeArguments(sc.getTypeArguments());// reify params
// Create a parameterized type, based on type args, raw type
// and previous owner
owner = getFactory().makeParameterizedType(c, pts, owner);
}
resultType = owner;
}
}
|