Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/migration_bench/lang/java/eval/parse_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from migration_bench.common import utils


ANNOTATION = "annotation"
CLASS = "class"
ENUM = "enum"
Copy link
Copy Markdown
Contributor

@sheilaliuxl sheilaliuxl May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: They're sorted
Otherwise LGTM

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheilaliuxl thanks! should be fixed now!

INTERFACE = "interface"
METHOD = "method"

Expand All @@ -34,6 +36,12 @@ def get_classes_and_methods(filename: str, content: str = None, add_line: bool =
elif isinstance(node, javalang.tree.InterfaceDeclaration):
current_class = node.name
nodes.append((INTERFACE, current_class))
elif isinstance(node, javalang.tree.EnumDeclaration):
current_class = node.name
nodes.append((ENUM, current_class))
elif isinstance(node, javalang.tree.AnnotationDeclaration):
current_class = node.name
nodes.append((ANNOTATION, current_class))
elif isinstance(node, javalang.tree.MethodDeclaration):
if not current_class:
raise ValueError(
Expand Down
22 changes: 22 additions & 0 deletions src/migration_bench/lang/java/eval/test_parse_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

FILE_01 = "../native/src/main/java/qct/XmlBeautifier.java"
FILE_02 = "./testdata/LabelManager.java"
FILE_03 = "./testdata/Status.java"
FILE_04 = "./testdata/Marker.java"


class TestParseFile(unittest.TestCase):
Expand Down Expand Up @@ -78,6 +80,26 @@ class TestParseFile(unittest.TestCase):
("method", ("get", False)),
),
),
# Top-level enum with constants overriding an abstract method.
# Pre-fix: raised "Unable to find out class for method `describe`".
(
FILE_03,
{},
(
("enum", "Status"),
("method", ("describe", False)),
("method", ("describe", False)),
("method", ("describe", False)),
),
),
# Top-level annotation declaration.
(
FILE_04,
{},
(
("annotation", "Marker"),
Comment thread
luyuzhe111 marked this conversation as resolved.
),
),
)
)
def test_get_classes_and_methods(self, filename, kwargs, expected_nodes):
Expand Down
10 changes: 10 additions & 0 deletions src/migration_bench/lang/java/eval/testdata/Marker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example;

/**
* Top-level annotation declaration with a method element. Previously crashed
* parse_file.get_classes_and_methods because AnnotationDeclaration was not
* handled.
*/
public @interface Marker {
String value() default "";
}
23 changes: 23 additions & 0 deletions src/migration_bench/lang/java/eval/testdata/Status.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example;

/**
* Top-level enum with constants whose bodies override an abstract method.
* This shape (seen in repos like thomasmueller/tinyStats) previously crashed
* parse_file.get_classes_and_methods because EnumDeclaration was not handled.
*/
public enum Status {
OK {
@Override
public String describe() {
return "ok";
}
},
BAD {
@Override
public String describe() {
return "bad";
}
};

public abstract String describe();
}