}
@Override
public PrintingElementVisitor visitType(TypeElement e, Boolean p) {
ElementKind kind = e.getKind();
NestingKind nestingKind = e.getNestingKind();
if (NestingKind.ANONYMOUS == nestingKind) {
// Print out an anonymous class in the style of a
// class instance creation expression rather than a
// class declaration.
writer.print("new ");
// If the anonymous class implements an interface
// print that name, otherwise print the superclass.
List<? extends TypeMirror> interfaces = e.getInterfaces();
if (!interfaces.isEmpty())
writer.print(interfaces.get(0));
else
writer.print(e.getSuperclass());
writer.print("(");
// Anonymous classes that implement an interface can't
// have any constructor arguments.
if (interfaces.isEmpty()) {
// Print out the parameter list from the sole
// constructor. For now, don't try to elide any
// synthetic parameters by determining if the
// anonymous class is in a static context, etc.
List<? extends ExecutableElement> constructors =
ElementFilter.constructorsIn(e.getEnclosedElements());
if (!constructors.isEmpty())
printParameters(constructors.get(0));
}
writer.print(")");
} else {
if (nestingKind == TOP_LEVEL) {
PackageElement pkg = elementUtils.getPackageOf(e);
if (!pkg.isUnnamed())
writer.print("package " + pkg.getQualifiedName() + ";\n");
}
defaultAction(e, true);
switch(kind) {
case ANNOTATION_TYPE:
writer.print("@interface");
break;
default:
writer.print(kind.toString().toLowerCase());
}
writer.print(" ");
writer.print(e.getSimpleName());
printFormalTypeParameters(e, false);