void (@NotNull PsiBuilder builder, @NotNull Predicate<? super PsiBuilder> importListStopper, @NotNull AbstractBundle bundle, @NotNull String errorMessageKey) { parsePackageStatement(builder); Pair<PsiBuilder.Marker, Boolean> impListInfo = parseImportList(builder, importListStopper); // (importList, isEmpty) Boolean firstDeclarationOk = null; PsiBuilder.Marker firstDeclaration = null; PsiBuilder.Marker invalidElements = null; boolean isUnnamedClass = false; while (!builder.eof()) { if (builder.getTokenType() == JavaTokenType.SEMICOLON) { builder.advanceLexer(); continue; } PsiBuilder.Marker declaration = myParser.getModuleParser().parse(builder); if (declaration == null) declaration = parseInitial(builder); if (declaration != null) { if (invalidElements != null) { invalidElements.errorBefore(error(bundle, errorMessageKey), declaration); invalidElements = null; } if (firstDeclarationOk == null) { firstDeclarationOk = exprType(declaration) != myJavaElementTypeContainer.MODIFIER_LIST; } if (firstDeclaration == null) { firstDeclaration = declaration; } if (!isUnnamedClass && UNNAMED_CLASS_INDICATORS.contains(exprType(declaration))) { isUnnamedClass = true; } continue; } if (invalidElements == null) { invalidElements = builder.mark(); } builder.advanceLexer(); if (firstDeclarationOk == null) firstDeclarationOk = false; } if (invalidElements != null) { invalidElements.error(error(bundle, errorMessageKey)); } if (impListInfo.second && firstDeclarationOk == Boolean.TRUE) { impListInfo.first.setCustomEdgeTokenBinders(myWhiteSpaceAndCommentSetHolder.getPrecedingCommentBinder(), null); // pass comments behind fake import list firstDeclaration.setCustomEdgeTokenBinders(myWhiteSpaceAndCommentSetHolder.getSpecialPrecedingCommentBinder(), null); } if (isUnnamedClass) { PsiBuilder.Marker beforeFirst = firstDeclaration.precede(); done(beforeFirst, myJavaElementTypeContainer.UNNAMED_CLASS, myWhiteSpaceAndCommentSetHolder); } }