@Nullable
  private PsiBuilder.Marker parseClassFromKeyword(PsiBuilder builder,
                                                  PsiBuilder.Marker declaration,
                                                  boolean isAnnotation,
                                                  BaseContext context) {
    IElementType keywordTokenType = builder.getTokenType();
    final boolean isRecord = isRecordToken(builder, keywordTokenType);
    if (isRecord) {
      if (builder.lookAhead(1) != JavaTokenType.IDENTIFIER) {
        declaration.drop();
        return null;
      }
      final IElementType afterIdent = builder.lookAhead(2);
      // No parser recovery for local records without < or ( to support light stubs
      // (look at com.intellij.psi.impl.source.JavaLightStubBuilder.CodeBlockVisitor.visit)
      if (context == BaseContext.CODE_BLOCK && afterIdent != JavaTokenType.LPARENTH && afterIdent != JavaTokenType.LT) {
        // skipping record kw and identifier
        PsiBuilderUtil.advance(builder, 2);
        error(builder, JavaPsiBundle.message("expected.lt.or.lparen"));
        declaration.drop();
        return null;
      }
      builder.remapCurrentToken(JavaTokenType.RECORD_KEYWORD);
      keywordTokenType = JavaTokenType.RECORD_KEYWORD;
    }
    assert BASIC_CLASS_KEYWORD_BIT_SET.contains(keywordTokenType) : keywordTokenType;
    builder.advanceLexer();
    final boolean isEnum = (keywordTokenType == JavaTokenType.ENUM_KEYWORD);

    if (!expect(builder, JavaTokenType.IDENTIFIER)) {
      error(builder, JavaPsiBundle.message("expected.identifier"));
      declaration.drop();
      return null;
    }

    final BasicReferenceParser refParser = myParser.getReferenceParser();
    refParser.parseTypeParameters(builder);

    if (builder.getTokenType() == JavaTokenType.LPARENTH) {
      parseElementList(builder, ListType.RECORD_COMPONENTS);
    }

    refParser.parseReferenceList(builder, JavaTokenType.EXTENDS_KEYWORD, myJavaElementTypeContainer.EXTENDS_LIST, JavaTokenType.COMMA);
    refParser.parseReferenceList(builder, JavaTokenType.IMPLEMENTS_KEYWORD, myJavaElementTypeContainer.IMPLEMENTS_LIST,
                                 JavaTokenType.COMMA);
    if (builder.getTokenType() == JavaTokenType.IDENTIFIER &&
        PsiKeyword.PERMITS.equals(builder.getTokenText())) {
      builder.remapCurrentToken(JavaTokenType.PERMITS_KEYWORD);
    }
    if (builder.getTokenType() == JavaTokenType.PERMITS_KEYWORD) {
      refParser.parseReferenceList(builder, JavaTokenType.PERMITS_KEYWORD, myJavaElementTypeContainer.PERMITS_LIST, JavaTokenType.COMMA);
    }

    if (builder.getTokenType() != JavaTokenType.LBRACE) {
      final PsiBuilder.Marker error = builder.mark();
      while (BEFORE_LBRACE_ELEMENTS_SET.contains(builder.getTokenType())) {
        builder.advanceLexer();
      }
      error.error(JavaPsiBundle.message("expected.lbrace"));
    }

    if (builder.getTokenType() == JavaTokenType.LBRACE) {
      parseClassBodyWithBraces(builder, isAnnotation, isEnum);
    }

    done(declaration, myJavaElementTypeContainer.CLASS, myWhiteSpaceAndCommentSetHolder);
    return declaration;
  }
@Nullable
  private PsiBuilder.Marker parseClassFromKeyword(PsiBuilder builder,
                                                  PsiBuilder.Marker declaration,
                                                  boolean isAnnotation,
                                                  BaseContext context)