@Test public void testBuild() throws Exception { String[] expectedValues = {"A", "B", "C", "D", "E"}; TypeSetting typeSetting = new TypeSetting(); typeSetting.setName(Constants.Settings.COMBOBOX_VALUES); FieldSetting fieldSetting = new FieldSetting(null, typeSetting, StringUtils.join(expectedValues, "\n")); Type type = new Type("mds.field.combobox", null, null); Field field = new Field(null, "swag", "swag", false, false, false, false, false, null, null, null, null); field.setType(type); field.addSetting(fieldSetting); Entity entity = new Entity(CLASS_NAME); entity.addField(field); ComboboxHolder holder = new ComboboxHolder(entity, field); ClassData data = new EnumBuilderImpl().build(holder); MDSClassLoader.getInstance().safeDefineClass(data.getClassName(), data.getBytecode()); Class<?> enumClass = MDSClassLoader.getInstance().loadClass(data.getClassName()); assertTrue("The class definition should be enum", enumClass.isEnum()); Object[] enumConstants = enumClass.getEnumConstants(); String[] actualValues = new String[enumConstants.length]; for (int i = 0; i < enumConstants.length; i++) { actualValues[i] = enumConstants[i].toString(); } Arrays.sort(expectedValues, String.CASE_INSENSITIVE_ORDER); Arrays.sort(actualValues, String.CASE_INSENSITIVE_ORDER); assertArrayEquals(expectedValues, actualValues); }
@Override public ClassData build(ComboboxHolder holder) { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassHelper helper = new ClassHelper(holder); start(classWriter, helper); visitFields(classWriter, helper); visitValues(classWriter, helper); visitValueOf(classWriter, helper); visitInit(classWriter, helper); visitClinit(classWriter, helper); end(classWriter); return new ClassData(helper.className, null, null, classWriter.toByteArray(), false, EntityType.STANDARD, true); }
EnumBuilderImpl implements EnumBuilder, Opcodes { @Override public ClassData build(ComboboxHolder holder) { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassHelper helper = new ClassHelper(holder); start(classWriter, helper); visitFields(classWriter, helper); visitValues(classWriter, helper); visitValueOf(classWriter, helper); visitInit(classWriter, helper); visitClinit(classWriter, helper); end(classWriter); return new ClassData(helper.className, null, null, classWriter.toByteArray(), false, EntityType.STANDARD, true); } }
EnumBuilderImpl implements EnumBuilder, Opcodes { @Override public ClassData build(ComboboxHolder holder) { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassHelper helper = new ClassHelper(holder); start(classWriter, helper); visitFields(classWriter, helper); visitValues(classWriter, helper); visitValueOf(classWriter, helper); visitInit(classWriter, helper); visitClinit(classWriter, helper); end(classWriter); return new ClassData(helper.className, null, null, classWriter.toByteArray(), false, EntityType.STANDARD, true); }  }
EnumBuilderImpl implements EnumBuilder, Opcodes { @Override public ClassData build(ComboboxHolder holder) { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassHelper helper = new ClassHelper(holder); start(classWriter, helper); visitFields(classWriter, helper); visitValues(classWriter, helper); visitValueOf(classWriter, helper); visitInit(classWriter, helper); visitClinit(classWriter, helper); end(classWriter); return new ClassData(helper.className, null, null, classWriter.toByteArray(), false, EntityType.STANDARD, true); }  @Override ClassData build(ComboboxHolder holder); }
EnumBuilderImpl implements EnumBuilder, Opcodes { @Override public ClassData build(ComboboxHolder holder) { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassHelper helper = new ClassHelper(holder); start(classWriter, helper); visitFields(classWriter, helper); visitValues(classWriter, helper); visitValueOf(classWriter, helper); visitInit(classWriter, helper); visitClinit(classWriter, helper); end(classWriter); return new ClassData(helper.className, null, null, classWriter.toByteArray(), false, EntityType.STANDARD, true); }  @Override ClassData build(ComboboxHolder holder);  }