@@ -826,9 +826,9 @@ object JavaParsers {
826826 addCompanionObject(statics, cls)
827827 }
828828
829- def unnamedClassDecl (priorTypes : List [Tree ], start : Offset ): List [Tree ] = {
829+ def unnamedClassDecl (priorTypes : List [Tree ], firstMemberMods : Modifiers , start : Offset ): List [Tree ] = {
830830 val name = source.name.replaceAll(" \\ .java$" , " " ).nn.toTypeName
831- val (statics, body) = typeBodyDecls(CLASS , name, Nil )
831+ val (statics, body) = typeBodyDecls(CLASS , name, parentTParams = Nil , firstMemberMods = Some (firstMemberMods) )
832832
833833 val (priorStatics, priorBody) = priorTypes.partition {
834834 case t : TypeDef => t.mods.is(Flags .JavaStatic )
@@ -920,13 +920,13 @@ object JavaParsers {
920920 defs
921921 }
922922
923- def typeBodyDecls (parentToken : Int , parentName : Name , parentTParams : List [TypeDef ]): (List [Tree ], List [Tree ]) = {
923+ def typeBodyDecls (parentToken : Int , parentName : Name , parentTParams : List [TypeDef ], firstMemberMods : Option [ Modifiers ] = None ): (List [Tree ], List [Tree ]) = {
924924 val inInterface = definesInterface(parentToken)
925925 val statics = new ListBuffer [Tree ]
926926 val members = new ListBuffer [Tree ]
927927 while (in.token != RBRACE && in.token != EOF ) {
928928 val start = in.offset
929- var mods = modifiers(inInterface)
929+ var mods = ( if (statics.isEmpty && members.isEmpty) firstMemberMods else None ).getOrElse( modifiers(inInterface) )
930930 if (in.token == LBRACE ) {
931931 skipAhead() // skip init block, we just assume we have seen only static
932932 accept(RBRACE )
@@ -1105,8 +1105,7 @@ object JavaParsers {
11051105 if (thisPackageName == tpnme.EMPTY_PACKAGE ) {
11061106 // upon encountering non-types directly at a compilation unit level in an unnamed package,
11071107 // the entire compilation unit is treated as a JEP-445 unnamed class
1108- // TODO support @annotated members of unnamed class
1109- val cls = unnamedClassDecl(priorTypes = typesBuf.toList, start = afterImports)
1108+ val cls = unnamedClassDecl(priorTypes = typesBuf.toList, firstMemberMods = mods, start = afterImports)
11101109 typesBuf.clear()
11111110 typesBuf ++= cls
11121111 } else {
@@ -1117,7 +1116,6 @@ object JavaParsers {
11171116 }
11181117 }
11191118 }
1120-
11211119 val unit = atSpan(start) { PackageDef (pkg, (buf ++ typesBuf).toList) }
11221120 accept(EOF )
11231121 unit match
0 commit comments