Skip to content

Commit 5a3f011

Browse files
committed
Locatable: add default behavior for getLocation
1 parent 906e644 commit 5a3f011

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/org/scijava/Locatable.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
package org.scijava;
3333

34+
import java.net.URL;
35+
36+
import org.scijava.util.ClassUtils;
37+
3438
/**
3539
* An object whose location is defined by a URL string.
3640
*
@@ -39,6 +43,9 @@
3943
public interface Locatable {
4044

4145
/** Gets the URL string defining the object's location. */
42-
String getLocation();
46+
default String getLocation() {
47+
final URL location = ClassUtils.getLocation(getClass());
48+
return location == null ? null : location.toExternalForm();
49+
}
4350

4451
}

0 commit comments

Comments
 (0)