diff --git a/data_prep/introspector.py b/data_prep/introspector.py index 07bee4179..700b78a60 100755 --- a/data_prep/introspector.py +++ b/data_prep/introspector.py @@ -504,6 +504,11 @@ def _get_exceptions(function: dict) -> List[str]: return function.get('exceptions', []) +def _is_jvm_static(function: dict) -> bool: + """Returns the static property of this function for JVM project.""" + return function.get('is_static', False) + + def _get_arg_names(function: dict, project: str, language: str) -> list[str]: """Returns the function argument names.""" if language == 'jvm': @@ -638,6 +643,7 @@ def populate_benchmarks_using_introspector(project: str, language: str, _get_clean_arg_types(function, project), _get_arg_names(function, project, language)), _get_exceptions(function), + _is_jvm_static(function), harness, target_name, function_dict=function)) diff --git a/experiment/benchmark.py b/experiment/benchmark.py index bf2f5d97b..16e524616 100644 --- a/experiment/benchmark.py +++ b/experiment/benchmark.py @@ -62,6 +62,7 @@ def to_yaml(cls, benchmarks: list[Benchmark], outdir: str = './'): 'return_type': b.return_type, 'params': b.params, 'exceptions': b.exceptions, + 'is_jvm_static': b.is_jvm_static, } for b in benchmarks], } with open(os.path.join(outdir, f'{benchmarks[0].project}.yaml'), @@ -100,6 +101,7 @@ def from_yaml(cls, benchmark_path: str) -> List: function.get('return_type'), function.get('params'), function.get('exceptions', []), + function.get('is_jvm_static', False), data['target_path'], data.get('target_name'), use_project_examples=use_project_examples, @@ -119,6 +121,7 @@ def __init__(self, return_type: str, params: list[dict[str, str]], exceptions: list[str], + is_jvm_static: bool, target_path: str, preferred_target_name: Optional[str] = None, use_project_examples=True, @@ -134,6 +137,7 @@ def __init__(self, self.return_type = return_type self.params = params self.exceptions = exceptions + self.is_jvm_static = is_jvm_static self.function_dict = function_dict self.target_path = target_path self._preferred_target_name = preferred_target_name diff --git a/llm_toolkit/prompt_builder.py b/llm_toolkit/prompt_builder.py index 2ba512646..1dff9011e 100644 --- a/llm_toolkit/prompt_builder.py +++ b/llm_toolkit/prompt_builder.py @@ -737,6 +737,18 @@ def _format_requirement(self, signature: str) -> str: else: requirement = requirement.replace('{HARNESS_NAME}', 'Fuzz') + class_name = self.benchmark.function_name[1:].split(']')[0] + if '' in self.benchmark.function_name: + creation = (f'The target method is a constructor of {class_name} ' + 'invoke it directly with new keyword.') + elif self.benchmark.is_jvm_static: + creation = ('The target method is a static method, invoke it directly ' + 'without creating an object.') + else: + creation = (f'You must create the {class_name} object before calling ' + 'the target method.') + requirement = requirement.replace('{STATIC_OR_INSTANCE}', creation) + return requirement def _format_data_filler(self) -> str: diff --git a/prompts/template_xml/jvm_requirement.txt b/prompts/template_xml/jvm_requirement.txt index a4e4e86f3..a8cde9887 100644 --- a/prompts/template_xml/jvm_requirement.txt +++ b/prompts/template_xml/jvm_requirement.txt @@ -10,6 +10,7 @@ Please add import statements for necessary classes, except for classes in the java.lang package. You must create the object before calling the target method. Please use {HARNESS_NAME} as the Java class name. +{STATIC_OR_INSTANCE} Do not create new variables with the same names as existing variables. WRONG: