EClassType classType = toClassType(element.getKind());
int modifiers = toJMod(element.getModifiers());
if (classType.equals(EClassType.INTERFACE))
modifiers = modifiers & ~JMod.ABSTRACT;
JDefinedClass newClass;
try {
newClass = codeModel._class(modifiers, element.getQualifiedName().toString(), classType);
} catch (JClassAlreadyExistsException ex) {
throw new CodeGenerationException(ex);
}
newClass.hide();
Annotator classAnnotator = new Annotator(newClass, environment);
classAnnotator.annotate(element.getAnnotationMirrors());
for (TypeParameterElement parameter: element.getTypeParameters()) {
JTypeVar typeVariable = newClass.generify(parameter.getSimpleName().toString());
environment.put(typeVariable.name(), typeVariable);
for (TypeMirror type: parameter.getBounds()) {
typeVariable.bound((AbstractJClass)toJType(type, environment));
}
}
TypeMirror superclass = element.getSuperclass();
if (superclass != null && superclass.getKind() != TypeKind.NONE) {
newClass._extends((AbstractJClass)toJType(superclass, environment));
}
for (TypeMirror iface: element.getInterfaces()) {
newClass._implements((AbstractJClass)toJType(iface, environment));
}
for (Element enclosedElement: element.getEnclosedElements()) {
if (enclosedElement.getKind().equals(ElementKind.METHOD)) {
ExecutableElement executable = (ExecutableElement)enclosedElement;
JMethod method = newClass.method(toJMod(executable.getModifiers()), codeModel.VOID, executable.getSimpleName().toString());
TypeEnvironment methodEnvironment = environment.enclosed();
Annotator methodAnnotator = new Annotator(method, environment);
methodAnnotator.annotate(executable.getAnnotationMirrors());
for (TypeParameterElement parameter: executable.getTypeParameters()) {
JTypeVar typeVariable = method.generify(parameter.getSimpleName().toString());