.getNeedsOnStateChangeHandler();
for (Entry<JClassType, Set<JMethod>> entry : needsOnStateChangeHandler
.entrySet()) {
JClassType connector = entry.getKey();
TreeLogger typeLogger = logger.branch(
Type.DEBUG,
"Generating @OnStateChange support for "
+ connector.getName());
// Build map to speed up error checking
HashMap<String, Property> stateProperties = new HashMap<String, Property>();
JClassType stateType = ConnectorBundle
.findInheritedMethod(connector, "getState").getReturnType()
.isClassOrInterface();
for (Property property : bundle.getProperties(stateType)) {
stateProperties.put(property.getName(), property);
}
for (JMethod method : entry.getValue()) {
TreeLogger methodLogger = typeLogger.branch(Type.DEBUG,
"Processing method " + method.getName());
if (method.isPublic() || method.isProtected()) {
methodLogger
.log(Type.ERROR,
"@OnStateChange is only supported for methods with private or default visibility.");
throw new UnableToCompleteException();
}
OnStateChange onStateChange = method
.getAnnotation(OnStateChange.class);
String[] properties = onStateChange.value();
if (properties.length == 0) {
methodLogger.log(Type.ERROR,
"There are no properties to listen to");
throw new UnableToCompleteException();
}
// Verify that all properties do exist
for (String propertyName : properties) {
if (!stateProperties.containsKey(propertyName)) {
methodLogger.log(Type.ERROR,
"State class has no property named "
+ propertyName);
throw new UnableToCompleteException();
}
}
if (method.getParameters().length != 0) {
methodLogger.log(Type.ERROR,
"Method should accept zero parameters");
throw new UnableToCompleteException();
}
// new OnStateChangeMethod(Class declaringClass, String