public static void dumpClasses()

in src/main/java/org/jetbrains/plugins/spotbugs/common/util/DebugUtil.java [44:82]


	public static void dumpClasses(@NotNull final Class<?> clazz) {
		final StringBuilder s = new StringBuilder();
		s.append("Begin dump: ").append(clazz).append("\n");

		final ClassLoader threadCl = Thread.currentThread().getContextClassLoader();
		s.append("Current Context CL: ").append(threadCl.getClass()).append(" [").append(System.identityHashCode(threadCl)).append("]\n");

    final Set<ClassLoader> cls = new HashSet<>();
		collectClassLoaders(cls, clazz.getClassLoader());
		collectClassLoaders(cls, threadCl);

		final Field classesField;
		try {
			classesField = ClassLoader.class.getDeclaredField("classes");
			classesField.setAccessible(true);
		} catch (final NoSuchFieldException e) {
			e.printStackTrace();
			return;
		}
		for (final ClassLoader cl : cls) {
			s.append("\n\nCL: ").append(cl.getClass()).append(" [").append(System.identityHashCode(cl)).append("]\n");
			try {
				@SuppressWarnings("unchecked") final Vector<Class<?>> classes = (Vector<Class<?>>) classesField.get(cl);
				final List<Class<?>> sorted = new ArrayList<>(classes);
				sorted.sort((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
				for (final Class<?> c : sorted) {
					final URL url = cl.getResource("/" + c.getName().replace(".", "/") + ".class");
					s.append("    ").append(c.getName()).append(" -> ").append(url).append("\n");
				}
			} catch (final IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		try {
			FileUtil.writeToFile(new File("C:\\classLoaderDump.txt"), s.toString());
		} catch (final IOException e) {
			e.printStackTrace();
		}
	}