public ClassMeta getClassInfo(Class<?> cls) { final Package pkg = cls.getPackage(); URL loadedFrom = null; try { loadedFrom = cls.getProtectionDomain().getCodeSource().getLocation(); } catch (Throwable t) { Log.warn(t, "Failed to get source for %s", cls); } final API apiAnnotation = pkg.getAnnotation(API.class); final ApiInfo apiInfo = apiAnnotation != null? new ApiInfo(apiAnnotation) : null; Map<File, Set<String>> mods = Maps.newHashMap(); for (ModCandidate candidate : table.getCandidatesFor(pkg.getName())) { if (!candidate.getClassList().contains(cls.getName().replace('.', '/'))) continue; final File candidateFile = candidate.getModContainer(); Set<String> modIds = Sets.newHashSet(); mods.put(candidateFile, modIds); for (ModContainer mod : candidate.getContainedMods()) modIds.add(mod.getModId()); } return new ClassMeta(cls, loadedFrom, apiInfo, mods); }
public ApiInfo(API api) { this.api = api.provides(); this.owner = api.owner(); this.version = api.apiVersion(); }