public static PreferenceProcessor createProcessor(final CommandAction command) { assert command != null; PreferenceProcessor pp = new PreferenceProcessor(); Branding branding = ShellHolder.get().getBranding(); pp.setBasePath(branding.getPreferencesBasePath()); pp.addBean(command); return pp; } }
private void discoverDescriptors(final Object bean) { assert bean != null; // Recursively process all the methods/fields (@Inherited won't work here) for (Class<?> type = bean.getClass(); type != null; type = type.getSuperclass()) { Preferences base = type.getAnnotation(Preferences.class); for (Method method : type.getDeclaredMethods()) { discoverDescriptor(base, bean, method); } for (Field field : type.getDeclaredFields()) { discoverDescriptor(base, bean, field); } } }
public void addBean(final Object bean) { discoverDescriptors(bean); }
PreferenceProcessor pp = new PreferenceProcessor(); pp.setBasePath(getBranding().getPreferencesBasePath()); pp.addBean(this); pp.process();
private void discoverDescriptor(final Preferences base, final Object bean, final AnnotatedElement element) { // base could be null assert bean != null; assert element != null; Preference pref = element.getAnnotation(Preference.class); if (pref != null) { log.trace("Discovered preference for: {}", element); PreferenceDescriptor desc = new PreferenceDescriptor(base, pref, SetterFactory.create(element, bean)); desc.setBasePath(getBasePath()); descriptors.add(desc); } }
@SuppressWarnings("unused") public String getPreferences() { if (pp.getDescriptors().isEmpty()) { return ""; } PrintBuffer buff = new PrintBuffer(); printHeader(buff, "section.preferences"); for (PreferenceDescriptor pd : pp.getDescriptors()) { String text = String.format(" %s @|bold %s|@ (%s)", pd.getPreferences().absolutePath(), pd.getId(), pd.getSetter().getType().getSimpleName()); buff.println(AnsiRenderer.render(text)); } return buff.toString(); }