@API(status=STABLE,
since="1.0")
public class ClassSource
extends java.lang.Object
implements TestSource
TestSource with
an optional file position.
If a Java Class reference is provided, the ClassSource
will contain that Class and its class name accordingly. If a class
name is provided, the ClassSource will contain the class name and
will only attempt to lazily load the Class if getJavaClass()
is invoked.
In this context, Java Class means anything that can be referenced
as a Class on the JVM — for example, classes from other JVM
languages such Groovy, Scala, etc.
ClassSelector,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CLASS_SCHEME
URI scheme for class sources: "class" |
private java.lang.String |
className |
private FilePosition |
filePosition |
private java.lang.Class<?> |
javaClass |
private static long |
serialVersionUID |
| Modifier | Constructor and Description |
|---|---|
private |
ClassSource(java.lang.Class<?> javaClass) |
private |
ClassSource(java.lang.Class<?> javaClass,
FilePosition filePosition) |
private |
ClassSource(java.lang.String className) |
private |
ClassSource(java.lang.String className,
FilePosition filePosition) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object o) |
static ClassSource |
from(java.lang.Class<?> javaClass)
Create a new
ClassSource using the supplied class. |
static ClassSource |
from(java.lang.Class<?> javaClass,
FilePosition filePosition)
Create a new
ClassSource using the supplied class
and file position. |
static ClassSource |
from(java.lang.String className)
Create a new
ClassSource using the supplied class name. |
static ClassSource |
from(java.lang.String className,
FilePosition filePosition)
Create a new
ClassSource using the supplied class name and
file position. |
static ClassSource |
from(java.net.URI uri)
Create a new
ClassSource from the supplied URI. |
java.lang.String |
getClassName()
Get the class name of this source.
|
java.lang.Class<?> |
getJavaClass()
Get the Java class of this source.
|
java.util.Optional<FilePosition> |
getPosition()
|
int |
hashCode() |
java.lang.String |
toString() |
private static final long serialVersionUID
@API(status=STABLE,
since="1.8")
public static final java.lang.String CLASS_SCHEME
URI scheme for class sources: "class"private final java.lang.String className
private final FilePosition filePosition
private java.lang.Class<?> javaClass
private ClassSource(java.lang.String className)
private ClassSource(java.lang.String className,
FilePosition filePosition)
private ClassSource(java.lang.Class<?> javaClass)
private ClassSource(java.lang.Class<?> javaClass,
FilePosition filePosition)
public static ClassSource from(java.lang.String className)
ClassSource using the supplied class name.className - the class name; must not be null or blankpublic static ClassSource from(java.lang.String className, FilePosition filePosition)
ClassSource using the supplied class name and
file position.className - the class name; must not be null or blankfilePosition - the position in the source file; may be nullpublic static ClassSource from(java.lang.Class<?> javaClass)
ClassSource using the supplied class.javaClass - the Java class; must not be nullpublic static ClassSource from(java.lang.Class<?> javaClass, FilePosition filePosition)
ClassSource using the supplied class
and file position.javaClass - the Java class; must not be nullfilePosition - the position in the Java source file; may be null@API(status=STABLE,
since="1.8")
public static ClassSource from(java.net.URI uri)
ClassSource from the supplied URI.
URIs should be formatted as class:fully.qualified.class.Name.
The query component of the URI, if
present, will be used to retrieve the FilePosition via
FilePosition.fromQuery(String). For example, line 42 and column
13 can be referenced in class org.example.MyType via the following
URI: class:com.example.MyType?line=42&column=13. The URI fragment,
if present, will be ignored.
uri - the URI for the class source; never nullClassSource; never nullPreconditionViolationException - if the supplied URI is
null, if the scheme of the supplied URI is not equal
to the CLASS_SCHEME, or if the specified class name is emptyCLASS_SCHEMEpublic final java.lang.String getClassName()
getJavaClass(),
getPosition()public final java.lang.Class<?> getJavaClass()
If the Class was not provided, but only the name, this method
attempts to lazily load the Class based on its name and throws a
PreconditionViolationException if the class cannot be loaded.
getClassName(),
getPosition()public final java.util.Optional<FilePosition> getPosition()
getClassName(),
getJavaClass()public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object