@@ -165,31 +165,41 @@ def _map_jvm_to_class_resource(
165165 to_resource , from_resources , from_classes_index , jvm_lang : jvm .JvmLanguage
166166):
167167 for extension in jvm_lang .source_extensions :
168- normalized_path = jvm_lang .get_normalized_path (
168+ # Perform basic conversion from .class to source file path
169+ source_path = jvm_lang .get_source_path (
169170 path = to_resource .path , extension = extension
170171 )
172+ # Perform basic mapping without normalization for scenarios listed in
173+ # https://github.com/aboutcode-org/scancode.io/issues/1873
174+ match = pathmap .find_paths (path = source_path , index = from_classes_index )
171175
172- match = pathmap .find_paths (path = normalized_path , index = from_classes_index )
173-
174- if not match and jvm_lang .name == "scala" :
175- package_path = str (Path (to_resource .path ).parent )
176- potential_sources = from_resources .filter (
177- path__startswith = package_path .replace ("to/" , "from/" ),
178- extension__in = jvm_lang .source_extensions ,
176+ if not match :
177+ normalized_path = jvm_lang .get_normalized_path (
178+ path = to_resource .path , extension = extension
179179 )
180- for from_resource in potential_sources :
181- from_source_root_parts = from_resource .path .strip ("/" ).split ("/" )
182- from_source_root = "/" .join (from_source_root_parts [:- 1 ])
183- pipes .make_relation (
184- from_resource = from_resource ,
185- to_resource = to_resource ,
186- map_type = jvm_lang .binary_map_type ,
187- extra_data = {"from_source_root" : f"{ from_source_root } /" },
180+ match = pathmap .find_paths (path = normalized_path , index = from_classes_index )
181+
182+ # Scala fallback for case classes and inner classes
183+ # https://github.com/aboutcode-org/scancode.io/issues/1875
184+ if not match and jvm_lang .name == "scala" :
185+ package_path = str (Path (to_resource .path ).parent )
186+ potential_sources = from_resources .filter (
187+ path__startswith = package_path .replace ("to/" , "from/" ),
188+ extension__in = jvm_lang .source_extensions ,
188189 )
189- continue
190+ for from_resource in potential_sources :
191+ from_source_root_parts = from_resource .path .strip ("/" ).split ("/" )
192+ from_source_root = "/" .join (from_source_root_parts [:- 1 ])
193+ pipes .make_relation (
194+ from_resource = from_resource ,
195+ to_resource = to_resource ,
196+ map_type = jvm_lang .binary_map_type ,
197+ extra_data = {"from_source_root" : f"{ from_source_root } /" },
198+ )
199+ continue
190200
191- if not match :
192- continue
201+ if not match :
202+ continue
193203
194204 for resource_id in match .resource_ids :
195205 from_resource = from_resources .get (id = resource_id )
0 commit comments