This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 12dc9753 fix(migrate_annotations): enhance property name extraction 
from non-private static final fields
12dc9753 is described below

commit 12dc97534097ea19f83cf60021ad422c1744653c
Author: Konrad Windszus <[email protected]>
AuthorDate: Sat May 9 18:50:03 2026 +0200

    fix(migrate_annotations): enhance property name extraction from non-private 
static final fields
---
 .../scripts/migrate_annotations.py                 |  5 +-
 .../scripts/tests/test_migrate_annotations.py      | 60 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/skills/osgi-scr-migrator/scripts/migrate_annotations.py 
b/skills/osgi-scr-migrator/scripts/migrate_annotations.py
index 8c647bc2..38666311 100755
--- a/skills/osgi-scr-migrator/scripts/migrate_annotations.py
+++ b/skills/osgi-scr-migrator/scripts/migrate_annotations.py
@@ -425,13 +425,14 @@ class AnnotationMigrator:
             # Look for the field declaration on the next line(s) after the 
annotation
             for i in range(idx, min(idx + 3, len(self.lines))):
                 field_line = self.lines[i]
-                # Match: private static final String FIELD_NAME = 
"property.name";
-                field_match = 
re.search(r'private\s+static\s+final\s+String\s+\w+\s*=\s*"([^"]+)"', 
field_line)
+                # Match: [private|protected|public] static final String 
FIELD_NAME = "property.name";
+                field_match = 
re.search(r'(?:(?:private|protected|public)\s+)?static\s+final\s+String\s+\w+\s*=\s*"([^"]+)"',
 field_line)
                 if field_match:
                     property_name = field_match.group(1)
                     break
 
         if not property_name:
+            print(f"Warning: Could not extract property name from annotation 
in {self.file_path}: {annotation}")
             return None
 
         prop = Property(name=property_name)
diff --git a/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py 
b/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py
index 8c4221b6..42c5f2b0 100644
--- a/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py
+++ b/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py
@@ -114,6 +114,66 @@ class TestPropertyParsing(unittest.TestCase):
         self.assertEqual(prop.description, "Request timeout in seconds")
         self.assertTrue(prop.is_configurable)
 
+    def test_property_name_derived_from_default_static_final_field(self):
+        """Test deriving property name from package-private static final 
field."""
+        content = '''
+@Property(value = "Apache Software Foundation")
+static final String SERVICE_VENDOR = "service.vendor";
+'''
+        stats = MigrationStats()
+        migrator = AnnotationMigrator(content, Path("test.java"), stats)
+        migrator._collect_properties()
+
+        self.assertEqual(len(migrator.component_properties), 1)
+        prop = migrator.component_properties[0]
+        self.assertEqual(prop.name, "service.vendor")
+        self.assertEqual(prop.value, "Apache Software Foundation")
+
+    def test_property_name_derived_from_private_static_final_field(self):
+        """Test deriving property name from private static final field."""
+        content = '''
+@Property(value = "Apache Software Foundation")
+private static final String SERVICE_VENDOR = "service.vendor";
+'''
+        stats = MigrationStats()
+        migrator = AnnotationMigrator(content, Path("test.java"), stats)
+        migrator._collect_properties()
+
+        self.assertEqual(len(migrator.component_properties), 1)
+        prop = migrator.component_properties[0]
+        self.assertEqual(prop.name, "service.vendor")
+        self.assertEqual(prop.value, "Apache Software Foundation")
+
+    def test_property_name_derived_from_protected_static_final_field(self):
+        """Test deriving property name from protected static final field."""
+        content = '''
+@Property(value = "Apache Software Foundation")
+protected static final String SERVICE_VENDOR = "service.vendor";
+'''
+        stats = MigrationStats()
+        migrator = AnnotationMigrator(content, Path("test.java"), stats)
+        migrator._collect_properties()
+
+        self.assertEqual(len(migrator.component_properties), 1)
+        prop = migrator.component_properties[0]
+        self.assertEqual(prop.name, "service.vendor")
+        self.assertEqual(prop.value, "Apache Software Foundation")
+
+    def test_property_name_derived_from_public_static_final_field(self):
+        """Test deriving property name from public static final field."""
+        content = '''
+@Property(value = "Apache Software Foundation")
+public static final String SERVICE_VENDOR = "service.vendor";
+'''
+        stats = MigrationStats()
+        migrator = AnnotationMigrator(content, Path("test.java"), stats)
+        migrator._collect_properties()
+
+        self.assertEqual(len(migrator.component_properties), 1)
+        prop = migrator.component_properties[0]
+        self.assertEqual(prop.name, "service.vendor")
+        self.assertEqual(prop.value, "Apache Software Foundation")
+
 
 class TestPropertyConversion(unittest.TestCase):
     """Test property conversion to OSGi R6/R7 format."""

Reply via email to