File size: 1,545 Bytes
7bd9b04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import re


def extract_java_files(patch: str) -> list[str]:
    files = set()
    for match in re.finditer(
        r"^diff --git a/(.*?\.java) b/(.*?\.java)", patch, re.MULTILINE
    ):
        files.add(match.group(2))
    for match in re.finditer(
        r"^diff --git /dev/null b/(.*?\.java)", patch, re.MULTILINE
    ):
        files.add(match.group(1))
    return sorted(files)


def extract_methods_from_patch(patch: str) -> list[str]:
    methods = set()

    for match in re.finditer(r"^@@ .+? @@\s+.*?(\w+)\s*\(", patch, re.MULTILINE):
        method_name = match.group(1)
        if method_name not in (
            "if",
            "for",
            "while",
            "switch",
            "catch",
            "class",
            "interface",
            "enum",
            "new",
            "return",
        ):
            methods.add(method_name)
    sig_pattern = re.compile(
        r"^[+]\s*(?:public|private|protected)?\s*(?:static\s+)?"
        r"(?:final\s+)?(?:synchronized\s+)?(?:abstract\s+)?"
        r"(?:<[^>]+>\s+)?"
        r"\w+(?:<[^>]*>)?(?:\[\])?\s+"
        r"(\w+)\s*\(",
        re.MULTILINE,
    )
    for match in sig_pattern.finditer(patch):
        method_name = match.group(1)
        if method_name not in (
            "if",
            "for",
            "while",
            "switch",
            "catch",
            "class",
            "interface",
            "enum",
            "new",
            "return",
        ):
            methods.add(method_name)

    return sorted(methods)