You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2026/05/13 10:24:55 UTC

(sling-whiteboard) branch master updated: Look for @Component annotation anywhere prior to class declaration

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 dd320067 Look for @Component annotation anywhere prior to class declaration
dd320067 is described below

commit dd320067b55ded0c3eecac740b3c496148b07b16
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Sat May 9 18:29:02 2026 +0200

    Look for @Component annotation anywhere prior to class declaration
    
    Not just in the 20 lines before class declaration, as it can be further up in the file.
    Print warning and skip metatype generation if @Component annotation or class declaration cannot be found.
---
 skills/osgi-scr-migrator/scripts/migrate_annotations.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/skills/osgi-scr-migrator/scripts/migrate_annotations.py b/skills/osgi-scr-migrator/scripts/migrate_annotations.py
index 3378f110..8c647bc2 100755
--- a/skills/osgi-scr-migrator/scripts/migrate_annotations.py
+++ b/skills/osgi-scr-migrator/scripts/migrate_annotations.py
@@ -944,16 +944,19 @@ class AnnotationMigrator:
                 break
 
         if class_idx is None:
+            print(f"Warning: Could not find class declaration for {self.component_name}, skipping metatype generation")
             return
 
         # Find the @Component annotation
         component_idx = None
-        for i in range(class_idx - 1, max(0, class_idx - 20), -1):
+        # must be somewhere between start of file and class declaration, look backwards from class declaration
+        for i in range(class_idx - 1, 0, -1): 
             if '@Component' in self.lines[i]:
                 component_idx = i
                 break
 
         if component_idx is None:
+            print(f"Warning: Could not find @Component annotation for {self.component_name}, skipping metatype generation")
             return
 
         # Add @Designate annotation before @Component