JavaPoet TypeGuesser
Ever wanted to call ClassName.bestGuess("int")
or ClassName.bestGuess("java.util.List<java.lang.Integer>")
? This project provides an extension to JavaPoet that allows you to do just that. Simply replace the call to ClassName.bestGuess(String)
with a call to TypeGuesser.guessTypeName(String)
which is able to parse everything that ClassName
can and additionally is fine with primitives, generics, wildcards and arrays.
Features
-
Guess everything that
ClassName
can guess -
Guess primitives
-
Guess generic types
-
Support for wildcards
-
Support for array types
Development Status
All currently required features are implemented. This project is in maintenance mode. Take a look at the open tickets for ways to help out or create a new ticket yourself.
Usage
Use the TypeGuesser
class as a replacement for ClassName
like this:
import de.xn__ho_hia.javapoet.TypeGuesser;
TypeName guessedType = TypeGuesser.guessTypeName("...");
Take a look at the test cases for types that can and cannot be parsed by this project.
Integration
To use this project just declare the following dependency inside your POM:
<dependency>
<groupId>de.xn--ho-hia.javapoet</groupId>
<artifactId>javapoet-type-guesser</artifactId>
<version>${version.javapoet-type-guesser}</version>
</dependency>
Replace ${version.javapoet-type-guesser}
with the latest release. This project is continuously deployed and uses a date based versioning approach. I vow not to break any of its API ever, thus it is safe to use an open version range like (1.0.0,)
as a replacement for ${version.javapoet-type-guesser}
.
Compatibility
This project is compatible with the following Java versions:
X.Y.Z | |
---|---|
Java 8 |
✓ |
License
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.