* 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.getStringLiteral(info, getPackageName(typeName));
JStringLiteral className = program.getStringLiteral(info, getClassName(typeName));
call.addArgs(packageName, className);
if (type instanceof JArrayType || type instanceof JClassType) {
// Add a runtime type reference.
call.addArg(new JRuntimeTypeReference(info, program.getTypeJavaLangObject(),
(JReferenceType) type));
} else if (type instanceof JPrimitiveType) {
// And give primitive types an illegal, though meaningful, value
call.addArg(program.getStringLiteral(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) {
if (JProgram.isJsTypePrototype(classType)) {
JDeclaredType jsInterface = program.typeOracle.getNearestJsType(classType, true);
assert jsInterface != null;
superclassLiteral = createDependentClassLiteral(info, jsInterface);
} else {
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 (methodIt.isStatic()) {
if (methodIt.getSignature().startsWith("values()")) {
valuesMethod = methodIt;
} else if (methodIt.getSignature().startsWith("valueOf(Ljava/lang/String;)")) {
valueOfMethod = methodIt;