protected void generateSelf_get(MemberRef[] fields) { MethodBuilder builder = new MethodBuilder( _context, _ce, Modifiers.PUBLIC, Object.class, SELFGET_METHODNAME, new Class[] {String.class}, new Class[0]); for (int fieldIdx = 0; fieldIdx < fields.length; fieldIdx++) { generateSelfGetMethodCase(builder, fieldIdx, fields[fieldIdx]); } Type superType = _ce.superclass(); if (instrumentedType(superType)) { builder.aload(0); builder.aload(1); builder.invokeSpecial(superType, SELFGET_METHODNAME, new Type[] {Type.STRING}, Type.OBJECT); } else { builder.ldc(null); } builder.areturn(); builder.commit(); }
public void generate() { addInterfaceIfNeeded(); if (!(inspectNoArgConstr(_ce.methods()))) { _context.addNoArgConstructor(_ce); } MemberRef[] declaredFields = _context.collectDeclaredFields(_ce); generateSelf_get(declaredFields); generateSelf_set(declaredFields); }
private boolean implementsSelfReflectable(ClassEditor ce) { Type[] interfaces = ce.interfaces(); for (int interfIdx = 0; interfIdx < interfaces.length; interfIdx++) { if (interfaces[interfIdx].getClass().equals(SelfReflectable.class)) { return true; } } return false; }
private void addInterfaceIfNeeded() { if (!instrumentedType(_ce.superclass()) && !implementsSelfReflectable(_ce)) { _ce.addInterface(SelfReflectable.class); } }