Skip to content

Commit fa58885

Browse files
committed
refactor(factories): Replace manual blank checks with StringHelper.defaultIfBlank()
- Update McpServerPromptFactory, McpServerResourceFactory, and McpServerToolFactory - Replace manual isBlank() checks with StringHelper.defaultIfBlank() method - Simplify code and improve readability across multiple factory classes
1 parent f6f9a64 commit fa58885

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/main/java/com/github/codeboyzhou/mcp/declarative/server/factory/McpServerPromptFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected McpServerPromptFactory(Injector injector) {
3838
@Override
3939
public McpServerFeatures.AsyncPromptSpecification create(Class<?> clazz, Method method) {
4040
McpPrompt promptMethod = method.getAnnotation(McpPrompt.class);
41-
final String name = promptMethod.name().isBlank() ? method.getName() : promptMethod.name();
41+
final String name = StringHelper.defaultIfBlank(promptMethod.name(), method.getName());
4242
final String title = StringHelper.defaultIfBlank(promptMethod.title(), NO_TITLE_SPECIFIED);
4343
final String description = getDescription(promptMethod.descriptionI18nKey(), promptMethod.description());
4444
List<McpSchema.PromptArgument> promptArguments = createPromptArguments(method);

src/main/java/com/github/codeboyzhou/mcp/declarative/server/factory/McpServerResourceFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected McpServerResourceFactory(Injector injector) {
3131
@Override
3232
public McpServerFeatures.AsyncResourceSpecification create(Class<?> clazz, Method method) {
3333
McpResource res = method.getAnnotation(McpResource.class);
34-
final String name = res.name().isBlank() ? method.getName() : res.name();
34+
final String name = StringHelper.defaultIfBlank(res.name(), method.getName());
3535
final String title = StringHelper.defaultIfBlank(res.title(), NO_TITLE_SPECIFIED);
3636
final String description = getDescription(res.descriptionI18nKey(), res.description());
3737
McpSchema.Annotations annotations = new McpSchema.Annotations(List.of(res.roles()), res.priority());

src/main/java/com/github/codeboyzhou/mcp/declarative/server/factory/McpServerToolFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected McpServerToolFactory(Injector injector) {
4343
@Override
4444
public McpServerFeatures.AsyncToolSpecification create(Class<?> clazz, Method method) {
4545
McpTool toolMethod = method.getAnnotation(McpTool.class);
46-
final String name = toolMethod.name().isBlank() ? method.getName() : toolMethod.name();
46+
final String name = StringHelper.defaultIfBlank(toolMethod.name(), method.getName());
4747
final String title = StringHelper.defaultIfBlank(toolMethod.title(), NO_TITLE_SPECIFIED);
4848
final String description = getDescription(toolMethod.descriptionI18nKey(), toolMethod.description());
4949
McpSchema.JsonSchema paramSchema = createJsonSchema(method);
@@ -139,7 +139,7 @@ private Map<String, Object> createJsonSchemaDefinition(Class<?> definitionClass)
139139
fieldProperties.put("type", field.getType().getSimpleName().toLowerCase());
140140
fieldProperties.put("description", getDescription(property.descriptionI18nKey(), property.description()));
141141

142-
final String fieldName = property.name().isBlank() ? field.getName() : property.name();
142+
final String fieldName = StringHelper.defaultIfBlank(property.name(), field.getName());
143143
properties.put(fieldName, fieldProperties);
144144

145145
if (property.required()) {

0 commit comments

Comments
 (0)