private boolean declareField(CtClass ctClass, String fieldName, CtClass fieldType) throws CannotCompileException, NotFoundException { CtMethod ctMethod = getMethod(ctClass, "get" + fieldName, ""); if (ctMethod == null) { return false; } CtClass getterFieldType = ctMethod.getReturnType(); if (!getterFieldType.equals(fieldType)) { return false; } if (getField(ctClass, fieldName) == null) { CtField field = new CtField(fieldType, fieldName, ctClass); field.setModifiers(Modifier.PRIVATE); ctClass.addField(field); } return true; }