SymbolLookup { public Descriptor<?> findDescriptor(Class<?> type, String symbol) { try { Key k = new Key("findDescriptor",type,symbol); Object i = cache.get(k); if (i!=null) return (Descriptor)i; if (!Utilities.isJavaIdentifier(symbol)) return null; checkPluginsForChangeAndRefresh(); Object miss = noHitCache.get(k); if (miss == NO_HIT) { return null; } for (Class<?> e : Index.list(Symbol.class, pluginManager.uberClassLoader, Class.class)) { if (Descriptor.class.isAssignableFrom(e)) { Descriptor<?> d = jenkins.getDescriptorByType(e.asSubclass(Descriptor.class)); if (d == null) { LOGGER.fine(() -> e.getName() + " is not registered as an extension, so will be ignored"); continue; } Symbol s = e.getAnnotation(Symbol.class); if (s != null) { for (String t : s.value()) { if (t.equals(symbol)) { if (type.isAssignableFrom(d.clazz)) { cache.put(k, d); return d; } } } } } } noHitCache.put(k, NO_HIT); return null; } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to find @Symbol",e); return null; } }  T find(Class<T> type, String symbol); Descriptor<?> findDescriptor(Class<?> type, String symbol); static SymbolLookup get(); @Nonnull static Set<String> getSymbolValue(@Nonnull Object o); @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Jenkins.getInstance() can return null in theory.") @Nonnull static Set<String> getSymbolValue(@Nonnull Class<?> c);  }
@Test public void descriptorLookup() { assertThat(lookup.findDescriptor(Fishing.class, "net"), is(sameInstance((Descriptor)fishingNetDescriptor))); assertThat(lookup.findDescriptor(Tech.class, "net"), is(sameInstance((Descriptor)internetDescriptor))); }