* @param sortGems If true, then the gems will be sorted alphabetically.
* @return (Set of GemEntity) a set of the matching gems
*/
public Set<GemEntity> findGemsByReturnType(ModuleName scopeModule, String returnTypeName, boolean sortGems) {
// Get the type expression for the type name.
final TypeExpr returnTypeExpr = getTypeFromString(scopeModule, returnTypeName);
if (returnTypeExpr == null) {
return Collections.emptySet();
}
// Find all gems matching this type.
final ModuleTypeInfo targetModuleTypeInfo = getModuleTypeInfo(scopeModule);
GemFilter filter = new GemFilter() {
@Override
public boolean select(GemEntity gemEntity) {
TypeExpr gemResultType = gemEntity.getTypeExpr().getResultType();
return TypeExpr.canPatternMatch(gemResultType, returnTypeExpr, targetModuleTypeInfo);
}
};
return getMatchingGems(filter, sortGems);
}