in json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java [1075:1133]
private boolean generateOnChange(Element clazz, Map<String,Collection<String[]>> propDeps,
Prprt[] properties, String className,
Map<String, Collection<String>> functionDeps
) {
boolean instance = clazz.getAnnotation(Model.class).instance();
for (Element m : clazz.getEnclosedElements()) {
if (m.getKind() != ElementKind.METHOD) {
continue;
}
ExecutableElement e = (ExecutableElement) m;
OnPropertyChange onPC = e.getAnnotation(OnPropertyChange.class);
if (onPC == null) {
continue;
}
for (String pn : onPC.value()) {
if (findPrprt(properties, pn) == null && findDerivedFrom(propDeps, pn).isEmpty()) {
error("No property named '" + pn + "' in the model", clazz);
return false;
}
}
if (!instance && !e.getModifiers().contains(Modifier.STATIC)) {
error("@OnPropertyChange method needs to be static", e);
return false;
}
if (e.getModifiers().contains(Modifier.PRIVATE)) {
error("@OnPropertyChange method cannot be private", e);
return false;
}
if (e.getReturnType().getKind() != TypeKind.VOID) {
error("@OnPropertyChange method should return void", e);
return false;
}
String n = e.getSimpleName().toString();
for (String pn : onPC.value()) {
StringBuilder call = new StringBuilder();
call.append(" ").append(inPckName(clazz, instance)).append(".").append(n).append("(");
call.append(wrapPropName(e, className, "name", pn));
call.append(");\n");
Collection<String> change = functionDeps.get(pn);
if (change == null) {
change = new ArrayList<String>();
functionDeps.put(pn, change);
}
change.add(call.toString());
for (String dpn : findDerivedFrom(propDeps, pn)) {
change = functionDeps.get(dpn);
if (change == null) {
change = new ArrayList<String>();
functionDeps.put(dpn, change);
}
change.add(call.toString());
}
}
}
return true;
}