1Change Log 2========== 3 4JavaPoet 1.11.1 *(2018-05-16)* 5----------------------------- 6 7 * Fix: JavaPoet 1.11 had a regression where `TypeName.get()` would throw on error types, masking 8 other errors in an annotation processing round. This is fixed with a test to prevent future 9 regressions! 10 11 12JavaPoet 1.11.0 *(2018-04-29)* 13----------------------------- 14 15 * New: Support `TYPE_USE` annotations on each enclosing `ClassName`. 16 * New: Work around a compiler bug in `TypeName.get(TypeElement)`. There was a problem getting an 17 element's kind when building from source ABIs. 18 19 20JavaPoet 1.10.0 *(2018-01-27)* 21----------------------------- 22 23 * **JavaPoet now requires Java 8 or newer.** 24 * New: `$Z` as an optional newline (zero-width space) if a line may exceed 100 chars. 25 * New: `CodeBlock.join()` and `CodeBlock.joining()` let you join codeblocks by delimiters. 26 * New: Add `CodeBlock.Builder.isEmpty()`. 27 * New: `addStatement(CodeBlock)` overloads for `CodeBlock` and `MethodSpec`. 28 * Fix: Include annotations when emitting type variables. 29 * Fix: Use the right imports for annotated type parameters. 30 * Fix: Don't incorrectly escape classnames that start with `$`. 31 32 33JavaPoet 1.9.0 *(2017-05-13)* 34----------------------------- 35 36 * Fix: Don't emit incorrect code when the declared type's signature references another type with 37 the same simple name. 38 * Fix: Support anonymous inner classes in `ClassName.get()`. 39 * New: `MethodSpec.Builder.addNamedCode()` and `TypeSpec.anonymousClassBuilder(CodeBlock)`. 40 41 42JavaPoet 1.8.0 *(2016-11-09)* 43----------------------------- 44 45 * New: Basic support for line wrapping. Use `$W` to insert a Wrappable Whitespace character. It'll 46 emit either a single space or a newline with appropriate indentation. 47 * New: Named arguments in `CodeBlock`. These are intended to make larger code snippets easier to 48 read: 49 50 ``` 51 Map<String, Object> map = new LinkedHashMap<>(); 52 map.put("count", 3); 53 map.put("greeting", "Hello, "); 54 map.put("system", System.class); 55 56 String template = "" 57 + "for (int i = 0; i < $count:L; i++) {\n" 58 + " $system:T.out.println($greeting:S + list.get(i));\n" 59 + "}\n"; 60 61 CodeBlock.Builder builder = CodeBlock.builder(); 62 builder.addNamed(template, map); 63 ``` 64 65 * New: `addJavadoc(CodeBlock)` overloads for TypeSpec, MethodSpec, and FieldSpec. 66 * New: `MethodSpec.addComment()` makes it easy to add a `// single-line comment.` 67 * New: `ClassName.getReflectionName()` returns a string like `java.util.Map$Entry`. 68 * Fix: Always write UTF-8. Previously JavaPoet would use the system default charset which was 69 potentially inconsistent across environments. 70 * Fix: Permit (constant) fields to be defined in annotation types. 71 72 73JavaPoet 1.7.0 *(2016-04-26)* 74----------------------------- 75 76 * New: Support parameterized types that enclose other types, like `Outer<String>.Inner`. 77 * New: `TypeName.isBoxedPrimitive()`. 78 79 80JavaPoet 1.6.1 *(2016-03-21)* 81----------------------------- 82 83 * Fix: Double quotes and backslashes in string literals were not properly quoted in 1.6.0. This is 84 now fixed. 85 86 87JavaPoet 1.6.0 *(2016-03-19)* 88----------------------------- 89 90 * New: Revive `CodeBlock.of()`, a handy factory method for building code blocks. 91 * New: Add `TypeSpec` factory methods that take a `ClassName`. 92 * New: `TypeName.annotated()` adds an annotation to a type. 93 * New: `TypeVariableName.withBounds()` adds bounds to a type variable. 94 * New: `TypeSpec.Builder.addInitializerBlock()` adds an instance initializer. 95 * Fix: Make `TypeSpec.Kind` enum public. This can be used to check if a `TypeSpec` is a class, 96 interface, enum, or annotation. 97 * Fix: Don’t break import resolution on annotated types. 98 * Fix: Forbid unexpected modifiers like `private` on annotation members. 99 * Fix: Deduplicate exceptions in `MethodSpec.Builder`. 100 * Fix: Treat `ErrorType` like a regular `DeclaredType` in `TypeName.get()`. This should make it 101 easier to write annotation processors. 102 103 104JavaPoet 1.5.1 *(2016-01-10)* 105----------------------------- 106 107 * Fix: Annotated `TypeName` instances are only equal if their annotations are equal. 108 109JavaPoet 1.5.0 *(2016-01-10)* 110----------------------------- 111 112 * New: `import static`! See `JavaFile.Builder.addStaticImport()` variants. 113 * New: Overload `NameAllocator.newName(String)` for creating a one-off name without a tag. 114 * Fix: AnnotationSpec escapes character literals properly. 115 * Fix: Don't stack overflow when `TypeVariableName` is part of `ParameterizedTypeName`. 116 * Fix: Reporting not used indexed arguments in like `add("$1S", "a", "b")`. 117 * Fix: Prevent import of types located in the default package, i.e. have no package name. 118 119 120JavaPoet 1.4.0 *(2015-11-13)* 121----------------------------- 122 123 * New: `AnnotationSpec.get(Annotation)`. 124 * New: Type annotations! `TypeName.annotated()` can attach annotations like `@Nullable` directly to 125 types. This works for both top-level types and type parameters as in `List<@Nullable String>`. 126 * New: `equals()` and `hashCode()` on `AnnotationSpec`, `CodeBlock`, `FieldSpec`, `JavaFile`, 127 `MethodSpec`, `ParameterSpec`, `TypeName`, and `TypeSpec`. 128 * New: `NameAllocator.clone()` to refine a NameAllocator for use in an inner scope code block. 129 * Fix: Don't stack overflow when `TypeVariableName` gets a self-referential type. 130 * Fix: Better handling of name collisions on imports. Previously JavaPoet did the wrong thing when 131 a referenced type and a nested types had the same name. 132 133 134JavaPoet 1.3.0 *(2015-09-20)* 135----------------------------- 136 137 * New: `NameAllocator` API makes it easy to declare non-conflicting names. 138 * New: Support annotations on enum values. 139 * Fix: Avoid infinite recursion in `TypeName.get(TypeMirror)`. 140 * Fix: Use qualified name for conflicting simple names in the same file. 141 * Fix: Better messages for parameter indexing errors. 142 143 144JavaPoet 1.2.0 *(2015-07-04)* 145----------------------------- 146 147 * New: Arguments may have positional indexes like `$1T` and `$2N`. Indexes can be used to refer to 148 the same argument multiple times in a single format string. 149 * New: Permit Javadoc on enum constants. 150 * New: Class initializer blocks with `addStaticBlock()`. 151 * Fix: `MethodSpec.overriding()` retains annotations. 152 153 154JavaPoet 1.1.0 *(2015-05-25)* 155----------------------------- 156 157 * New: Eager validation of argument types like `$T` and `$N`. 158 * New: `MethodSpec.varargs(boolean)` to generate varags methods. 159 * New: `AnnotationSpec.get()` and `MethodSpec.overriding()` to create annotations and methods from 160 the `javax.lang.model` API. 161 * New: `JavaFile.toJavaFileObject()`. 162 * New: Java 8 `DEFAULT` modifier. 163 * New: `toBuilder()` methods to build upon objects already constructed. 164 * New: Generate `@interface` annotation types. 165 * New: `TypeName.box()` and `TypeName.unbox()` convenience APIs. 166 * Fix: `nextControlFlow()` accepts arguments. 167 * Fix: Reject duplicate calls to set the superclass. 168 * Fix: `WildcardTypeName.get(WildcardType)` no longer throws a `NullPointerException`. 169 * Fix: Don't allow double field initialization. 170 171JavaPoet 1.0.0 *(2015-01-28)* 172----------------------------- 173 174 * This update is a complete rewrite. The project name is now `javapoet`. We renamed the it so you 175 can simultaneously use the old JavaWriter API and our new builder-based APIs in one project. 176 * Immutable value objects and builders. Instead of streaming the `.java` file from top to bottom, 177 you now define members in whatever way is convenient. 178 * We now use our own models for type names. 179 * Imports are now added automatically. 180 181 182JavaWriter 2.5.1 *(2014-12-03)* 183------------------------------- 184 185 * New: `StringLiteral` type which encapsulates the behavior of `stringLiteral`. 186 * Fix: Use canonical name when emitting a class import. 187 * Fix: Apply type compression to varargs and array types. 188 * Fix: Restore binary compatibility with pre-2.5 versions. 189 190 191JavaWriter 2.5.0 *(2014-04-18)* 192------------------------------- 193 194 * New: Methods in interfaces will always have no body declaration. 195 * New: Control flow begin declaration now supports String format arguments. 196 * Fix: Truncate any generic type when emitting constructors. 197 * Fix: Do not emit trailing whitespace after '=' at end-of-line. 198 199 200JavaWriter 2.4.0 *(2014-01-10)* 201------------------------------- 202 203 * New: Properly indent hanging lines in field initializers. 204 * New: `emitEnumValue` variant which exposes a boolean of whether the current value is the last. 205 206 207JavaWriter 2.3.1 *(2013-12-16)* 208------------------------------- 209 210 * Fix: Properly handle subpackages of `java.lang` in `compressType`. 211 212 213JavaWriter 2.3.0 *(2013-11-24)* 214------------------------------- 215 216 * New: Configurable indent level via `setIndent`. 217 * New: `beginConstructor` method is a semantically clearer alternative for constructors. 218 * New: `emitEnumValues` method emits a list of values followed by semicolon. 219 * `emitImports` now supports `Class` arguments directly. 220 * Previously-deprecated, `int`-based modifier methods have been removed. 221 222 223JavaWriter 2.2.1 *(2013-10-23)* 224------------------------------- 225 226 * Fix: Do not emit trailing whitespace for empty Javadoc lines. 227 228 229JavaWriter 2.2.0 *(2013-09-25)* 230------------------------------- 231 232 * `setCompressingTypes` controls whether types are emitted as fully-qualified or not. 233 234 235JavaWriter 2.1.2 *(2013-08-23)* 236------------------------------- 237 238 * Attempt to keep annotations on a single line. 239 240 241JavaWriter 2.1.1 *(2013-07-23)* 242------------------------------- 243 244 * Fix: `stringLiteral` now correctly handles escapes and control characters. 245 246 247JavaWriter 2.1.0 *(2013-07-15)* 248------------------------------- 249 250 * New: All methods now take a `Set` of `Modifier`s rather than an `int`. The `int` methods are 251 now deprecated for removal in JavaPoet 1.0. 252 * Annotations with a single "value" attribute will now omit the key. 253 254 255JavaWriter 2.0.1 *(2013-06-17)* 256------------------------------- 257 258 * Correct casing of `emitSingleLineComment`. 259 260 261JavaWriter 2.0.0 *(2013-06-06)* 262------------------------------- 263 264 * Package name is now `com.squareup.javawriter`. 265 * Support declaring `throws` clause on methods. 266 267 268JavaWriter 1.0.5 *(2013-05-08)* 269------------------------------- 270 271 * Fix: Fully qualify types whose simple name matches an import. 272 273 274JavaWriter 1.0.4 *(2013-03-15)* 275------------------------------- 276 277 * Fix: Static import emit now properly supports method imports. 278 279 280JavaWriter 1.0.3 *(2013-02-21)* 281------------------------------- 282 283 * Add support for emitting static imports. 284 285 286JavaWriter 1.0.2 *(2013-02-11)* 287------------------------------- 288 289 * Add `type` API for helping build generic types. 290 * Minor performance improvements. 291 292 293JavaWriter 1.0.1 *(2013-02-03)* 294------------------------------- 295 296 * Expose `compressType` API. 297 298 299JavaWriter 1.0.0 *(2013-02-01)* 300------------------------------- 301 302Initial release. 303