code: public static <T extends BuildStep&Describable<T>>
      List<Descriptor<T>> filter(List<Descriptor<T>> base, Class<? extends AbstractProject> type) {
          // descriptor of the project
          Descriptor pd = Jenkins.getInstance().getDescriptor((Class) type);
  
          List<Descriptor<T>> r = new ArrayList<>(base.size());
          for (Descriptor<T> d : base) {
              if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(d))
                  continue;
  
              if (d instanceof BuildStepDescriptor) {
                  BuildStepDescriptor<T> bd = (BuildStepDescriptor<T>) d;
                  if(!bd.isApplicable(type))  continue;
                  r.add(bd);
              } else {
                  // old plugins built before 1.150 may not implement BuildStepDescriptor
                  r.add(d);
              }
          }
          return r;
      }
docs: Filters a descriptor for {@link BuildStep}s by using {@link BuildStepDescriptor#isApplicable(Class)}.