In javac's source code, what is the purpose of traversing from a type to a symbol to its type?

Viewed 12

In the source code for javac, I have seen idioms of this form:

Type t = ...;

// Now let's say I want to, say, get its supertype. The idiom seems to be:
Object o = t.tsym.type.supertype_field;

// ...rather than:
Object o = t.supertype_field;

I understand that certain Types and Symbols are circular dependencies. That is, every non-error ClassType, for example, has a ClassSymbol, and every non-error ClassSymbol has a ClassType, even though logically types precede symbols (during construction everything is twiddled to point to each other).

I also understand hazily that there may be various errors during compilation such that a given Type may actually be an ErrorType and I suppose may have different information associated with it.

What kind of canonicalizing is being accomplished by saying t.tsym.type.something rather than just t.something?

If (to reduce mental load) I pretend that errors never exist (so all, say, ClassTypes have ClassSymbols and vice versa), when is there a substantive difference between accessing t.something and t.tsym.type.something?

There is a concrete example in the supertype(Type) method.

0 Answers
Related