Skip to content

Support @TempDir as a meta-annotation #3311

Closed
@marschall

Description

@marschall

With 5.10-M1 offering TempDirFactory it would be great to have @TempDir meta annotation capable.

To give you an example, I have my own TempDirFactory (I know it's not thread safe yet) that creates directories on a in-memory file system.

If my users do not want to switch the global default provider they have to use this everywhere.

@TempDir(factory = MemoryFileSystemTempDirFactory.class)
Path tempDirectory;

If @TempDir is meta annotation capable we can instead define the following meta annotation

@Retention(RUNTIME)
@Target({FIELD, PARAMETER, ANNOTATION_TYPE})
@TempDir(factory = MemoryFileSystemTempDirFactory.class)
public @interface MemoryTempDir {
  
}

and our users can use:

@MemoryTempDir
Path tempDirectory;

If we want to go further and allow the user some configuration options, eg. which file system semantics (Windows, Linux, ...) they want we would use an annotation for this.

With meta annotations instead of having

@MemoryTempDirType(WINDOWS)
@TempDir(factory = MemoryFileSystemTempDirFactory.class)
Path tempDirectory;

we could have a meta annotation

@Retention(RUNTIME)
@Target({FIELD, PARAMETER, ANNOTATION_TYPE})
@MemoryTempDir
@MemoryTempDirType(WINDOWS)
public @interface WindowsMemoryTempDir {

}

And the user could simply write

@WindowsMemoryTempDir
Path windowsTempDirectory;

Deliverables

  • Add ElementType.ANNOTATION_TYPE to @Target of @TempDir

I would be willing to work on a PR.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions