// $ANTLR start "ruleModelElement"
  // PsiInternalBug289524TestLanguage.g:111:1: ruleModelElement returns [Boolean current=false] : (
  // () ( ( (lv_containments_1_0= ruleContained ) ) | (otherlv_2= 'reference' ( (otherlv_3= RULE_ID
  // ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID ) ) )* ) )+ ) ;
  public final Boolean ruleModelElement() throws RecognitionException {
    Boolean current = false;

    Token otherlv_2 = null;
    Token otherlv_3 = null;
    Token otherlv_4 = null;
    Token otherlv_5 = null;
    Boolean lv_containments_1_0 = null;

    try {
      // PsiInternalBug289524TestLanguage.g:112:1: ( ( () ( ( (lv_containments_1_0= ruleContained )
      // ) | (otherlv_2= 'reference' ( (otherlv_3= RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID
      // ) ) )* ) )+ ) )
      // PsiInternalBug289524TestLanguage.g:113:2: ( () ( ( (lv_containments_1_0= ruleContained ) )
      // | (otherlv_2= 'reference' ( (otherlv_3= RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID )
      // ) )* ) )+ )
      {
        // PsiInternalBug289524TestLanguage.g:113:2: ( () ( ( (lv_containments_1_0= ruleContained )
        // ) | (otherlv_2= 'reference' ( (otherlv_3= RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5=
        // RULE_ID ) ) )* ) )+ )
        // PsiInternalBug289524TestLanguage.g:114:3: () ( ( (lv_containments_1_0= ruleContained ) )
        // | (otherlv_2= 'reference' ( (otherlv_3= RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID
        // ) ) )* ) )+
        {
          // PsiInternalBug289524TestLanguage.g:114:3: ()
          // PsiInternalBug289524TestLanguage.g:115:4:
          {
            if (state.backtracking == 0) {

              /* */

            }
            if (state.backtracking == 0) {

              precedeComposite(
                  elementTypeProvider.getModelElement_ModelElementAction_0ElementType());
              doneComposite();
              associateWithSemanticElement();
            }
          }

          // PsiInternalBug289524TestLanguage.g:124:3: ( ( (lv_containments_1_0= ruleContained ) ) |
          // (otherlv_2= 'reference' ( (otherlv_3= RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID
          // ) ) )* ) )+
          int cnt3 = 0;
          loop3:
          do {
            int alt3 = 3;
            int LA3_0 = input.LA(1);

            if ((LA3_0 == 14)) {
              int LA3_2 = input.LA(2);

              if ((synpred2_PsiInternalBug289524TestLanguage())) {
                alt3 = 1;
              }

            } else if ((LA3_0 == 12)) {
              int LA3_3 = input.LA(2);

              if ((synpred4_PsiInternalBug289524TestLanguage())) {
                alt3 = 2;
              }
            }

            switch (alt3) {
              case 1:
                // PsiInternalBug289524TestLanguage.g:125:4: ( (lv_containments_1_0= ruleContained )
                // )
                {
                  // PsiInternalBug289524TestLanguage.g:125:4: ( (lv_containments_1_0= ruleContained
                  // ) )
                  // PsiInternalBug289524TestLanguage.g:126:5: (lv_containments_1_0= ruleContained )
                  {
                    // PsiInternalBug289524TestLanguage.g:126:5: (lv_containments_1_0= ruleContained
                    // )
                    // PsiInternalBug289524TestLanguage.g:127:6: lv_containments_1_0= ruleContained
                    {
                      if (state.backtracking == 0) {

                        markComposite(
                            elementTypeProvider
                                .getModelElement_ContainmentsContainedParserRuleCall_1_0_0ElementType());
                      }
                      pushFollow(FollowSets000.FOLLOW_3);
                      lv_containments_1_0 = ruleContained();

                      state._fsp--;
                      if (state.failed) return current;
                      if (state.backtracking == 0) {

                        doneComposite();
                        if (!current) {
                          associateWithSemanticElement();
                          current = true;
                        }
                      }
                    }
                  }
                }
                break;
              case 2:
                // PsiInternalBug289524TestLanguage.g:141:4: (otherlv_2= 'reference' ( (otherlv_3=
                // RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID ) ) )* )
                {
                  // PsiInternalBug289524TestLanguage.g:141:4: (otherlv_2= 'reference' ( (otherlv_3=
                  // RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID ) ) )* )
                  // PsiInternalBug289524TestLanguage.g:142:5: otherlv_2= 'reference' ( (otherlv_3=
                  // RULE_ID ) ) (otherlv_4= '$' ( (otherlv_5= RULE_ID ) ) )*
                  {
                    if (state.backtracking == 0) {

                      markLeaf(
                          elementTypeProvider.getModelElement_ReferenceKeyword_1_1_0ElementType());
                    }
                    otherlv_2 = (Token) match(input, 12, FollowSets000.FOLLOW_4);
                    if (state.failed) return current;
                    if (state.backtracking == 0) {

                      doneLeaf(otherlv_2);
                    }
                    // PsiInternalBug289524TestLanguage.g:149:5: ( (otherlv_3= RULE_ID ) )
                    // PsiInternalBug289524TestLanguage.g:150:6: (otherlv_3= RULE_ID )
                    {
                      // PsiInternalBug289524TestLanguage.g:150:6: (otherlv_3= RULE_ID )
                      // PsiInternalBug289524TestLanguage.g:151:7: otherlv_3= RULE_ID
                      {
                        if (state.backtracking == 0) {

                          /* */

                        }
                        if (state.backtracking == 0) {

                          if (!current) {
                            associateWithSemanticElement();
                            current = true;
                          }
                        }
                        if (state.backtracking == 0) {

                          markLeaf(
                              elementTypeProvider
                                  .getModelElement_RefsContainedCrossReference_1_1_1_0ElementType());
                        }
                        otherlv_3 = (Token) match(input, RULE_ID, FollowSets000.FOLLOW_5);
                        if (state.failed) return current;
                        if (state.backtracking == 0) {

                          doneLeaf(otherlv_3);
                        }
                      }
                    }

                    // PsiInternalBug289524TestLanguage.g:169:5: (otherlv_4= '$' ( (otherlv_5=
                    // RULE_ID ) ) )*
                    loop2:
                    do {
                      int alt2 = 2;
                      int LA2_0 = input.LA(1);

                      if ((LA2_0 == 13)) {
                        alt2 = 1;
                      }

                      switch (alt2) {
                        case 1:
                          // PsiInternalBug289524TestLanguage.g:170:6: otherlv_4= '$' ( (otherlv_5=
                          // RULE_ID ) )
                          {
                            if (state.backtracking == 0) {

                              markLeaf(
                                  elementTypeProvider
                                      .getModelElement_DollarSignKeyword_1_1_2_0ElementType());
                            }
                            otherlv_4 = (Token) match(input, 13, FollowSets000.FOLLOW_4);
                            if (state.failed) return current;
                            if (state.backtracking == 0) {

                              doneLeaf(otherlv_4);
                            }
                            // PsiInternalBug289524TestLanguage.g:177:6: ( (otherlv_5= RULE_ID ) )
                            // PsiInternalBug289524TestLanguage.g:178:7: (otherlv_5= RULE_ID )
                            {
                              // PsiInternalBug289524TestLanguage.g:178:7: (otherlv_5= RULE_ID )
                              // PsiInternalBug289524TestLanguage.g:179:8: otherlv_5= RULE_ID
                              {
                                if (state.backtracking == 0) {

                                  /* */

                                }
                                if (state.backtracking == 0) {

                                  if (!current) {
                                    associateWithSemanticElement();
                                    current = true;
                                  }
                                }
                                if (state.backtracking == 0) {

                                  markLeaf(
                                      elementTypeProvider
                                          .getModelElement_RefsContainedCrossReference_1_1_2_1_0ElementType());
                                }
                                otherlv_5 = (Token) match(input, RULE_ID, FollowSets000.FOLLOW_5);
                                if (state.failed) return current;
                                if (state.backtracking == 0) {

                                  doneLeaf(otherlv_5);
                                }
                              }
                            }
                          }
                          break;

                        default:
                          break loop2;
                      }
                    } while (true);
                  }
                }
                break;

              default:
                if (cnt3 >= 1) break loop3;
                if (state.backtracking > 0) {
                  state.failed = true;
                  return current;
                }
                EarlyExitException eee = new EarlyExitException(3, input);
                throw eee;
            }
            cnt3++;
          } while (true);
        }
      }

    } catch (RecognitionException re) {
      reportError(re);
      recover(input, re);
    } finally {
    }
    return current;
  }