Example #1
0
  /*
   * modifiers declarationRest
   */
  private boolean parseLocalDeclaration() {
    PsiBuilder.Marker decl = mark();
    JetParsing.ModifierDetector detector = new JetParsing.ModifierDetector();
    myJetParsing.parseModifierList(MODIFIER_LIST, detector, REGULAR_ANNOTATIONS_ONLY_WITH_BRACKETS);

    IElementType declType = parseLocalDeclarationRest(detector.isEnumDetected());

    if (declType != null) {
      // we do not attach preceding comments (non-doc) to local variables because they are likely
      // commenting a few statements below
      closeDeclarationWithCommentBinders(
          decl,
          declType,
          declType != JetNodeTypes.PROPERTY && declType != JetNodeTypes.MULTI_VARIABLE_DECLARATION);
      return true;
    } else {
      decl.rollbackTo();
      return false;
    }
  }
Example #2
0
  /*
   * when
   *   : "when" ("(" (modifiers "val" SimpleName "=")? element ")")? "{"
   *         whenEntry*
   *     "}"
   *   ;
   */
  private void parseWhen() {
    assert _at(WHEN_KEYWORD);

    PsiBuilder.Marker when = mark();

    advance(); // WHEN_KEYWORD

    // Parse condition
    myBuilder.disableNewlines();
    if (at(LPAR)) {
      advanceAt(LPAR);

      int valPos =
          matchTokenStreamPredicate(
              new FirstBefore(new At(VAL_KEYWORD), new AtSet(RPAR, LBRACE, RBRACE, SEMICOLON, EQ)));
      if (valPos >= 0) {
        PsiBuilder.Marker property = mark();
        myJetParsing.parseModifierList(MODIFIER_LIST, REGULAR_ANNOTATIONS_ALLOW_SHORTS);
        myJetParsing.parseProperty(true);
        property.done(PROPERTY);
      } else {
        parseExpression();
      }

      expect(RPAR, "Expecting ')'");
    }
    myBuilder.restoreNewlinesState();

    // Parse when block
    myBuilder.enableNewlines();
    if (expect(LBRACE, "Expecting '{'")) {
      while (!eof() && !at(RBRACE)) {
        parseWhenEntry();
      }

      expect(RBRACE, "Expecting '}'");
    }
    myBuilder.restoreNewlinesState();

    when.done(WHEN);
  }