Java Code Examples for com.squareup.javapoet.CodeBlock#of()
The following examples show how to use
com.squareup.javapoet.CodeBlock#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestingDIComponentProcessor.java From litho with Apache License 2.0 | 5 votes |
@Override public CodeBlock generateFactoryMethodsComponentInstance(SpecModel specModel) { return CodeBlock.of( "$L instance = new $L(context.getAndroidContext());\n", specModel.getComponentName(), specModel.getComponentName()); }
Example 2
Source File: JavaFiler.java From convalida with Apache License 2.0 | 5 votes |
private static CodeBlock createValidateOnClickCodeBlock(ValidationClass validationClass) { Element button = validationClass.getValidateButton(); if(button != null) { return CodeBlock.builder() .add("\n") .add( "validateOnClickListener(target.$N, target);", button.getSimpleName().toString() ) .build(); } return CodeBlock.of(""); }
Example 3
Source File: ServiceMetadataGenerator.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private CodeBlock globalRegion(Partition partition) { ClassName region = ClassName.get(regionBasePackage, "Region"); Service service = partition.getServices().get(this.serviceEndpointPrefix); boolean hasGlobalRegionForPartition = service.isRegionalized() != null && !service.isRegionalized() && service.isPartitionWideEndpointAvailable(); String globalRegionForPartition = hasGlobalRegionForPartition ? service.getPartitionEndpoint() : null; return globalRegionForPartition == null ? CodeBlock.of("null") : CodeBlock.of("$T.of($S)", region, globalRegionForPartition); }
Example 4
Source File: PoetCollectorsTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void codeBlocksJoined() { CodeBlock a = CodeBlock.of("a"); CodeBlock b = CodeBlock.of("b"); CodeBlock ab = CodeBlock.builder().add(a).add(b).build(); CodeBlock result = Stream.of(a, b).collect(PoetCollectors.toCodeBlock()); assertThat(result).isEqualTo(ab); }
Example 5
Source File: AwsServiceModel.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private CodeBlock enumGetterStatement(MemberModel member) { String fieldName = member.getVariable().getVariableName(); if (member.isList() || member.isMap()) { Optional<ClassName> copier = serviceModelCopiers.copierClassFor(member); if (!copier.isPresent()) { throw new IllegalStateException("Don't know how to copy " + fieldName + " with enum elements!"); } return CodeBlock.of("return $T.$N($N);", copier.get(), serviceModelCopiers.stringToEnumCopyMethodName(), fieldName); } else { ClassName enumClass = poetExtensions.getModelClass(member.getEnumType()); return CodeBlock.of("return $T.fromValue($N);", enumClass, fieldName); } }
Example 6
Source File: ModelMethodOverrides.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public CodeBlock toStringValue(MemberModel member) { if (!member.isSensitive()) { return CodeBlock.of("$L()", member.getFluentGetterMethodName()); } return CodeBlock.of("$L() == null ? null : $S", member.getFluentGetterMethodName(), "*** Sensitive Data Redacted ***"); }
Example 7
Source File: MemberCopierSpec.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private CodeBlock mapKeyValCopyExpr(MemberModel keyValModel, String getterName, EnumTransform enumTransform) { Optional<ClassName> keyCopier = serviceModelCopiers.copierClassFor(keyValModel); boolean hasCopier = keyCopier.isPresent(); switch (enumTransform) { case STRING_TO_ENUM: if (hasCopier) { return CodeBlock.of("$T.$N(e.$N())", keyCopier.get(), serviceModelCopiers.stringToEnumCopyMethodName(), getterName); } else { return CodeBlock.of("$T.fromValue(e.$N())", poetExtensions.getModelClass(keyValModel.getEnumType()), getterName); } case ENUM_TO_STRING: if (hasCopier) { return CodeBlock.of("$T.$N(e.$N())", keyCopier.get(), serviceModelCopiers.enumToStringCopyMethodName(), getterName); } else { return CodeBlock.of("e.$N().toString()", getterName); } case NONE: if (hasCopier) { return CodeBlock.of("$T.$N(e.$N())", keyCopier.get(), serviceModelCopiers.copyMethodName(), getterName); } else { return CodeBlock.of("e.$N()", getterName); } default: throw new IllegalArgumentException("Unknown enum transform: " + enumTransform); } }
Example 8
Source File: AbstractMemberSetters.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private CodeBlock sdkBytesMapValueSetter() { return CodeBlock.of("$1N($2N == null ? null : " + "$2N.entrySet().stream()" + ".collect($4T.toMap(e -> e.getKey(), e -> $3T.fromByteBuffer(e.getValue()))));", memberModel.getFluentSetterMethodName(), fieldName(), SdkBytes.class, Collectors.class); }
Example 9
Source File: PoetCollectorsTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void delimitedCodeBlocksJoined() { CodeBlock a = CodeBlock.of("a"); CodeBlock b = CodeBlock.of("b"); CodeBlock delimeter = CodeBlock.of(","); CodeBlock ab = CodeBlock.builder().add(a).add(delimeter).add(b).build(); CodeBlock result = Stream.of(a, b).collect(PoetCollectors.toDelimitedCodeBlock(",")); assertThat(result).isEqualTo(ab); }
Example 10
Source File: BaseClientBuilderInterface.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock getJavadoc() { return CodeBlock.of("This includes configuration specific to $L that is supported by both {@link $T} and {@link $T}.", model.getMetadata().getDescriptiveServiceName(), ClassName.get(basePackage, model.getMetadata().getSyncBuilderInterface()), ClassName.get(basePackage, model.getMetadata().getAsyncBuilderInterface())); }
Example 11
Source File: AsyncClientBuilderInterface.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock getJavadoc() { return CodeBlock.of("A builder for creating an instance of {@link $1T}. This can be created with the static " + "{@link $1T#builder()} method.", clientInterfaceName); }
Example 12
Source File: BaseClientBuilderClass.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock s3SignerDefinitionMethodBody() { return CodeBlock.of("return $T.create();\n", ClassName.get("software.amazon.awssdk.auth.signer", "AwsS3V4Signer")); }
Example 13
Source File: ListSetters.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock consumerBuilderVarargSetterBody() { return CodeBlock.of("$1L($3T.of($2L).map(c -> $4T.builder().applyMutation(c).build()).collect($5T.toList()));", memberModel().getFluentSetterMethodName(), fieldName(), Stream.class, listElementType(), Collectors.class); }
Example 14
Source File: ListSetters.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock varargToListSetterBody() { return CodeBlock.of("$1L($2T.asList($3L));", memberModel().getFluentSetterMethodName(), Arrays.class, fieldName()); }
Example 15
Source File: AbstractMemberSetters.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock sdkBytesSetter() { return CodeBlock.of("$1N($2N == null ? null : $3T.fromByteBuffer($2N));", memberModel.getFluentSetterMethodName(), fieldName(), SdkBytes.class); }
Example 16
Source File: AwsServiceModel.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock getterStatement(MemberModel model) { VariableModel modelVariable = model.getVariable(); return CodeBlock.of("return $N;", modelVariable.getVariableName()); }
Example 17
Source File: BaseClientBuilderClass.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock v4SignerDefinitionMethodBody() { return CodeBlock.of("return $T.create();", Aws4Signer.class); }
Example 18
Source File: Id.java From convalida with Apache License 2.0 | 4 votes |
public Id(int value, ClassName className, String resourceName) { this.value = value; this.code = className.topLevelClassName().equals(ANDROID_R) ? CodeBlock.of("$L.$N", className, resourceName) : CodeBlock.of("$T.$N", className, resourceName); }
Example 19
Source File: Id.java From convalida with Apache License 2.0 | 4 votes |
public Id(int value) { this.value = value; this.code = CodeBlock.of("$L", value); }
Example 20
Source File: SyncClientBuilderInterface.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private CodeBlock getJavadoc() { return CodeBlock.of("A builder for creating an instance of {@link $1T}. This can be created with the static " + "{@link $1T#builder()} method.", clientInterfaceName); }