@@ -826,9 +826,9 @@ object JavaParsers {
826
826
addCompanionObject(statics, cls)
827
827
}
828
828
829
- def unnamedClassDecl (priorTypes : List [Tree ], start : Offset ): List [Tree ] = {
829
+ def unnamedClassDecl (priorTypes : List [Tree ], firstMemberMods : Modifiers , start : Offset ): List [Tree ] = {
830
830
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) )
832
832
833
833
val (priorStatics, priorBody) = priorTypes.partition {
834
834
case t : TypeDef => t.mods.is(Flags .JavaStatic )
@@ -920,13 +920,13 @@ object JavaParsers {
920
920
defs
921
921
}
922
922
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 ]) = {
924
924
val inInterface = definesInterface(parentToken)
925
925
val statics = new ListBuffer [Tree ]
926
926
val members = new ListBuffer [Tree ]
927
927
while (in.token != RBRACE && in.token != EOF ) {
928
928
val start = in.offset
929
- var mods = modifiers(inInterface)
929
+ var mods = ( if (statics.isEmpty && members.isEmpty) firstMemberMods else None ).getOrElse( modifiers(inInterface) )
930
930
if (in.token == LBRACE ) {
931
931
skipAhead() // skip init block, we just assume we have seen only static
932
932
accept(RBRACE )
@@ -1105,8 +1105,7 @@ object JavaParsers {
1105
1105
if (thisPackageName == tpnme.EMPTY_PACKAGE ) {
1106
1106
// upon encountering non-types directly at a compilation unit level in an unnamed package,
1107
1107
// 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)
1110
1109
typesBuf.clear()
1111
1110
typesBuf ++= cls
1112
1111
} else {
@@ -1117,7 +1116,6 @@ object JavaParsers {
1117
1116
}
1118
1117
}
1119
1118
}
1120
-
1121
1119
val unit = atSpan(start) { PackageDef (pkg, (buf ++ typesBuf).toList) }
1122
1120
accept(EOF )
1123
1121
unit match
0 commit comments