1717import javax .swing .event .ChangeListener ;
1818
1919import org .objectweb .asm .Opcodes ;
20+ import org .objectweb .asm .Type ;
2021import org .objectweb .asm .tree .AbstractInsnNode ;
2122import org .objectweb .asm .tree .ClassNode ;
2223import org .objectweb .asm .tree .LabelNode ;
@@ -172,7 +173,8 @@ private Component createEditor(InstructionList il, AbstractInsnNode ain, String
172173 }
173174
174175 private Component createLdcEditor (InstructionList il , LdcInsnNode ain , Field f ) {
175- String [] items = { "String" , "Integer" , "Float" , "Long" , "Double" , "Type" , "Handle" , "ConstantDynamic" };
176+ String [] items = { "String" , "Integer" , "Float" , "Long" , "Double" , "Type" , "<html><s>Handle" ,
177+ "<html><s>ConstantDynamic" };
176178
177179 WebComboBox wcb = new WebComboBox (items );
178180 wcb .setSelectedItem (ain .cst .getClass ().getSimpleName ());
@@ -181,20 +183,60 @@ private Component createLdcEditor(InstructionList il, LdcInsnNode ain, Field f)
181183 panel .add (wcb , BorderLayout .WEST );
182184 WebTextField field = new WebTextField (ain .cst .toString ());
183185 field .setMaximumWidth (maxWidth / 2 );
184- field .setInputPrompt ("only String supported yet.." );
185- wcb .setEnabled (false );
186- field .setEnabled (ain .cst .getClass ().getSimpleName ().equals ("String" ));
186+ field .setEnabled (!ain .cst .getClass ().getSimpleName ().equals ("Handle" )
187+ && !ain .cst .getClass ().getSimpleName ().equals ("ConstantDynamic" ));
187188 Listeners .addChangeListener (field , c -> {
188- setField (f , ain , field .getText ().trim ());
189+ try {
190+ ldcComponentUpdate (wcb , ain , f , field );
191+ } catch (Exception e ) {
192+ wcb .setSelectedIndex (0 );
193+ }
194+ il .repaint ();
195+ });
196+ wcb .addActionListener (l -> {
197+ if (wcb .getSelectedIndex () >= 6 ) {
198+ wcb .setSelectedIndex (0 ); //not supported yet
199+ }
200+ try {
201+ ldcComponentUpdate (wcb , ain , f , field );
202+ } catch (Exception e ) {
203+ wcb .setSelectedIndex (0 );
204+ }
189205 il .repaint ();
190206 });
191207 panel .add (field , BorderLayout .CENTER );
192208 return panel ;
193209 }
194210
195- /*
196- * if (cst instanceof Integer) { // ... } else if (cst instanceof Float) { // ... } else if (cst instanceof Long) { // ... } else if (cst instanceof Double) { // ... } else if (cst instanceof String) { // ... } else if (cst instanceof Type) { int sort = ((Type) cst).getSort(); if (sort == Type.OBJECT) { // ... } else if (sort == Type.ARRAY) { // ... } else if (sort == Type.METHOD) { // ... } else { // throw an exception } } else if (cst instanceof Handle) { // ... } else if (cst instanceof ConstantDynamic) { // ... } else { // throw an exception }
197- */
211+ private void ldcComponentUpdate (WebComboBox wcb , LdcInsnNode ain , Field f , WebTextField field ) {
212+ switch (wcb .getSelectedIndex ()) {
213+ case 0 :
214+ setField (f , ain , field .getText ().trim ());
215+ break ;
216+ case 1 :
217+ setField (f , ain , Integer .parseInt (field .getText ().trim ()));
218+ break ;
219+ case 2 :
220+ setField (f , ain , Float .parseFloat (field .getText ().trim ()));
221+ break ;
222+ case 3 :
223+ setField (f , ain , Long .parseLong (field .getText ().trim ()));
224+ break ;
225+ case 4 :
226+ setField (f , ain , Double .parseDouble (field .getText ().trim ()));
227+ break ;
228+ case 5 :
229+ setField (f , ain , Type .getType (field .getText ().trim ()));
230+ break ;
231+ case 6 :
232+ setField (f , ain , field .getText ().trim ());
233+ break ;
234+ case 7 :
235+ setField (f , ain , field .getText ().trim ());
236+ break ;
237+ }
238+ }
239+
198240 private void setField (Field f , AbstractInsnNode ain , Object object ) {
199241 // to avoid try catch blocks all the time..
200242 try {
0 commit comments