- Forked square/javapoet under a new name xenit-eu/bard
- Changed package namespace to
eu.xenit.contentcloud.bard
- Converted build system to Gradle
- New: Inline annotation members for fields
- New: Supports JDK 11 (baseline) & JDK 17
- Override whitespace for nested annotations
- Changed package namespace to
com.contentgrid.bard
- New: Add support for explicit receiver parameters.
- Fix: Don't copy parameter annotations when creating a
ParameterSpec
.
- Fix: Ignore parameter annotations in
MethodSpec.overriding()
.
- New: Add
JavaFile.writeToPath()
andJavaFile.writeToFile()
methods that return paths to the generated file asPath
andFile
respectively. - New: Add
TypeSpec.alwaysQualify()
API to avoid clashes involving nested type names. - New: Add overloads accepting
CodeBlock
s toMethodSpec
's control flow methods. - New: Make list fields of all
Builder
types mutable. - New: Add
CodeBlock.clear()
. - New: Allow passing a custom
Charset
toJavaFile.writeTo()
. - New: Improved performance of
ClassName.simpleNames()
by memoizing results. - New: Significant performance improvements for
CodeWriter.resolve()
as all nested simple names of aTypeSpec
get pre-computed. - New: Add
TypeName.Builder.setName()
to allow overriding names passed in the constructor. - New: Add
TypeName.canonicalName()
. - Fix: Use
\\R
instead of\n
as line separator inCodeWriter.emitAndIndent()
. - Fix: Copy originating elements in
TypeSpec.toBuilder()
. - Fix: Ensure trailing newlines in Javadocs and method bodies.
- Fix: Copy annotations when creating a
ParameterSpec
from aVariableElement
. - Fix: Properly handle classes located in empty packages in
ClassName
. - Fix: Only allow
final
modifier on aParameterSpec
. - Fix: Use fully-qualified names for type names that are masked by type variable names.
- Fix: JavaPoet 1.11 had a regression where
TypeName.get()
would throw on error types, masking other errors in an annotation processing round. This is fixed with a test to prevent future regressions!
- New: Support
TYPE_USE
annotations on each enclosingClassName
. - New: Work around a compiler bug in
TypeName.get(TypeElement)
. There was a problem getting an element's kind when building from source ABIs.
- JavaPoet now requires Java 8 or newer.
- New:
$Z
as an optional newline (zero-width space) if a line may exceed 100 chars. - New:
CodeBlock.join()
andCodeBlock.joining()
let you join codeblocks by delimiters. - New: Add
CodeBlock.Builder.isEmpty()
. - New:
addStatement(CodeBlock)
overloads forCodeBlock
andMethodSpec
. - Fix: Include annotations when emitting type variables.
- Fix: Use the right imports for annotated type parameters.
- Fix: Don't incorrectly escape classnames that start with
$
.
- Fix: Don't emit incorrect code when the declared type's signature references another type with the same simple name.
- Fix: Support anonymous inner classes in
ClassName.get()
. - New:
MethodSpec.Builder.addNamedCode()
andTypeSpec.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 likejava.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.
- New: Support parameterized types that enclose other types, like
Outer<String>.Inner
. - New:
TypeName.isBoxedPrimitive()
.
- Fix: Double quotes and backslashes in string literals were not properly quoted in 1.6.0. This is now fixed.
- New: Revive
CodeBlock.of()
, a handy factory method for building code blocks. - New: Add
TypeSpec
factory methods that take aClassName
. - New:
TypeName.annotated()
adds an annotation to a type. - New:
TypeVariableName.withBounds()
adds bounds to a type variable. - New:
TypeSpec.Builder.addInitializerBlock()
adds an instance initializer. - Fix: Make
TypeSpec.Kind
enum public. This can be used to check if aTypeSpec
is a class, interface, enum, or annotation. - Fix: Don’t break import resolution on annotated types.
- Fix: Forbid unexpected modifiers like
private
on annotation members. - Fix: Deduplicate exceptions in
MethodSpec.Builder
. - Fix: Treat
ErrorType
like a regularDeclaredType
inTypeName.get()
. This should make it easier to write annotation processors.
- Fix: Annotated
TypeName
instances are only equal if their annotations are equal.
- New:
import static
! SeeJavaFile.Builder.addStaticImport()
variants. - New: Overload
NameAllocator.newName(String)
for creating a one-off name without a tag. - Fix: AnnotationSpec escapes character literals properly.
- Fix: Don't stack overflow when
TypeVariableName
is part ofParameterizedTypeName
. - Fix: Reporting not used indexed arguments in like
add("$1S", "a", "b")
. - Fix: Prevent import of types located in the default package, i.e. have no package name.
- New:
AnnotationSpec.get(Annotation)
. - New: Type annotations!
TypeName.annotated()
can attach annotations like@Nullable
directly to types. This works for both top-level types and type parameters as inList<@Nullable String>
. - New:
equals()
andhashCode()
onAnnotationSpec
,CodeBlock
,FieldSpec
,JavaFile
,MethodSpec
,ParameterSpec
,TypeName
, andTypeSpec
. - New:
NameAllocator.clone()
to refine a NameAllocator for use in an inner scope code block. - Fix: Don't stack overflow when
TypeVariableName
gets a self-referential type. - Fix: Better handling of name collisions on imports. Previously JavaPoet did the wrong thing when a referenced type and a nested types had the same name.
- New:
NameAllocator
API makes it easy to declare non-conflicting names. - New: Support annotations on enum values.
- Fix: Avoid infinite recursion in
TypeName.get(TypeMirror)
. - Fix: Use qualified name for conflicting simple names in the same file.
- Fix: Better messages for parameter indexing errors.
- New: Arguments may have positional indexes like
$1T
and$2N
. Indexes can be used to refer to the same argument multiple times in a single format string. - New: Permit Javadoc on enum constants.
- New: Class initializer blocks with
addStaticBlock()
. - Fix:
MethodSpec.overriding()
retains annotations.
- New: Eager validation of argument types like
$T
and$N
. - New:
MethodSpec.varargs(boolean)
to generate varags methods. - New:
AnnotationSpec.get()
andMethodSpec.overriding()
to create annotations and methods from thejavax.lang.model
API. - New:
JavaFile.toJavaFileObject()
. - New: Java 8
DEFAULT
modifier. - New:
toBuilder()
methods to build upon objects already constructed. - New: Generate
@interface
annotation types. - New:
TypeName.box()
andTypeName.unbox()
convenience APIs. - Fix:
nextControlFlow()
accepts arguments. - Fix: Reject duplicate calls to set the superclass.
- Fix:
WildcardTypeName.get(WildcardType)
no longer throws aNullPointerException
. - Fix: Don't allow double field initialization.
- This update is a complete rewrite. The project name is now
javapoet
. We renamed the it so you can simultaneously use the old JavaWriter API and our new builder-based APIs in one project. - Immutable value objects and builders. Instead of streaming the
.java
file from top to bottom, you now define members in whatever way is convenient. - We now use our own models for type names.
- Imports are now added automatically.
- New:
StringLiteral
type which encapsulates the behavior ofstringLiteral
. - Fix: Use canonical name when emitting a class import.
- Fix: Apply type compression to varargs and array types.
- Fix: Restore binary compatibility with pre-2.5 versions.
- New: Methods in interfaces will always have no body declaration.
- New: Control flow begin declaration now supports String format arguments.
- Fix: Truncate any generic type when emitting constructors.
- Fix: Do not emit trailing whitespace after '=' at end-of-line.
- New: Properly indent hanging lines in field initializers.
- New:
emitEnumValue
variant which exposes a boolean of whether the current value is the last.
- Fix: Properly handle subpackages of
java.lang
incompressType
.
- New: Configurable indent level via
setIndent
. - New:
beginConstructor
method is a semantically clearer alternative for constructors. - New:
emitEnumValues
method emits a list of values followed by semicolon. emitImports
now supportsClass
arguments directly.- Previously-deprecated,
int
-based modifier methods have been removed.
- Fix: Do not emit trailing whitespace for empty Javadoc lines.
setCompressingTypes
controls whether types are emitted as fully-qualified or not.
- Attempt to keep annotations on a single line.
- Fix:
stringLiteral
now correctly handles escapes and control characters.
- New: All methods now take a
Set
ofModifier
s rather than anint
. Theint
methods are now deprecated for removal in JavaPoet 1.0. - Annotations with a single "value" attribute will now omit the key.
- Correct casing of
emitSingleLineComment
.
- Package name is now
com.squareup.javawriter
. - Support declaring
throws
clause on methods.
- Fix: Fully qualify types whose simple name matches an import.
- Fix: Static import emit now properly supports method imports.
- Add support for emitting static imports.
- Add
type
API for helping build generic types. - Minor performance improvements.
- Expose
compressType
API.
Initial release.