MCPcopy Create free account
hub / github.com/antlr/codebuff / ClassPath

Class ClassPath

output/java_guava/1.4.19/ClassPath.java:62–538  ·  view source on GitHub ↗

Scans the source of a ClassLoader and finds all loadable classes and resources. Warning: Currently only URLClassLoader and only file:// urls are supported. @author Ben Yu @since 14.0

Source from the content-addressed store, hash-verified

60
61
62@Beta
63public final class ClassPath {
64 private static final Logger logger = Logger.getLogger(ClassPath.class.getName());
65
66 private static final Predicate<ClassInfo> IS_TOP_LEVEL = new Predicate<ClassInfo>() {
67 @Override
68 public boolean apply(ClassInfo info) {
69 return info.className.indexOf('$') == -1;
70 }
71 };
72
73 /** Separator for the Class-Path manifest attribute value in jar files. */
74
75 private static final Splitter CLASS_PATH_ATTRIBUTE_SEPARATOR = Splitter.on(" ").omitEmptyStrings();
76
77 private static final String CLASS_FILE_NAME_EXTENSION = ".class";
78
79 private final ImmutableSet<ResourceInfo> resources;
80
81 private ClassPath(ImmutableSet<ResourceInfo> resources) {
82 this.resources = resources;
83 }
84
85 /**
86 * Returns a {@code ClassPath} representing all classes and resources loadable from {@code
87 * classloader} and its parent class loaders.
88 *
89 * <p><b>Warning:</b> Currently only {@link URLClassLoader} and only {@code file://} urls are
90 * supported.
91 *
92 * @throws IOException if the attempt to read class path resources (jar files or directories)
93 * failed.
94 */
95
96
97 public static ClassPath from(ClassLoader classloader) throws IOException {
98 DefaultScanner scanner = new DefaultScanner();
99 scanner.scan(classloader);
100 return new ClassPath(scanner.getResources());
101 }
102
103 /**
104 * Returns all resources loadable from the current class path, including the class files of all
105 * loadable classes but excluding the "META-INF/MANIFEST.MF" file.
106 */
107
108
109 public ImmutableSet<ResourceInfo> getResources() {
110 return resources;
111 }
112
113 /**
114 * Returns all classes loadable from the current class path.
115 *
116 * @since 16.0
117 */
118
119

Callers

nothing calls this directly

Calls 3

onMethod · 0.95
getNameMethod · 0.45
omitEmptyStringsMethod · 0.45

Tested by

no test coverage detected