Skip to content

Commit

Permalink
Add convenience anonymousClassBuilder(CodeBlock) (square#560)
Browse files Browse the repository at this point in the history
* Add convenience anonymousClassBuilder(CodeBlock)

Resolves square#558

* Fix indent
  • Loading branch information
ZacSweers authored and swankjesse committed May 13, 2017
1 parent 48378f7 commit 40dfa0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/squareup/javapoet/TypeSpec.java
Expand Up @@ -111,11 +111,15 @@ public static Builder enumBuilder(ClassName className) {
}

public static Builder anonymousClassBuilder(String typeArgumentsFormat, Object... args) {
return new Builder(Kind.CLASS, null, CodeBlock.builder()
return anonymousClassBuilder(CodeBlock.builder()
.add(typeArgumentsFormat, args)
.build());
}

public static Builder anonymousClassBuilder(CodeBlock typeArguments) {
return new Builder(Kind.CLASS, null, typeArguments);
}

public static Builder annotationBuilder(String name) {
return new Builder(Kind.ANNOTATION, checkNotNull(name, "name == null"), null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/squareup/javapoet/TypeSpecTest.java
Expand Up @@ -127,7 +127,7 @@ private boolean isJava8() {
ParameterSpec thungParameter = ParameterSpec.builder(thungOfSuperFoo, "thung")
.addModifiers(Modifier.FINAL)
.build();
TypeSpec aSimpleThung = TypeSpec.anonymousClassBuilder("$N", thungParameter)
TypeSpec aSimpleThung = TypeSpec.anonymousClassBuilder(CodeBlock.of("$N", thungParameter))
.superclass(simpleThungOfBar)
.addMethod(MethodSpec.methodBuilder("doSomething")
.addAnnotation(Override.class)
Expand Down

0 comments on commit 40dfa0c

Please sign in to comment.