Skip to content

Commit 079516d

Browse files
author
HeZhengQing
committed
[FEAT] oc properties logic
1 parent b27f4b1 commit 079516d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

update-comment/api_comment_updater/src/injectors/code_locator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def _create_platform_locator(self, repo_config: Dict[str, Any], platform_config:
4444
elif self.platform in ["ios-ng", "oc-ng"]:
4545
from .platforms.oc_locator import OcLocator
4646
return OcLocator(repo_config, platform_config)
47+
elif self.platform in ["mac-ng", "oc-ng"]:
48+
from .platforms.oc_locator import OcLocator
49+
return OcLocator(repo_config, platform_config)
4750
else:
4851
raise ValueError(f"Unsupported platform: {self.platform}")
4952

update-comment/api_comment_updater/src/injectors/comment_injector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def _create_platform_injector(self, repo_config: Dict[str, Any], platform_config
4444
elif self.platform in ["ios-ng", "oc-ng"]:
4545
from .platforms.oc_injector import OcInjector
4646
return OcInjector(repo_config, platform_config)
47+
elif self.platform in ["mac-ng", "oc-ng"]:
48+
from .platforms.oc_injector import OcInjector
49+
return OcInjector(repo_config, platform_config)
4750
else:
4851
raise ValueError(f"Unsupported platform: {self.platform}")
4952

update-comment/api_comment_updater/src/injectors/platforms/oc_locator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ def locate_class_attribute(self, class_data: Dict[str, Any], attribute_name: str
313313
logger.info("定位到Objective-C类属性 {}.{}: {}", class_name, attribute_name, f"{file_path}:{line_num}")
314314
return (file_path, line_num)
315315

316+
# 查找getter方法
317+
if self._is_getter_method_definition(line_clean, attribute_name):
318+
logger.info("定位到Objective-C类属性getter {}.{}: {}", class_name, attribute_name, f"{file_path}:{line_num}")
319+
return (file_path, line_num)
320+
316321
# 如果遇到下一个类定义,停止搜索
317322
if line_num > class_line and ('@interface' in line_clean or '@implementation' in line_clean):
318323
break
@@ -350,6 +355,41 @@ def _is_attribute_definition_enhanced(self, line: str, attribute_name: str) -> b
350355

351356
return False
352357

358+
def _is_getter_method_definition(self, line: str, attribute_name: str) -> bool:
359+
"""
360+
判断是否为Objective-C属性getter方法定义
361+
362+
Args:
363+
line: 代码行
364+
attribute_name: 属性名
365+
366+
Returns:
367+
bool: 是否为getter方法定义
368+
"""
369+
# 检查是否以实例方法关键字开头
370+
if not line.strip().startswith('- ('):
371+
return False
372+
373+
# 检查是否包含属性名
374+
if attribute_name not in line:
375+
return False
376+
377+
# 检查是否是getter方法格式
378+
# - (ReturnType)attributeName;
379+
# - (ReturnType)attributeName:(ParamType)param;
380+
patterns = [
381+
# 无参数的getter方法
382+
rf'-\s*\([^)]+\)\s*{re.escape(attribute_name)}\s*;',
383+
# 有参数的getter方法(如indexed accessor)
384+
rf'-\s*\([^)]+\)\s*{re.escape(attribute_name)}\s*:\s*\([^)]+\)',
385+
]
386+
387+
for pattern in patterns:
388+
if re.search(pattern, line):
389+
return True
390+
391+
return False
392+
353393
def locate_enum_value(self, enum_data: Dict[str, Any], value_name: str) -> Optional[Tuple[str, int]]:
354394
"""
355395
定位枚举值在代码中的位置 - Objective-C版本

0 commit comments

Comments
 (0)