@@ -431,6 +431,55 @@ TEST(java_interface) {
431431 PASS ();
432432}
433433
434+ /* Regression for #1234: Java interface/enum methods were emitted as both a
435+ * Method node (correct, via extract_class_methods) and a duplicate Function
436+ * node (incorrect, via walk_defs). Prevention in push_class_body_children
437+ * (gated to Java) recognizes interface_body and enum_body as class body
438+ * containers, stopping the fallback path from re-walking method_declaration
439+ * children as top-level functions. */
440+ TEST (java_interface_no_duplicate_function_issue1234 ) {
441+ CBMFileResult * r =
442+ extract ("public interface MarketplaceService {\n"
443+ " ReservationDTO createReservation(Authentication auth, RequestDTO req);\n"
444+ " void cancelReservation(long id);\n"
445+ "}\n" ,
446+ CBM_LANG_JAVA , "t" , "MarketplaceService.java" );
447+ ASSERT_NOT_NULL (r );
448+ ASSERT_FALSE (r -> has_error );
449+
450+ ASSERT (has_def (r , "Interface" , "MarketplaceService" ));
451+ ASSERT (has_def (r , "Method" , "createReservation" ));
452+ ASSERT (has_def (r , "Method" , "cancelReservation" ));
453+ ASSERT_EQ (count_defs_with_label (r , "Function" ), 0 );
454+
455+ cbm_free_result (r );
456+ PASS ();
457+ }
458+
459+ TEST (java_enum_dedup_preserves_calls_issue1234 ) {
460+ CBMFileResult * r =
461+ extract ("package app;\n\nenum Day {\n"
462+ " MON, TUE, WED, THU, FRI, SAT, SUN;\n\n"
463+ " public boolean isWeekend() { return this == SAT || this == SUN; }\n"
464+ " public String label() { return name().toLowerCase(); }\n}\n\n"
465+ "class DayUtil {\n"
466+ " static String describe(Day d) {\n"
467+ " return d.label() + (d.isWeekend() ? \"(rest)\" : \"(work)\");\n }\n}\n" ,
468+ CBM_LANG_JAVA , "t" , "Day.java" );
469+ ASSERT_NOT_NULL (r );
470+ ASSERT_FALSE (r -> has_error );
471+
472+ ASSERT (has_def (r , "Enum" , "Day" ));
473+ ASSERT (has_def (r , "Method" , "isWeekend" ));
474+ ASSERT (has_def (r , "Method" , "label" ));
475+ ASSERT (has_def (r , "Class" , "DayUtil" ));
476+ ASSERT (has_def (r , "Method" , "describe" ));
477+ ASSERT_EQ (count_defs_with_label (r , "Function" ), 0 );
478+
479+ cbm_free_result (r );
480+ PASS ();
481+ }
482+
434483/* Regression for #279: a Java class declaring both `extends` and
435484 * `implements` must produce one INHERITS edge per base — the extends parent
436485 * AND every implements interface — with bare type names (not the keyword
@@ -5183,6 +5232,8 @@ SUITE(extraction) {
51835232 RUN_TEST (java_class );
51845233 RUN_TEST (java_method );
51855234 RUN_TEST (java_interface );
5235+ RUN_TEST (java_interface_no_duplicate_function_issue1234 );
5236+ RUN_TEST (java_enum_dedup_preserves_calls_issue1234 );
51865237 RUN_TEST (java_class_extends_and_implements );
51875238 RUN_TEST (python_class_base_extracted_bare );
51885239 RUN_TEST (php_class );
0 commit comments