/*
 * This file is part of FastClasspathScanner.
 * 
 * Author: Luke Hutchison
 * 
 * Hosted at: https://github.com/lukehutch/fast-classpath-scanner
 * 
 * --
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 Luke Hutchison
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without
 * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial
 * portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
 * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
 * OR OTHER DEALINGS IN THE SOFTWARE.
 */
package io.github.lukehutch.fastclasspathscanner.utils;

import java.io.File;
import java.net.MalformedURLException;

public class ClasspathUtils {
    /**
     * Can be used to get the URL of a classpath resource whose classpath element and relative path has been passed
     * into a MatchProcessor.
     * 
     * @param classpathElt
     *            The classpath element (a directory or jarfile), as a File object.
     * @param relativePath
     *            The relative path within the classpath element, with '/' as the path delimiter character, and
     *            without an initial or final delimiter character.
     * @return The URL, in the form "file:/classpath/elt/path/followed/by/relative/path" or
     *         "jar:file:/classpath/elt/path.jar!/followed/by/relative/path".
     */
    public static String getClasspathResourceURL(final File classpathElt, final String relativePath) {
        final boolean classpathEltIsJar = classpathElt.isFile();
        String classpathEltURL;
        try {
            classpathEltURL = classpathElt.toURI().toURL().toString();
        } catch (final MalformedURLException e) {
            // Should not happen
            throw new RuntimeException(e);
        }
        final String relativePathEncoded = URLPathEncoder.encodePath(relativePath);
        final String url = classpathEltIsJar ? "jar:" + classpathEltURL + "!/" + relativePathEncoded
                : classpathEltURL + relativePathEncoded;
        return url;
    }
}

@@ -1409,16 +1409,37 @@
 ception;
+%0Aimport java.net.URL;
 %0A%0Apublic
@@ -2137,22 +2137,19 @@
  static 
-String
+URL
  getClas
@@ -2397,24 +2397,223 @@
 toString();%0A
+            if (!classpathEltIsJar && !classpathEltURL.endsWith(%22/%22)) %7B%0A                // Ensure trailing slash for directory classpath entries%0A                classpathEltURL += %22/%22;%0A            %7D%0A
         %7D ca
@@ -2990,19 +2990,182 @@
     
-return url;
+try %7B%0A            return new URL(url);%0A        %7D catch (final MalformedURLException e) %7B%0A            // Should not happen%0A            throw new RuntimeException(e);%0A        %7D
 %0A   

Return URL as URL type, rather than String