/// <summary> /// Creates a resource from a fully qualified resource name. /// <para> /// If the resource name does not start with a slash '/', one will be prepended. /// Use <seealso cref="#ofClasspath(Class, String)"/> to get a relative resource. /// </para> /// <para> /// In Java 9 and later, resources can be encapsulated due to the module system. /// As such, this method is caller sensitive. /// It finds the class of the method that called this one, and uses that to search for /// resources using <seealso cref="Class#getResource(String)"/>. /// /// </para> /// </summary> /// <param name="resourceName"> the resource name, which will have a slash '/' prepended if missing </param> /// <returns> the resource locator </returns> public static ResourceLocator ofClasspath(string resourceName) { ArgChecker.notNull(resourceName, "classpathLocator"); string searchName = resourceName.StartsWith("/", StringComparison.Ordinal) ? resourceName : "/" + resourceName; Type caller = Guavate.callerClass(3); return(ofClasspath(caller, searchName)); }
//------------------------------------------------------------------------- public virtual void test_callerClass() { assertEquals(Guavate.callerClass(0), typeof(Guavate.CallerClassSecurityManager)); assertEquals(Guavate.callerClass(1), typeof(Guavate)); assertEquals(Guavate.callerClass(2), typeof(GuavateTest)); }