tokens space "[ \t ]+" newline "\n" | " " | " \n" id "[$\u][$\i]*" number "\d+[lL]?" | "\d+.\d*([eE][+-]?\d+)?[fFdD]?" | ".\d+([eE][+-]?\d+)?[fFdD]?" | "\d+[eE][+-]?\d+[fFdD]?" | "\d+([eE][+-]?\d+)?[fFdD]" | "0[xX][\dabcdefABCDEF]+.[pP][+-]?\d+[fFdD]?" | "0[xX][\dabcdefABCDEF]*.[\dabcdefABCDEF]+[pP][+-]?\d+[fFdD]?" | "0[xX][\dabcdefABCDEF]+([pP][+-]?\d+)?[lLfFdD]?" end tokens comments // /* */ end comments compounds != '%= && &= *= ++ += -- -= /= ^= |= || << <<= <= == >= ... end compounds keys 'abstract 'assert 'boolean 'break 'byte 'case 'catch 'char 'class 'const 'continue 'default 'do 'double 'else 'extends 'false 'final 'finally 'float 'for 'goto 'if 'implements 'import 'instanceof 'int 'interface 'long 'native 'new 'null 'package 'private 'protected 'public 'return 'short 'static 'strictfp 'switch 'synchronized 'throw 'throws 'transient 'true 'try 'void 'volatile 'while 'enum end keys define program [package_declaration] end define define package_declaration [opt package_header] [repeat import_declaration] [repeat type_declaration] end define define package_header [repeat annotation] 'package [package_name] '; [NL] [NL] end define define package_name [qualified_name] end define define import_declaration 'import [opt 'static] [imported_name] '; [NL] | '; [NL] end define define imported_name [package_or_type_name] [opt dot_star] end define define package_or_type_name [qualified_name] end define define dot_star '. '* end define define declared_name [id] [opt generic_parameter] end define define type_declaration [class_declaration] [NL] [NL] | [interface_declaration] [NL] [NL] | [enum_declaration] [NL] end define define class_declaration [class_header] [class_body] end define define class_header [repeat modifier] 'class [class_name] [opt extends_clause] [opt implements_clause] end define define class_body [class_or_interface_body] end define define interface_declaration [interface_header] [interface_body] end define define interface_header [repeat modifier] [opt annot_marker] 'interface [interface_name] [opt extends_clause] [opt implements_clause] end define define annot_marker '@ end define define interface_body [class_or_interface_body] end define define enum_declaration [enum_header] [enum_body] end define define enum_header [repeat modifier] [opt id] 'enum [opt declared_name] [opt extends_clause] [opt implements_clause] end define define enum_body '{ [IN] [list enum_element] [opt ',] [repeat class_body_declaration] [EX] '} [opt ';] [NL] [NL] end define define enum_element [NL] [id] [opt method_argument] end define define modifier 'abstract | 'final | 'public | 'protected | 'private | 'static | 'transient | 'volatile | 'native | 'synchronized | 'strictfp | [annotation] end define define extends_clause 'extends [list type_name +] end define define implements_clause 'implements [list qualified_name +] end define define class_name [declared_name] end define define interface_name [declared_name] end define define class_or_interface_body '{ [NL] [IN] [repeat class_body_declaration] [EX] '} [opt ';] [NL] [NL] end define define class_body_declaration [empty_declaration] | [member_declaration] | [instance_initializer] | [static_initializer] | [field_declaration] end define define empty_declaration '; [NL] end define define member_declaration [method_or_constructor_declaration] | [type_declaration] end define define method_or_constructor_declaration [method_declaration] | [constructor_declaration] end define define instance_initializer [NL] [block] [NL] [NL] end define define static_initializer [NL] 'static [block] [NL] [NL] end define define constructor_declaration [NL] [repeat modifier] [opt generic_parameter] [constructor_declarator] [opt throws] [constructor_body] [NL] [NL] end define define constructor_declarator [class_name] '( [list formal_parameter] ') end define define constructor_body [block] [NL] end define define field_declaration [variable_declaration] end define define variable_declaration [repeat modifier] [type_specifier] [variable_declarators] '; [NL] end define define variable_declarators [list variable_declarator +] end define define variable_declarator [variable_name] [opt equals_variable_initializer] end define define variable_name [declared_name] [repeat dimension] end define define equals_variable_initializer '= [variable_initializer] end define define variable_initializer [expression] | [array_initializer] | [id] '( ') [block] end define define array_initializer '{ [list variable_initializer] [opt ',] '} end define define method_declaration [NL] [repeat modifier] [opt generic_parameter] [type_specifier] [method_declarator] [opt throws] [method_body] end define define method_declarator [method_name] '( [list formal_parameter] ') [repeat dimension] end define define method_name [declared_name] end define define formal_parameter [opt 'final] [type_specifier] [opt var_arg_specifier] [formal_parameter_name] end define define var_arg_specifier '... end define define formal_parameter_name [variable_name] end define define throws 'throws [list qualified_name +] end define define method_body [block] [NL] [NL] | [opt annotation_default] '; [NL] [NL] end define define annotation_default 'default [expression] | 'default [array_initializer] end define define type_specifier [type_name] | [array_type_specifier] end define define array_type_specifier [type_name] [repeat dimension +] end define define type_name [primitive_type] | [qualified_name] end define define primitive_type 'boolean | 'char | 'byte | 'short | 'int | 'long | 'float | 'double | 'void end define define annotation [SPOFF] '@ [reference] [SPON] [opt annotation_value_spec] [NL] end define define annotation_value_spec '( [annotation_value_list] ') end define define annotation_value_list [single_annotation_value] | [list keyed_annotation_value] end define define single_annotation_value [expression] | [nested_annotation] | { [list expression_or_nested_annotation] } end define define nested_annotation [annotation] end define define expression_or_nested_annotation [expression] | [nested_annotation] end define define keyed_annotation_value [id] '= [single_annotation_value] end define define block '{ [NL] [IN] [repeat declaration_or_statement] [EX] '} end define define declaration_or_statement [local_variable_declaration] | [class_declaration] | [statement] end define define local_variable_declaration [variable_declaration] end define define statement [label_statement] | [empty_statement] | [expression_statement] | [if_statement] | [switch_statement] | [while_statement] | [do_statement] | [for_statement] | [for_in_statement] | [break_statement] | [continue_statement] | [return_statement] | [throw_statement] | [synchronized_statement] | [try_statement] | [assert_statement] | [block] end define define empty_statement '; [NL] end define define label_statement [label_name] ': [statement] end define define label_name [reference] end define define expression_statement [expression] '; [NL] end define define if_statement 'if '( [expression] ') [statement] [opt else_clause] [NL] end define define else_clause 'else [statement] end define define switch_statement 'switch '( [expression] ') [switch_block] [NL] end define define switch_block '{ [IN] [NL] [repeat switch_alternative] [EX] '} end define define switch_alternative [switch_label] [IN] [NL] [repeat declaration_or_statement] [EX] end define define switch_label 'case [constant_expression] ': | 'default ': end define define while_statement 'while '( [expression] ') [statement] [NL] end define define do_statement 'do [statement] 'while '( [expression] ') '; [NL] end define define for_statement 'for '( [for_init] [for_expression] [for_update] ') [statement] [NL] end define define for_init [list expression] '; | [local_variable_declaration] end define define for_expression [opt expression] '; end define define for_update [list expression] end define define for_in_statement 'for '( [for_in_init] : [expression] ') [statement] [NL] end define define for_in_init [repeat modifier] [type_specifier] [variable_name] end define define break_statement 'break [opt label_name] '; [NL] end define define continue_statement 'continue [opt label_name] '; [NL] end define define return_statement 'return [opt expression] '; [NL] end define define throw_statement 'throw [expression] '; [NL] end define define synchronized_statement 'synchronized '( [expression] ') [statement] [NL] end define define try_statement 'try [block] [repeat catch_clause] [opt finally_clause] [NL] end define define catch_clause 'catch '( [repeat modifier] [type_specifier] [variable_name] ') [block] end define define finally_clause 'finally [block] end define define assert_statement 'assert [expression] [opt assert_error_code] '; [NL] end define define assert_error_code ': [expression] end define define constant_expression [expression] end define define expression [assignment_expression] end define define assignment_expression [conditional_expression] | [unary_expression] [assignment_operator] [assignment_expression] end define define assignment_operator '= | '*= | '/= | '%= | '+= | '-= | '<<= | [SPOFF] '> '>= [SPON] | [SPOFF] '> '> '>= [SPON] | '&= | '^= | '|= end define define conditional_expression [conditional_or_expression] [opt conditional_choice] end define define conditional_choice '? [expression] ': [conditional_expression] end define define conditional_or_expression [conditional_and_expression] [repeat or_conditional_and_expression] end define define or_conditional_and_expression '|| [conditional_and_expression] end define define conditional_and_expression [inclusive_or_expression] [repeat and_inclusive_or_expression] end define define and_inclusive_or_expression '&& [inclusive_or_expression] end define define inclusive_or_expression [exclusive_or_expression] [repeat or_exclusive_or_expression] end define define or_exclusive_or_expression '| [exclusive_or_expression] end define define exclusive_or_expression [and_expression] [repeat or_and_expression] end define define or_and_expression '^ [and_expression] end define define and_expression [equality_expression] [repeat and_equality_expression] end define define and_equality_expression '& [equality_expression] end define define equality_expression [relational_expression] [repeat equality_op_relational_expression] end define define equality_op_relational_expression [equality_op] [relational_expression] end define define equality_op '== | '!= end define define relational_expression [shift_expression] [repeat relational_op_shift_expression] end define define relational_op_shift_expression [relational_op] [shift_expression] | 'instanceof [type_specifier] end define define relational_op '< | '> | '<= | '>= end define define shift_expression [additive_expression] [repeat shift_additive_expression] end define define shift_additive_expression [shift_op] [additive_expression] end define define shift_op '<< | [SPOFF] '> '> [SPON] | [SPOFF] '> '> '> [SPON] end define define additive_expression [multiplicative_expression] [repeat add_op_multiplicative_expression] end define define add_op_multiplicative_expression [add_op] [multiplicative_expression] end define define add_op '+ | '- end define define multiplicative_expression [unary_expression] [repeat mult_op_unary_expression] end define define mult_op_unary_expression [mult_op] [unary_expression] end define define mult_op '* | '/ | '% end define define unary_expression [pre_inc_dec] [unary_expression] | [unary_op] [unary_expression] | [postfix_expression] | [cast_expression] end define define pre_inc_dec '++ | '-- end define define unary_op '+ | '- | '~ | '! end define define cast_expression '( [type_specifier] ') [unary_expression] end define define postfix_expression [primary] [repeat post_inc_dec] end define define post_inc_dec '++ | '-- end define define subscript '[ [expression] '] end define define primary [literal] [repeat component] | [reference] | '( [expression] ') [repeat component] | [class_instance_creation_expression] [repeat component] | [array_creation_expression] [repeat component] end define define literal [numeric_literal] | [character_literal] | [string_literal] | [boolean_literal] | [null_literal] end define define numeric_literal [number] end define define character_literal [charlit] end define define string_literal [stringlit] end define define boolean_literal 'true | 'false end define define null_literal 'null end define define class_instance_creation_expression 'new [class_or_interface_name] '( [list argument] ') [opt class_body] end define define class_or_interface_name [id] [repeat class_or_interface_component] end define define class_or_interface_component [dot_id] | '. [generic_argument] | [generic_argument] end define define array_creation_expression 'new [array_type_specifier] [opt array_initializer] end define define dimension '[ [opt expression] '] end define define argument [expression] | [type_specifier] end define define qualified_name [reference] end define define reference [id] [repeat dimension] [repeat component] | [primitive_type] [repeat dimension] [repeat component] end define define component [dot_id] | [method_argument] | [subscript] | [generic_argument] | '. [class_instance_declaration] end define define class_instance_declaration [class_instance_creation_expression] | 'class end define define method_argument '( [list argument] ') end define define dot_id '. [id] | '. 'class end define define generic_argument '< [list type_argument] '> end define define type_argument [type_specifier] | [wildcard_type] end define define wildcard_type '? [opt wildcard_type_bound] | [id] [opt wildcard_type_bound] end define define wildcard_type_bound 'extends [type_specifier] | 'super [type_specifier] end define define generic_parameter < [list type_parameter] > end define define type_parameter [declared_name] [opt type_bound_clause] end define define type_bound_clause 'extends [type_bound] end define define type_bound [type_specifier] [repeat and_type_spec] end define define and_type_spec '& [type_specifier] end define redefine enum_element [comment_nl] ... end define redefine type_declaration [comment_nl] [NL] ... end define redefine type_specifier ... [comment_nl] end define redefine add_op_multiplicative_expression [add_op] [multiplicative_expression] [comment_nl] end define redefine statement ... [comment_nl] end define redefine expression_statement [expression] '; [comment_nl] end define redefine statement [comment_nl] ... end define redefine package_declaration [comment_nl] [NL] ... end define redefine class_body_declaration [comment_nl] ... end define redefine import_declaration [comment_nl] ... end define redefine type_declaration ... [comment_nl] end define redefine class_or_interface_body '{ [NL] [IN] [comment_nl] [repeat class_body_declaration] [EX] [comment_nl] '} [opt ';] [comment_nl] [NL] [NL] end define redefine variable_initializer ... [comment_nl] end define redefine variable_initializer [comment_nl] ... end define redefine variable_declarator ... [comment_nl] end define redefine equals_variable_initializer [comment_nl] ... end define redefine equals_variable_initializer ... [comment_nl] end define redefine formal_parameter ... [comment_nl] end define redefine formal_parameter [comment_nl] ... end define redefine constructor_declarator ... [comment_nl] end define redefine method_declarator ... [comment_nl] end define redefine argument ... [comment_nl] end define redefine argument [comment_nl] ... end define redefine method_argument ... [comment_nl] end define redefine if_statement 'if '( [expression] ') [comment_nl] [statement] [opt else_clause] [NL] end define redefine block '{ [NL] [IN] [comment_nl] [EX] '} [NL] | '{ [NL] [IN] [comment_nl] [repeat declaration_or_statement +] [EX] [comment_nl] '} [NL] end define redefine declaration_or_statement ... [comment_nl] [NL] end define redefine declaration_or_statement [comment_nl] [NL] ... end define redefine expression ... [comment_nl] end define redefine expression [comment_nl] ... end define define mycomment [comment] end define define comment_nl [empty] | [repeat mycomment] end define redefine block '{ [NL] [IN] [repeat declaration_or_statement] [EX] '} end define redefine type_declaration [class_declaration] [NL] [NL] [comment_nl] | [interface_declaration] [NL] [NL] [comment_nl] | [enum_declaration] [NL] [comment_nl] end define redefine import_declaration [comment_nl] 'import [opt 'static] [imported_name] '; [NL] [comment_nl] | [comment_nl] '; [NL] [comment_nl] end define redefine program [package_declaration] | [class_body_declaration] end define redefine comment_nl [my_comment] end define define my_comment [repeat comment] end define keys <<<<<< >>>>>> end keys compounds <<<<<< >>>>>> end compounds define Change [NL] <<<<<< [opt stringlit] [NL] | [NL] >>>>>> [opt stringlit] [NL] end define redefine package_header ... | [attr Change] end define function find_replace_package_header replace [program] P [ program ] import Program_Diff [program] construct S [package_header *] _ [ find_clones_package_header P Program_Diff ] construct P3 [program] P [mark_clones_package_header each S] by P3 end function function find_clones_package_header P [program] P2 [program] replace [package_header *] _ [ package_header * ] construct S [package_header *] _ [ ^ P ] by _ [add_if_clones_package_header1 P2 each S] end function function add_if_clones_package_header1 P2 [program] Stmt [package_header] construct S2 [package_header *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ package_header * ] replace [package_header *] StructuredClones [ package_header * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_package_header S [package_header] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [package_header] >>>>>> C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [package_header] <<<<<< C by P [ $ S S1 ] end function redefine import_declaration ... | [attr Change] end define function find_replace_import_declaration replace [program] P [ program ] import Program_Diff [program] construct S [import_declaration *] _ [ find_clones_import_declaration P Program_Diff ] construct P3 [program] P [mark_clones_import_declaration each S] by P3 end function function find_clones_import_declaration P [program] P2 [program] replace [import_declaration *] _ [ import_declaration * ] construct S [import_declaration *] _ [ ^ P ] by _ [add_if_clones_import_declaration1 P2 each S] end function function add_if_clones_import_declaration1 P2 [program] Stmt [import_declaration] construct S2 [import_declaration *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ import_declaration * ] replace [import_declaration *] StructuredClones [ import_declaration * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_import_declaration S [import_declaration] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [import_declaration] >>>>>> C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [import_declaration] <<<<<< C by P [ $ S S1 ] end function redefine type_declaration ... | [attr Change] end define function find_replace_type_declaration replace [program] P [ program ] import Program_Diff [program] construct S [type_declaration *] _ [ find_clones_type_declaration P Program_Diff ] construct P3 [program] P [mark_clones_type_declaration each S] by P3 end function function find_clones_type_declaration P [program] P2 [program] replace [type_declaration *] _ [ type_declaration * ] construct S [type_declaration *] _ [ ^ P ] by _ [add_if_clones_type_declaration1 P2 each S] end function function add_if_clones_type_declaration1 P2 [program] Stmt [type_declaration] construct S2 [type_declaration *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ type_declaration * ] replace [type_declaration *] StructuredClones [ type_declaration * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_type_declaration S [type_declaration] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [type_declaration] >>>>>> C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [type_declaration] <<<<<< C by P [ $ S S1 ] end function redefine class_body_declaration ... | [attr Change] end define function find_replace_class_body_declaration replace [program] P [ program ] import Program_Diff [program] construct S [class_body_declaration *] _ [ find_clones_class_body_declaration P Program_Diff ] construct P3 [program] P [mark_clones_class_body_declaration each S] by P3 end function function find_clones_class_body_declaration P [program] P2 [program] replace [class_body_declaration *] _ [ class_body_declaration * ] construct S [class_body_declaration *] _ [ ^ P ] by _ [add_if_clones_class_body_declaration1 P2 each S] end function function add_if_clones_class_body_declaration1 P2 [program] Stmt [class_body_declaration] construct S2 [class_body_declaration *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ class_body_declaration * ] replace [class_body_declaration *] StructuredClones [ class_body_declaration * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_class_body_declaration S [class_body_declaration] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [class_body_declaration] >>>>>> C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [class_body_declaration] <<<<<< C by P [ $ S S1 ] end function redefine declaration_or_statement ... | [attr Change] end define function find_replace_declaration_or_statement replace [program] P [ program ] import Program_Diff [program] construct S [declaration_or_statement *] _ [ find_clones_declaration_or_statement P Program_Diff ] construct P3 [program] P [mark_clones_declaration_or_statement each S] by P3 end function function find_clones_declaration_or_statement P [program] P2 [program] replace [declaration_or_statement *] _ [ declaration_or_statement * ] construct S [declaration_or_statement *] _ [ ^ P ] by _ [add_if_clones_declaration_or_statement1 P2 each S] end function function add_if_clones_declaration_or_statement1 P2 [program] Stmt [declaration_or_statement] construct S2 [declaration_or_statement *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ declaration_or_statement * ] replace [declaration_or_statement *] StructuredClones [ declaration_or_statement * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_declaration_or_statement S [declaration_or_statement] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [declaration_or_statement] >>>>>> C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [declaration_or_statement] <<<<<< C by P [ $ S S1 ] end function redefine package_declaration ... | [attr Change] end define function find_replace_package_declaration replace [program] P [ program ] import Program_Diff [program] construct S [package_declaration *] _ [ find_clones_package_declaration P Program_Diff ] construct P3 [program] P [mark_clones_package_declaration each S] by P3 end function function find_clones_package_declaration P [program] P2 [program] replace [package_declaration *] _ [ package_declaration * ] construct S [package_declaration *] _ [ ^ P ] by _ [add_if_clones_package_declaration1 P2 each S] end function function add_if_clones_package_declaration1 P2 [program] Stmt [package_declaration] construct S2 [package_declaration *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ package_declaration * ] replace [package_declaration *] StructuredClones [ package_declaration * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_package_declaration S [package_declaration] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [package_declaration] >>>>>> C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [package_declaration] <<<<<< C by P [ $ S S1 ] end function redefine my_comment ... | [attr Change] end define function find_replace_my_comment replace [program] P [ program ] import Program_Diff [program] construct S [my_comment *] _ [ find_clones_my_comment P Program_Diff ] construct P3 [program] P [mark_clones_my_comment each S] by P3 end function function find_clones_my_comment P [program] P2 [program] replace [my_comment *] _ [ my_comment * ] construct S [my_comment *] _ [ ^ P ] by _ [add_if_clones_my_comment1 P2 each S] end function function add_if_clones_my_comment1 P2 [program] Stmt [my_comment] construct S2 [my_comment *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ my_comment * ] replace [my_comment *] StructuredClones [ my_comment * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_my_comment S [my_comment] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [my_comment] >>>>>> C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [my_comment] <<<<<< C by P [ $ S S1 ] end function rule normalise_list_package_declaration_import_declaration replace [repeat import_declaration] N1 [import_declaration] N2 [import_declaration] Rest [repeat import_declaration] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_id_by3_declared_name1 replace [declared_name *] P1 [declared_name] P2 [declared_name *] deconstruct P1 X8 [id] X9 [opt generic_parameter] deconstruct * [id] X8 X8_x1 [id] construct X8_d1 [id *] _ [ . ' declared_name ] [ . X8_x1 ] [ print ] by P2 end rule function normalise_id_by4_declared_name1 replace [program] P1 [ program ] construct Element [declared_name *] _ [ ^ P1 ] construct d_Element [declared_name *] Element [ normalise_id_by3_declared_name1 ] by P1 end function rule normalise_list_class_header_modifier replace [repeat modifier] N1 [modifier] N2 [modifier] Rest [repeat modifier] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_list_interface_header_modifier replace [repeat modifier] N1 [modifier] N2 [modifier] Rest [repeat modifier] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_list_enum_header_modifier replace [repeat modifier] N1 [modifier] N2 [modifier] Rest [repeat modifier] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_list_enum_body_class_body_declaration replace [repeat class_body_declaration] N1 [class_body_declaration] N2 [class_body_declaration] Rest [repeat class_body_declaration] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_id_by3_enum_element1 replace [enum_element *] P1 [enum_element] P2 [enum_element *] deconstruct P1 X10 [id] X11 [opt method_argument] deconstruct * [id] X10 X10_x1 [id] construct X10_d1 [id *] _ [ . ' enum_element ] [ . X10_x1 ] [ print ] by P2 end rule function normalise_id_by4_enum_element1 replace [program] P1 [ program ] construct Element [enum_element *] _ [ ^ P1 ] construct d_Element [enum_element *] Element [ normalise_id_by3_enum_element1 ] by P1 end function rule normalise_list_extends_clause_type_name replace [list type_name +] N1 [type_name] , N2 [type_name] , Rest [list type_name +] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 , N1 , Rest end rule rule normalise_list_implements_clause_qualified_name replace [list qualified_name +] N1 [qualified_name] , N2 [qualified_name] , Rest [list qualified_name +] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 , N1 , Rest end rule rule normalise_list_class_or_interface_body_class_body_declaration replace [repeat class_body_declaration] N1 [class_body_declaration] N2 [class_body_declaration] Rest [repeat class_body_declaration] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_list_constructor_declaration_modifier replace [repeat modifier] N1 [modifier] N2 [modifier] Rest [repeat modifier] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_list_variable_declaration_modifier replace [repeat modifier] N1 [modifier] N2 [modifier] Rest [repeat modifier] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_list_variable_declarators_variable_declarator replace [list variable_declarator +] N1 [variable_declarator] , N2 [variable_declarator] , Rest [list variable_declarator +] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 , N1 , Rest end rule rule normalise_id_by3_variable_initializer1 replace [variable_initializer *] P1 [variable_initializer] P2 [variable_initializer *] deconstruct P1 X12 [id] '( ') X13 [block] deconstruct * [id] X12 X12_x1 [id] construct X12_d1 [id *] _ [ . ' variable_initializer ] [ . X12_x1 ] [ print ] by P2 end rule function normalise_id_by4_variable_initializer1 replace [program] P1 [ program ] construct Element [variable_initializer *] _ [ ^ P1 ] construct d_Element [variable_initializer *] Element [ normalise_id_by3_variable_initializer1 ] by P1 end function rule normalise_list_method_declaration_modifier replace [repeat modifier] N1 [modifier] N2 [modifier] Rest [repeat modifier] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule rule normalise_list_throws_qualified_name replace [list qualified_name +] N1 [qualified_name] , N2 [qualified_name] , Rest [list qualified_name +] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 , N1 , Rest end rule rule normalise_list_annotation_value_list_keyed_annotation_value replace [list keyed_annotation_value] N1 [keyed_annotation_value] , N2 [keyed_annotation_value] , Rest [list keyed_annotation_value] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 , N1 , Rest end rule rule normalise_list_single_annotation_value_expression_or_nested_annotation replace [list expression_or_nested_annotation] N1 [expression_or_nested_annotation] , N2 [expression_or_nested_annotation] , Rest [list expression_or_nested_annotation] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 , N1 , Rest end rule rule normalise_id_by3_keyed_annotation_value1 replace [keyed_annotation_value *] P1 [keyed_annotation_value] P2 [keyed_annotation_value *] deconstruct P1 X14 [id] '= X15 [single_annotation_value] deconstruct * [id] X14 X14_x1 [id] construct X14_d1 [id *] _ [ . ' keyed_annotation_value ] [ . X14_x1 ] [ print ] by P2 end rule function normalise_id_by4_keyed_annotation_value1 replace [program] P1 [ program ] construct Element [keyed_annotation_value *] _ [ ^ P1 ] construct d_Element [keyed_annotation_value *] Element [ normalise_id_by3_keyed_annotation_value1 ] by P1 end function rule normalise_id_by3_class_or_interface_name1 replace [class_or_interface_name *] P1 [class_or_interface_name] P2 [class_or_interface_name *] deconstruct P1 X16 [id] X17 [repeat class_or_interface_component] deconstruct * [id] X16 X16_x1 [id] construct X16_d1 [id *] _ [ . ' class_or_interface_name ] [ . X16_x1 ] [ print ] by P2 end rule function normalise_id_by4_class_or_interface_name1 replace [program] P1 [ program ] construct Element [class_or_interface_name *] _ [ ^ P1 ] construct d_Element [class_or_interface_name *] Element [ normalise_id_by3_class_or_interface_name1 ] by P1 end function rule normalise_id_by3_reference1 replace [reference *] P1 [reference] P2 [reference *] deconstruct P1 X18 [id] X19 [repeat dimension] X20 [repeat component] deconstruct * [id] X18 X18_x1 [id] construct X18_d1 [id *] _ [ . ' reference ] [ . X18_x1 ] [ print ] by P2 end rule function normalise_id_by4_reference1 replace [program] P1 [ program ] construct Element [reference *] _ [ ^ P1 ] construct d_Element [reference *] Element [ normalise_id_by3_reference1 ] by P1 end function rule normalise_id_by3_dot_id1 replace [dot_id *] P1 [dot_id] P2 [dot_id *] deconstruct P1 '. X21 [id] deconstruct * [id] X21 X21_x1 [id] construct X21_d1 [id *] _ [ . ' dot_id ] [ . X21_x1 ] [ print ] by P2 end rule function normalise_id_by4_dot_id1 replace [program] P1 [ program ] construct Element [dot_id *] _ [ ^ P1 ] construct d_Element [dot_id *] Element [ normalise_id_by3_dot_id1 ] by P1 end function rule normalise_id_by3_wildcard_type1 replace [wildcard_type *] P1 [wildcard_type] P2 [wildcard_type *] deconstruct P1 X22 [id] X23 [opt wildcard_type_bound] deconstruct * [id] X22 X22_x1 [id] construct X22_d1 [id *] _ [ . ' wildcard_type ] [ . X22_x1 ] [ print ] by P2 end rule function normalise_id_by4_wildcard_type1 replace [program] P1 [ program ] construct Element [wildcard_type *] _ [ ^ P1 ] construct d_Element [wildcard_type *] Element [ normalise_id_by3_wildcard_type1 ] by P1 end function function program_normalise replace [program] Prg [ program ] by Prg [ normalise_list_package_declaration_import_declaration ] [ normalise_list_class_header_modifier ] [ normalise_list_interface_header_modifier ] [ normalise_list_enum_header_modifier ] [ normalise_list_enum_body_class_body_declaration ] [ normalise_list_extends_clause_type_name ] [ normalise_list_implements_clause_qualified_name ] [ normalise_list_class_or_interface_body_class_body_declaration ] [ normalise_list_constructor_declaration_modifier ] [ normalise_list_variable_declaration_modifier ] [ normalise_list_variable_declarators_variable_declarator ] [ normalise_list_method_declaration_modifier ] [ normalise_list_throws_qualified_name ] [ normalise_list_annotation_value_list_keyed_annotation_value ] [ normalise_list_single_annotation_value_expression_or_nested_annotation ] [ normalise_id_by4_declared_name1 ] [ normalise_id_by4_enum_element1 ] [ normalise_id_by4_variable_initializer1 ] [ normalise_id_by4_keyed_annotation_value1 ] [ normalise_id_by4_class_or_interface_name1 ] [ normalise_id_by4_reference1 ] [ normalise_id_by4_dot_id1 ] [ normalise_id_by4_wildcard_type1 ] end function function program_remove_clone replace [program] Prg [ program ] export CloneNumber [number] 0 import TXLargs [repeat stringlit] deconstruct * TXLargs "-diff" Filename [ stringlit ] export CloneNumber 99 construct P2 [program] _ [ read Filename ] [ program_normalise ] export Program_Diff [program] P2 by Prg [ find_replace_package_header ] [ find_replace_import_declaration ] [ find_replace_type_declaration ] [ find_replace_class_body_declaration ] [ find_replace_declaration_or_statement ] [ find_replace_package_declaration ] [ find_replace_my_comment ] end function redefine program ... | [empty] | [attr number] end define function print_diff_1 replace [program] Prg [ program ] import TXLinput [stringlit] construct Str_TmpFile [stringlit] TXLinput [ + ".tmp" ] construct Str_RmTmpFile [stringlit] _ [ + "/bin/rm -f " ] [ + Str_TmpFile ] construct P2 [program] Prg [ write Str_TmpFile ] [ read Str_TmpFile ] [ system Str_RmTmpFile ] construct S_Diff [stringlit] _ [ quote P2 ] where not S_Diff [= ""] by Prg end function function print_diff_2 replace [program] Prg [ program ] import TXLinput [stringlit] construct Str_TmpFile [stringlit] TXLinput [ + ".tmp" ] construct Str_RmTmpFile [stringlit] _ [ + "/bin/rm -f " ] [ + Str_TmpFile ] construct P2 [program] Prg [ program_normalise ] [ write Str_TmpFile ] [ read Str_TmpFile ] [ system Str_RmTmpFile ] construct S_Diff [stringlit] _ [ quote P2 ] where S_Diff [= ""] by _ end function function print_diff replace [program] P_diff [ program ] import CloneNumber [number] import Program_Diff [program] where CloneNumber [> 0] construct P_Clone [program] CloneNumber [ - 99 ] construct P_Left [program] P_diff [ print_diff_1 ] [ print_diff_2 ] [ printattr ] construct P_Right [program] Program_Diff [ print_diff_1 ] [ print_diff_2 ] [ printattr ] by P_Clone end function redefine program ... | [id_nl *] end define define id_nl [id] [id] [NL] end define function id2id_nl T [id] replace [id_nl *] V [ id_nl * ] construct V2 [id_nl *] T T by _ [ . V ] [ . V2 ] end function function exportIds replace [program] Prg [ program ] construct I [id *] _ [ ^ Prg ] construct I2 [id_nl *] _ [id2id_nl each I] by I2 end function function main replace [program] Prg [ program ] export Program_Diff [program] _ export Program [program] Prg by Prg [ program_normalise ] [ program_remove_clone ] [ print_diff ] end function