Interface TempDirectory.TempDirContext

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <A extends java.lang.annotation.Annotation>
      java.util.Optional<A>
      findAnnotation​(java.lang.Class<A> annotationType)
      Find the first annotation of annotationType that is either present or meta-present on the Field or Parameter associated with this context.
      <A extends java.lang.annotation.Annotation>
      java.util.List<A>
      findRepeatableAnnotations​(java.lang.Class<A> annotationType)
      Find all repeatable annotations of annotationType that are either present or meta-present on the Field or Parameter associated with this context.
      java.lang.reflect.AnnotatedElement getElement()
      Get the AnnotatedElement associated with this context.
      java.util.Optional<java.lang.reflect.Field> getField()
      Get the Field associated with this context, if available.
      java.util.Optional<ParameterContext> getParameterContext()
      Get the ParameterContext associated with this context, if available.
      boolean isAnnotated​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Determine if an annotation of annotationType is either present or meta-present on the Field or Parameter associated with this context.
    • Method Detail

      • getElement

        java.lang.reflect.AnnotatedElement getElement()
        Get the AnnotatedElement associated with this context.

        The annotated element will be the corresponding Field or Parameter on which @TempDir is declared.

        Favor this method over more specific methods whenever the AnnotatedElement API suits the task at hand — for example, when looking up annotations regardless of concrete element type.

        Returns:
        the AnnotatedElement; never null
        See Also:
        getField(), getParameterContext()
      • getField

        java.util.Optional<java.lang.reflect.Field> getField()
        Get the Field associated with this context, if available.

        If this method returns an empty Optional, getParameterContext() will return a non-empty Optional.

        Returns:
        an Optional containing the field; never null but potentially empty
        See Also:
        getElement(), getParameterContext()
      • getParameterContext

        java.util.Optional<ParameterContext> getParameterContext()
        Get the ParameterContext associated with this context, if available.

        If this method returns an empty Optional, getField() will return a non-empty Optional.

        Returns:
        an Optional containing the ParameterContext; never null but potentially empty
        See Also:
        getElement(), getField()
      • isAnnotated

        boolean isAnnotated​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Determine if an annotation of annotationType is either present or meta-present on the Field or Parameter associated with this context.

        WARNING

        Favor the use of this method over directly invoking AnnotatedElement.isAnnotationPresent(Class) due to a bug in javac on JDK versions prior to JDK 9.

        Parameters:
        annotationType - the annotation type to search for; never null
        Returns:
        true if the annotation is present or meta-present
        See Also:
        findAnnotation(Class), findRepeatableAnnotations(Class)
      • findAnnotation

        <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation​(java.lang.Class<A> annotationType)
        Find the first annotation of annotationType that is either present or meta-present on the Field or Parameter associated with this context.

        WARNING

        Favor the use of this method over directly invoking annotation lookup methods in the Parameter API due to a bug in javac on JDK versions prior to JDK 9.

        Type Parameters:
        A - the annotation type
        Parameters:
        annotationType - the annotation type to search for; never null
        Returns:
        an Optional containing the annotation; never null but potentially empty
        See Also:
        isAnnotated(Class), findRepeatableAnnotations(Class)
      • findRepeatableAnnotations

        <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations​(java.lang.Class<A> annotationType)
        Find all repeatable annotations of annotationType that are either present or meta-present on the Field or Parameter associated with this context.

        WARNING

        Favor the use of this method over directly invoking annotation lookup methods in the Parameter API due to a bug in javac on JDK versions prior to JDK 9.

        Type Parameters:
        A - the annotation type
        Parameters:
        annotationType - the repeatable annotation type to search for; never null
        Returns:
        the list of all such annotations found; neither null nor mutable, but potentially empty
        See Also:
        isAnnotated(Class), findAnnotation(Class), Repeatable