* Use the classForEnum() constructor even for enum subtypes to aid in
* pruning supertype data.
*/
boolean isEnumOrSubclass = false;
if (type instanceof JClassType) {
JEnumType maybeEnum = ((JClassType) type).isEnumOrSubclass();
if (maybeEnum != null) {
isEnumOrSubclass = true;
method = program.getIndexedMethod(maybeEnum.getClassLiteralFactoryMethod());
}
}
assert method != null;
JMethodCall call = new JMethodCall(info, null, method);
JStringLiteral packageName = program.getLiteralString(info, getPackageName(typeName));
JStringLiteral className = program.getLiteralString(info, getClassName(typeName));
call.addArgs(packageName, className);
if (type instanceof JArrayType) {
// There's only one seed function for all arrays
JDeclaredType arrayType = program.getIndexedType("Array");
call.addArg(new JNameOf(info, className.getType(), arrayType));
} else if (type instanceof JClassType) {
// Add the name of the seed function for concrete types
call.addArg(new JNameOf(info, className.getType(), type));
} else if (type instanceof JPrimitiveType) {
// And give primitive types an illegal, though meaningful, value
call.addArg(program.getLiteralString(info, " " + type.getJavahSignatureName()));
}
if (type instanceof JClassType) {
/*
* For non-array classes and enums, determine the class literal of the
* supertype, if there is one. Arrays are excluded because they always
* have Object as their superclass.
*/
JClassType classType = (JClassType) type;
JLiteral superclassLiteral;
if (classType.getSuperClass() != null) {
superclassLiteral = createDependentClassLiteral(info, classType.getSuperClass());
} else {
superclassLiteral = JNullLiteral.INSTANCE;
}
call.addArg(superclassLiteral);
if (classType instanceof JEnumType) {
JEnumType enumType = (JEnumType) classType;
JMethod valuesMethod = null;
JMethod valueOfMethod = null;
for (JMethod methodIt : enumType.getMethods()) {
if ("values".equals(methodIt.getName())) {
if (methodIt.getParams().size() != 0) {
continue;
}
valuesMethod = methodIt;