ClassName.get()
.MethodSpec.Builder.addNamedCode()
and TypeSpec.anonymousClassBuilder(CodeBlock)
.New: Basic support for line wrapping. Use $W
to insert a Wrappable Whitespace character. It'll emit either a single space or a newline with appropriate indentation.
New: Named arguments in CodeBlock
. These are intended to make larger code snippets easier to read:
Map<String, Object> map = new LinkedHashMap<>(); map.put("count", 3); map.put("greeting", "Hello, "); map.put("system", System.class); String template = "" + "for (int i = 0; i < $count:L; i++) {\n" + " $system:T.out.println($greeting:S + list.get(i));\n" + "}\n"; CodeBlock.Builder builder = CodeBlock.builder(); builder.addNamed(template, map);
New: addJavadoc(CodeBlock)
overloads for TypeSpec, MethodSpec, and FieldSpec.
New: MethodSpec.addComment()
makes it easy to add a // single-line comment.
New: ClassName.getReflectionName()
returns a string like java.util.Map$Entry
.
Fix: Always write UTF-8. Previously JavaPoet would use the system default charset which was potentially inconsistent across environments.
Fix: Permit (constant) fields to be defined in annotation types.
Outer<String>.Inner
.TypeName.isBoxedPrimitive()
.CodeBlock.of()
, a handy factory method for building code blocks.TypeSpec
factory methods that take a ClassName
.TypeName.annotated()
adds an annotation to a type.TypeVariableName.withBounds()
adds bounds to a type variable.TypeSpec.Builder.addInitializerBlock()
adds an instance initializer.TypeSpec.Kind
enum public. This can be used to check if a TypeSpec
is a class, interface, enum, or annotation.private
on annotation members.MethodSpec.Builder
.ErrorType
like a regular DeclaredType
in TypeName.get()
. This should make it easier to write annotation processors.TypeName
instances are only equal if their annotations are equal.import static
! See JavaFile.Builder.addStaticImport()
variants.NameAllocator.newName(String)
for creating a one-off name without a tag.TypeVariableName
is part of ParameterizedTypeName
.add("$1S", "a", "b")
.AnnotationSpec.get(Annotation)
.TypeName.annotated()
can attach annotations like @Nullable
directly to types. This works for both top-level types and type parameters as in List<@Nullable String>
.equals()
and hashCode()
on AnnotationSpec
, CodeBlock
, FieldSpec
, JavaFile
, MethodSpec
, ParameterSpec
, TypeName
, and TypeSpec
.NameAllocator.clone()
to refine a NameAllocator for use in an inner scope code block.TypeVariableName
gets a self-referential type.NameAllocator
API makes it easy to declare non-conflicting names.TypeName.get(TypeMirror)
.$1T
and $2N
. Indexes can be used to refer to the same argument multiple times in a single format string.addStaticBlock()
.MethodSpec.overriding()
retains annotations.$T
and $N
.MethodSpec.varargs(boolean)
to generate varags methods.AnnotationSpec.get()
and MethodSpec.overriding()
to create annotations and methods from the javax.lang.model
API.JavaFile.toJavaFileObject()
.DEFAULT
modifier.toBuilder()
methods to build upon objects already constructed.@interface
annotation types.TypeName.box()
and TypeName.unbox()
convenience APIs.nextControlFlow()
accepts arguments.WildcardTypeName.get(WildcardType)
no longer throws a NullPointerException
.javapoet
. We renamed the it so you can simultaneously use the old JavaWriter API and our new builder-based APIs in one project..java
file from top to bottom, you now define members in whatever way is convenient.StringLiteral
type which encapsulates the behavior of stringLiteral
.emitEnumValue
variant which exposes a boolean of whether the current value is the last.java.lang
in compressType
.setIndent
.beginConstructor
method is a semantically clearer alternative for constructors.emitEnumValues
method emits a list of values followed by semicolon.emitImports
now supports Class
arguments directly.int
-based modifier methods have been removed.setCompressingTypes
controls whether types are emitted as fully-qualified or not.stringLiteral
now correctly handles escapes and control characters.Set
of Modifier
s rather than an int
. The int
methods are now deprecated for removal in JavaPoet 1.0.emitSingleLineComment
.com.squareup.javawriter
.throws
clause on methods.type
API for helping build generic types.compressType
API.Initial release.