ClassDefItem toClassDefItem() { if (!declared) { throw new IllegalStateException( "Undeclared type " + type + " declares members: " + fields.keySet() + " " + methods.keySet()); } DexOptions dexOptions = new DexOptions(); dexOptions.targetApiLevel = DexFormat.API_NO_EXTENDED_OPCODES; CstType thisType = type.constant; ClassDefItem out = new ClassDefItem( thisType, flags, supertype.constant, interfaces.ropTypes, new CstString(sourceFile)); for (MethodDeclaration method : methods.values()) { EncodedMethod encoded = method.toEncodedMethod(dexOptions); if (method.isDirect()) { out.addDirectMethod(encoded); } else { out.addVirtualMethod(encoded); } } for (FieldDeclaration field : fields.values()) { EncodedField encoded = field.toEncodedField(); if (field.isStatic()) { out.addStaticField(encoded, Constants.getConstant(field.staticValue)); } else { out.addInstanceField(encoded); } } return out; }