Package org.apache.beam.sdk.util
Class ApiSurface
- java.lang.Object
-
- org.apache.beam.sdk.util.ApiSurface
-
@Internal public class ApiSurface extends java.lang.Object
Represents the API surface of a package prefix. Used for accessing public classes, methods, and the types they reference, to control what dependencies are re-exported.For the purposes of calculating the public API surface, exposure includes any public or protected occurrence of:
- superclasses
- interfaces implemented
- actual type arguments to generic types
- array component types
- method return types
- method parameter types
- type variable bounds
- wildcard bounds
Exposure is a transitive property. The resulting map excludes primitives and array classes themselves.
It is prudent (though not required) to prune prefixes like "java" via the builder method
pruningPrefix(java.lang.String)
to halt the traversal so it does not uselessly catalog references that are not interesting.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static org.hamcrest.Matcher<java.lang.Class<?>>
classesInPackage(java.lang.String packageName)
A factory method to create aClass
matcher for classes residing in a given package.static org.hamcrest.Matcher<ApiSurface>
containsOnlyClassesMatching(java.util.Set<org.hamcrest.Matcher<java.lang.Class<?>>> classMatchers)
A factory method to create anApiSurface
matcher, producing a positive match if the queried api surface contains ONLY classes described by the provided matchers.static org.hamcrest.Matcher<ApiSurface>
containsOnlyClassesMatching(org.hamcrest.Matcher<java.lang.Class<?>>... classMatchers)
static org.hamcrest.Matcher<ApiSurface>
containsOnlyPackages(java.lang.String... packageNames)
static org.hamcrest.Matcher<ApiSurface>
containsOnlyPackages(java.util.Set<java.lang.String> packageNames)
A factory method to create anApiSurface
matcher, producing a positive match if the queried api surface contains classes ONLY from specified package names.static ApiSurface
empty()
Returns an emptyApiSurface
.java.util.List<java.lang.Class<?>>
getAnyExposurePath(java.lang.Class<?> exposedClass)
Returns a path from an exposed class to a root class.java.util.Set<java.lang.Class<?>>
getExposedClasses()
Returns exposed types in this set, including arrays and primitives as specified.java.util.Set<java.lang.Class<?>>
getRootClasses()
Returns all public classes originally belonging to the package in theApiSurface
.ApiSurface
includingClass(java.lang.Class<?> clazz)
Returns anApiSurface
like this one, but also including the given class.ApiSurface
includingPackage(java.lang.String packageName, java.lang.ClassLoader classLoader)
Returns anApiSurface
like this one, but also including the named package and all of its subpackages.static ApiSurface
ofClass(java.lang.Class<?> clazz)
Returns anApiSurface
object representing just the surface of the given class.static ApiSurface
ofPackage(java.lang.Package aPackage, java.lang.ClassLoader classLoader)
Returns anApiSurface
object representing the given package and all subpackages.static ApiSurface
ofPackage(java.lang.String packageName, java.lang.ClassLoader classLoader)
Returns anApiSurface
object representing the given package and all subpackages.ApiSurface
pruningClass(java.lang.Class<?> clazz)
Returns anApiSurface
like this one, but pruning references from the provided class.ApiSurface
pruningClassName(java.lang.String className)
Returns anApiSurface
like this one, but pruning references from the named class.ApiSurface
pruningPattern(java.lang.String patternString)
ApiSurface
pruningPattern(java.util.regex.Pattern pattern)
Returns anApiSurface
like this one, but pruning transitive references from classes whose full name (including package) begins with the provided prefix.ApiSurface
pruningPrefix(java.lang.String prefix)
Returns anApiSurface
like this one, but pruning transitive references from classes whose full name (including package) begins with the provided prefix.
-
-
-
Method Detail
-
classesInPackage
public static org.hamcrest.Matcher<java.lang.Class<?>> classesInPackage(java.lang.String packageName)
A factory method to create aClass
matcher for classes residing in a given package.
-
containsOnlyClassesMatching
public static org.hamcrest.Matcher<ApiSurface> containsOnlyClassesMatching(java.util.Set<org.hamcrest.Matcher<java.lang.Class<?>>> classMatchers)
A factory method to create anApiSurface
matcher, producing a positive match if the queried api surface contains ONLY classes described by the provided matchers.
-
containsOnlyClassesMatching
@SafeVarargs public static org.hamcrest.Matcher<ApiSurface> containsOnlyClassesMatching(org.hamcrest.Matcher<java.lang.Class<?>>... classMatchers)
-
containsOnlyPackages
public static org.hamcrest.Matcher<ApiSurface> containsOnlyPackages(java.lang.String... packageNames)
-
containsOnlyPackages
public static org.hamcrest.Matcher<ApiSurface> containsOnlyPackages(java.util.Set<java.lang.String> packageNames)
A factory method to create anApiSurface
matcher, producing a positive match if the queried api surface contains classes ONLY from specified package names.
-
empty
public static ApiSurface empty()
Returns an emptyApiSurface
.
-
ofPackage
public static ApiSurface ofPackage(java.lang.String packageName, java.lang.ClassLoader classLoader) throws java.io.IOException
Returns anApiSurface
object representing the given package and all subpackages.- Throws:
java.io.IOException
-
ofPackage
public static ApiSurface ofPackage(java.lang.Package aPackage, java.lang.ClassLoader classLoader) throws java.io.IOException
Returns anApiSurface
object representing the given package and all subpackages.- Throws:
java.io.IOException
-
ofClass
public static ApiSurface ofClass(java.lang.Class<?> clazz)
Returns anApiSurface
object representing just the surface of the given class.
-
includingPackage
public ApiSurface includingPackage(java.lang.String packageName, java.lang.ClassLoader classLoader) throws java.io.IOException
Returns anApiSurface
like this one, but also including the named package and all of its subpackages.- Throws:
java.io.IOException
-
includingClass
public ApiSurface includingClass(java.lang.Class<?> clazz)
Returns anApiSurface
like this one, but also including the given class.
-
pruningPrefix
public ApiSurface pruningPrefix(java.lang.String prefix)
Returns anApiSurface
like this one, but pruning transitive references from classes whose full name (including package) begins with the provided prefix.
-
pruningClassName
public ApiSurface pruningClassName(java.lang.String className)
Returns anApiSurface
like this one, but pruning references from the named class.
-
pruningClass
public ApiSurface pruningClass(java.lang.Class<?> clazz)
Returns anApiSurface
like this one, but pruning references from the provided class.
-
pruningPattern
public ApiSurface pruningPattern(java.util.regex.Pattern pattern)
Returns anApiSurface
like this one, but pruning transitive references from classes whose full name (including package) begins with the provided prefix.
-
pruningPattern
public ApiSurface pruningPattern(java.lang.String patternString)
-
getRootClasses
public java.util.Set<java.lang.Class<?>> getRootClasses()
Returns all public classes originally belonging to the package in theApiSurface
.
-
getExposedClasses
public java.util.Set<java.lang.Class<?>> getExposedClasses()
Returns exposed types in this set, including arrays and primitives as specified.
-
getAnyExposurePath
public java.util.List<java.lang.Class<?>> getAnyExposurePath(java.lang.Class<?> exposedClass)
Returns a path from an exposed class to a root class. There may be many, but this gives only one.If there are only cycles, with no path back to a root class, throws IllegalStateException.
-
-