public final MMethod addGetterMethod(String name, boolean isSynchronized) { final MMethod method; if (type != null) { container.addExtraImport(type); method = container .addMethod(name, type, generic) .setGenerator( new MCodeGenerator<MMethod>() { @Override public MCodeBlock getCodeBlock(MMethod element) { MCodeBlock code = element.getCodeBlock(element); code.addLine("return " + MField.this.getName() + ";"); return code; } }); } else { method = container .addMethod(name, generic) .setGenerator( new MCodeGenerator<MMethod>() { @Override public MCodeBlock getCodeBlock(MMethod element) { MCodeBlock code = element.getCodeBlock(element); code.addLine("return " + MField.this.getName() + ";"); return code; } }); } return method.setSynchronized(isSynchronized && !isFinal()); }
public MMethod newMethod(MCpInfo clazz, String name, String signature) { MMethod method = new MMethod(this); MCpInfo methodName = newCpInfoUtf8(name); MCpInfo methodSign = newCpInfoUtf8(signature); MCpInfo methodNat = newCpInfo(CpNameAndType); MCpInfo methodRef = newCpInfo(CpMethodref); method.ptr_name = methodName; method.ptr_signature = methodSign; method.ptr_ref = methodRef; methodNat.ptr_name = methodName; methodNat.ptr_signature = methodSign; methodRef.ptr_class = clazz; methodRef.ptr_name_and_type = methodNat; return method; }
public final AccessorMethods addAccessorMethods() throws ClassNotFoundException { final MMethod getter = addGetterMethod(); getter.setFinal(true); final MMethod setter = addSetterMethod(); if (setter != null) { setter.setFinal(true); } return new AccessorMethods() { @Override public MMethod getter() { return getter; } @Override public MMethod setter() { return setter; } }; }