include "Java/java.grm" % Yijun Yu, April, 2011 % The rules are redefined to include annotations redefine class_or_interface_body '{ [NL][IN] [repeat class_body_declaration kept ordered ignored when Private] [EX] [NL] '} [opt ';] [NL][NL] end define redefine method_body [repeat block preferred with ';] | [opt annotation_default] '; % T.D. Oct 2007 end define redefine constructor_body [repeat block preferred with '{ '}] end define redefine enum_body '{ [IN] [list enum_element] [opt ',] [repeat class_body_declaration kept ordered] [EX] '} [opt ';] [NL][NL] end define redefine type_declaration [class_declaration kept] [NL][NL] | [interface_declaration kept] [NL][NL] | [enum_declaration kept] [NL] % T.D. Oct 2007 end define redefine import_declaration 'import [opt 'static] [imported_name] '; [NL] | '; [NL] % JRC Apr 08 end define redefine package_declaration [opt package_header kept] [repeat import_declaration kept ordered] [repeat type_declaration] end define redefine class_header [repeat modifier ordered] 'class [class_name] [opt extends_clause] [opt implements_clause] end define % T.D. Oct 2007 -- added annotation marker redefine interface_header [repeat modifier ordered] [opt annot_marker] 'interface [interface_name] [opt extends_clause] [opt implements_clause] end define redefine enum_header [repeat modifier ordered] [opt id] 'enum [opt declared_name][opt extends_clause] [opt implements_clause] end define redefine extends_clause 'extends [list type_name+ ordered] end define redefine implements_clause 'implements [list qualified_name+ ordered] end define % to match Java Code like: % public void someMethod(T t) { % // ... % } redefine constructor_declaration [NL] [repeat modifier ordered] [opt generic_parameter] [constructor_declarator] [opt throws] [constructor_body] [NL][NL] end define redefine variable_declaration [repeat modifier ordered] [type_specifier] [variable_declarators] '; [NL] end define redefine variable_declarators [list variable_declarator+ ordered] end define % Method declarations % generic method declaration (to match generic types used only in a method's declaration and body) redefine method_declaration [NL] [repeat modifier ordered] [opt generic_parameter] [type_specifier] [method_declarator] [opt throws] [method_body] end define redefine throws 'throws [list qualified_name+ ordered] end define redefine annotation_value_list [single_annotation_value] % for single value annotation | [list keyed_annotation_value ordered] end define redefine single_annotation_value [expression] % must be constant | [nested_annotation] | { [list expression_or_nested_annotation ordered] } % array of annotation values end define redefine catch_clause 'catch '( [repeat modifier ordered] [type_specifier] [variable_name] ') [block] % July 15 end define #ifdef COMMENTS include "Java/javaCommentOverrides.grm" #endif function contains Object [any] match * [any] Object end function function Private A [class_body_declaration] match [class_or_interface_body] B [class_or_interface_body] construct M [modifier *] _ [^ A] construct PublicModifiers [modifier*] 'public 'protected where not M [contains each PublicModifiers] end function