public static Surrogate lookupSlotrefOnInstance(Stella_Object term, Symbol slotname) {
    { Surrogate termtype = null;

      termtype = Logic.safeLogicalType(term);
      if (termtype == null) {
        return (null);
      }
      if ((termtype.surrogateValue == null) ||
          ((!Stella_Object.isaP(termtype.surrogateValue, Logic.SGT_STELLA_CLASS)) ||
           (termtype == Logic.SGT_STELLA_THING))) {
        return (null);
      }
      if (Symbol.lookupFunction(slotname) != null) {
        return (null);
      }
      { Surrogate surrogate = Surrogate.lookupSlotref(termtype, slotname);

        if (surrogate != null) {
          return (surrogate);
        }
        if (Surrogate.subtypeOfP(Stella_Object.safePrimaryType(term), Logic.SGT_LOGIC_LOGIC_OBJECT)) {
          { LogicObject term000 = ((LogicObject)(term));

            { Proposition prop = null;
              Iterator iter000 = Logic.unfilteredDependentIsaPropositions(term000).allocateIterator();

              while (iter000.nextP()) {
                prop = ((Proposition)(iter000.value));
                if (prop.kind == Logic.KWD_ISA) {
                  surrogate = Surrogate.lookupSlotref(((Surrogate)(prop.operator)), slotname);
                  if (surrogate != null) {
                    return (surrogate);
                  }
                }
              }
            }
          }
        }
        else {
        }
        if (Surrogate.subtypeOfP(Stella_Object.safePrimaryType(term), Logic.SGT_LOGIC_SKOLEM)) {
          { Skolem term000 = ((Skolem)(term));

            if ((term000.definingProposition != null) &&
                Stella_Object.isaP(term000.definingProposition.operator, Logic.SGT_STELLA_SURROGATE)) {
              { NamedDescription description = Logic.getDescription(((Surrogate)(term000.definingProposition.operator)));

                if (description != null) {
                  termtype = ((Surrogate)(description.ioVariableTypes.last()));
                  surrogate = Surrogate.lookupSlotref(termtype, slotname);
                  if (surrogate != null) {
                    return (surrogate);
                  }
                }
              }
            }
          }
        }
        else {
        }
        return (null);
      }
    }
  }