public static void collectMatchingRuleGoals(Proposition proposition, Cons toplevelvars, Keyword headortail, List collection) {
    { Keyword testValue000 = proposition.kind;

      if ((testValue000 == Logic.KWD_AND) ||
          (testValue000 == Logic.KWD_OR)) {
        if (headortail == Logic.KWD_HEAD) {
          { Stella_Object arg = null;
            Vector vector000 = proposition.arguments;
            int index000 = 0;
            int length000 = vector000.length();

            for (;index000 < length000; index000 = index000 + 1) {
              arg = (vector000.theArray)[index000];
              Proposition.collectMatchingRuleGoals(((Proposition)(arg)), toplevelvars, headortail, collection);
            }
          }
        }
        else if (headortail == Logic.KWD_TAIL) {
          { int goalcount = collection.length();

            { Stella_Object arg = null;
              Vector vector001 = proposition.arguments;
              int index001 = 0;
              int length001 = vector001.length();

              for (;index001 < length001; index001 = index001 + 1) {
                arg = (vector001.theArray)[index001];
                Proposition.collectMatchingRuleGoals(((Proposition)(arg)), toplevelvars, headortail, collection);
              }
            }
            if (goalcount == collection.length()) {
              { Stella_Object arg = null;
                Vector vector002 = proposition.arguments;
                int index002 = 0;
                int length002 = vector002.length();

                for (;index002 < length002; index002 = index002 + 1) {
                  arg = (vector002.theArray)[index002];
                  Proposition.collectMatchingRuleGoals(((Proposition)(arg)), toplevelvars, headortail, collection);
                }
              }
            }
          }
        }
        else {
          { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

            stream000.nativeStream.print("`" + headortail + "' is not a valid case option");
            throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
          }
        }
      }
      else if (testValue000 == Logic.KWD_EXISTS) {
        if (headortail == Logic.KWD_HEAD) {
          Proposition.collectMatchingRuleGoals(((Proposition)((proposition.arguments.theArray)[0])), toplevelvars, headortail, collection);
        }
        else if (headortail == Logic.KWD_TAIL) {
          { PatternVariable v = null;
            Vector vector003 = ((Vector)(KeyValueList.dynamicSlotValue(proposition.dynamicSlots, Logic.SYM_LOGIC_IO_VARIABLES, null)));
            int index003 = 0;
            int length003 = vector003.length();

            for (;index003 < length003; index003 = index003 + 1) {
              v = ((PatternVariable)((vector003.theArray)[index003]));
              toplevelvars = Cons.cons(v, toplevelvars);
            }
          }
          Proposition.collectMatchingRuleGoals(((Proposition)((proposition.arguments.theArray)[0])), toplevelvars, headortail, collection);
        }
        else {
          { OutputStringStream stream001 = OutputStringStream.newOutputStringStream();

            stream001.nativeStream.print("`" + headortail + "' is not a valid case option");
            throw ((StellaException)(StellaException.newStellaException(stream001.theStringReader()).fillInStackTrace()));
          }
        }
      }
      else if (testValue000 == Logic.KWD_FORALL) {
        if (headortail == Logic.KWD_HEAD) {
          { PatternVariable v = null;
            Vector vector004 = ((Vector)(KeyValueList.dynamicSlotValue(proposition.dynamicSlots, Logic.SYM_LOGIC_IO_VARIABLES, null)));
            int index004 = 0;
            int length004 = vector004.length();

            for (;index004 < length004; index004 = index004 + 1) {
              v = ((PatternVariable)((vector004.theArray)[index004]));
              toplevelvars = Cons.cons(v, toplevelvars);
            }
          }
          Proposition.collectMatchingRuleGoals(((Proposition)((proposition.arguments.theArray)[1])), toplevelvars, headortail, collection);
        }
        else if (headortail == Logic.KWD_TAIL) {
        }
        else {
          { OutputStringStream stream002 = OutputStringStream.newOutputStringStream();

            stream002.nativeStream.print("`" + headortail + "' is not a valid case option");
            throw ((StellaException)(StellaException.newStellaException(stream002.theStringReader()).fillInStackTrace()));
          }
        }
      }
      else if ((testValue000 == Logic.KWD_ISA) ||
          ((testValue000 == Logic.KWD_PREDICATE) ||
           ((testValue000 == Logic.KWD_FUNCTION) ||
            ((testValue000 == Logic.KWD_NOT) ||
             (testValue000 == Logic.KWD_IMPLIES))))) {
        { boolean testValue001 = false;

          { boolean alwaysP000 = true;

            { Stella_Object a = null;
              Cons iter000 = Proposition.extractGoalArguments(proposition);

              loop005 : for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
                a = iter000.value;
                if (!(toplevelvars.memberP(a) ||
                    (!Stella_Object.isaP(a, Logic.SGT_LOGIC_PATTERN_VARIABLE)))) {
                  alwaysP000 = false;
                  break loop005;
                }
              }
            }
            testValue001 = alwaysP000;
          }
          if (testValue001) {
            testValue001 = (Proposition.extractGoalDescription(proposition, headortail) != null) &&
                (!(proposition.operator == Logic.SGT_PL_KERNEL_KB_HOLDS));
          }
          if (testValue001) {
            collection.insert(proposition);
          }
        }
      }
      else {
      }
    }
  }