serverConnectorType = typeOracle.getType(ServerConnector.class
.getName());
} catch (NotFoundException e) {
logger.log(Type.ERROR,
"Can't find " + ServerConnector.class.getName());
throw new UnableToCompleteException();
}
JClassType[] types = serverConnectorType.getSubtypes();
Map<String, JClassType> mappings = new HashMap<String, JClassType>();
// Keep track of what has happened to avoid logging intermediate state
Map<JClassType, List<JClassType>> replaced = new HashMap<JClassType, List<JClassType>>();
for (JClassType type : types) {
Connect connectAnnotation = type.getAnnotation(Connect.class);
if (connectAnnotation == null) {
continue;
}
String identifier = connectAnnotation.value().getCanonicalName();
JClassType previousMapping = mappings.put(identifier, type);
if (previousMapping != null) {
// There are multiple mappings, pick the subclass
JClassType subclass;
JClassType superclass;
if (previousMapping.isAssignableFrom(type)) {
subclass = type;
superclass = previousMapping;
} else if (type.isAssignableFrom(previousMapping)) {
subclass = previousMapping;
superclass = type;
} else {
// Neither inherits from the other - this is a conflict
logger.log(
Type.ERROR,
"Conflicting @Connect mappings detected for "
+ identifier
+ ": "
+ type.getQualifiedSourceName()
+ " and "
+ previousMapping.getQualifiedSourceName()
+ ". There can only be multiple @Connect mappings for the same server-side type if one is the subclass of the other.");
throw new UnableToCompleteException();
}
mappings.put(identifier, subclass);
// Inherit any previous replacements