本文整理了Java中com.squareup.javapoet.ClassName.nestedClass()
方法的一些代码示例,展示了ClassName.nestedClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassName.nestedClass()
方法的具体详情如下:
包路径:com.squareup.javapoet.ClassName
类名称:ClassName
方法名:nestedClass
[英]Returns a new ClassName instance for the specified name as nested inside this class.
[中]返回嵌套在此类中的指定名称的新ClassName实例。
代码示例来源:origin: square/javapoet
/** Returns the class named {@code simpleName} when nested in the class at {@code stackDepth}. */
private ClassName stackClassName(int stackDepth, String simpleName) {
ClassName className = ClassName.get(packageName, typeSpecStack.get(0).name);
for (int i = 1; i <= stackDepth; i++) {
className = className.nestedClass(typeSpecStack.get(i).name);
}
return className.nestedClass(simpleName);
}
代码示例来源:origin: square/javapoet
@Override public ClassName visitType(TypeElement enclosingClass, Void p) {
return ClassName.get(enclosingClass).nestedClass(simpleName);
}
代码示例来源:origin: square/javapoet
/**
* Returns a class name created from the given parts. For example, calling this with package name
* {@code "java.util"} and simple names {@code "Map"}, {@code "Entry"} yields {@link Map.Entry}.
*/
public static ClassName get(String packageName, String simpleName, String... simpleNames) {
ClassName className = new ClassName(packageName, null, simpleName);
for (String name : simpleNames) {
className = className.nestedClass(name);
}
return className;
}
代码示例来源:origin: square/javapoet
/**
* Returns a new {@link ParameterizedTypeName} instance for the specified {@code name} as nested
* inside this class.
*/
public ParameterizedTypeName nestedClass(String name) {
checkNotNull(name, "name == null");
return new ParameterizedTypeName(this, rawType.nestedClass(name), new ArrayList<>(),
new ArrayList<>());
}
代码示例来源:origin: square/dagger
private ClassName bindingClassName(ClassName adapterName, ExecutableElement providerMethod,
Map<ExecutableElement, ClassName> methodToClassName,
Map<String, AtomicInteger> methodNameToNextId) {
ClassName className = methodToClassName.get(providerMethod);
if (className != null) return className;
String methodName = providerMethod.getSimpleName().toString();
String suffix = "";
AtomicInteger id = methodNameToNextId.get(methodName);
if (id == null) {
methodNameToNextId.put(methodName, new AtomicInteger(2));
} else {
suffix = id.toString();
id.incrementAndGet();
}
String uppercaseMethodName = Character.toUpperCase(methodName.charAt(0))
+ methodName.substring(1);
className = adapterName.nestedClass(uppercaseMethodName + "ProvidesAdapter" + suffix);
methodToClassName.put(providerMethod, className);
return className;
}
代码示例来源:origin: square/javapoet
/**
* Returns a new {@link ParameterizedTypeName} instance for the specified {@code name} as nested
* inside this class, with the specified {@code typeArguments}.
*/
public ParameterizedTypeName nestedClass(String name, List<TypeName> typeArguments) {
checkNotNull(name, "name == null");
return new ParameterizedTypeName(this, rawType.nestedClass(name), typeArguments,
new ArrayList<>());
}
代码示例来源:origin: square/javapoet
public static ClassName get(Class<?> clazz) {
checkNotNull(clazz, "clazz == null");
checkArgument(!clazz.isPrimitive(), "primitive types cannot be represented as a ClassName");
checkArgument(!void.class.equals(clazz), "'void' type cannot be represented as a ClassName");
checkArgument(!clazz.isArray(), "array types cannot be represented as a ClassName");
String anonymousSuffix = "";
while (clazz.isAnonymousClass()) {
int lastDollar = clazz.getName().lastIndexOf('$');
anonymousSuffix = clazz.getName().substring(lastDollar) + anonymousSuffix;
clazz = clazz.getEnclosingClass();
}
String name = clazz.getSimpleName() + anonymousSuffix;
if (clazz.getEnclosingClass() == null) {
// Avoid unreliable Class.getPackage(). https://github.com/square/javapoet/issues/295
int lastDot = clazz.getName().lastIndexOf('.');
String packageName = (lastDot != -1) ? clazz.getName().substring(0, lastDot) : null;
return new ClassName(packageName, null, name);
}
return ClassName.get(clazz.getEnclosingClass()).nestedClass(name);
}
代码示例来源:origin: square/wire
private MethodSpec newBuilder(NameAllocator nameAllocator, MessageType message) {
NameAllocator localNameAllocator = nameAllocator.clone();
String builderName = localNameAllocator.newName("builder");
ClassName javaType = (ClassName) typeName(message.type());
ClassName builderJavaType = javaType.nestedClass("Builder");
MethodSpec.Builder result = MethodSpec.methodBuilder("newBuilder")
.addAnnotation(Override.class)
.addModifiers(PUBLIC)
.returns(builderJavaType)
.addStatement("$1T $2L = new $1T()", builderJavaType, builderName);
List<Field> fields = message.fieldsAndOneOfFields();
for (Field field : fields) {
String fieldName = localNameAllocator.get(field);
if (field.isRepeated() || field.type().isMap()) {
result.addStatement("$1L.$2L = $3T.copyOf($2S, $2L)", builderName, fieldName,
Internal.class);
} else {
result.addStatement("$1L.$2L = $2L", builderName, fieldName);
}
}
result.addStatement("$L.addUnknownFields(unknownFields())", builderName);
result.addStatement("return $L", builderName);
return result.build();
}
代码示例来源:origin: square/wire
private static void putAll(Map<ProtoType, ClassName> wireToJava, String javaPackage,
ClassName enclosingClassName, List<Type> types) {
for (Type type : types) {
ClassName className = enclosingClassName != null
? enclosingClassName.nestedClass(type.type().simpleName())
: ClassName.get(javaPackage, type.type().simpleName());
wireToJava.put(type.type(), className);
putAll(wireToJava, javaPackage, className, type.nestedTypes());
}
}
代码示例来源:origin: square/wire
ClassName adapterJavaType = javaType.nestedClass("ProtoAdapter_" + javaType.simpleName());
if (!emitCompact) {
adapterBuilder.initializer("new $T()", adapterJavaType);
代码示例来源:origin: square/wire
ClassName builderJavaType = javaType.nestedClass("Builder");
String protoAdapterName = "ProtoAdapter_" + javaType.simpleName();
String protoAdapterClassName = nameAllocator.newName(protoAdapterName);
ClassName adapterJavaType = javaType.nestedClass(protoAdapterClassName);
builder.addField(messageAdapterField(adapterName, javaType, adapterJavaType));
代码示例来源:origin: palantir/atlasdb
public TableClassRendererV2(
String packageName,
Namespace namespace,
String rawTableName,
TableDefinition table) {
Preconditions.checkArgument(
Schemas.isTableNameValid(rawTableName),
"Invalid table name %s", rawTableName);
this.packageName = packageName;
this.namespace = namespace;
this.rawTableName = rawTableName;
this.tableName = Renderers.getClassTableName(rawTableName, table);
this.tableMetadata = table.toTableMetadata();
this.simpleTableName = this.tableName + SCHEMA_V2_TABLE_NAME;
this.tableClassName = this.tableName + "Table";
this.rowClassName = this.tableName + "Row";
this.rowResultClassName = this.tableName + "RowResult";
this.tableType = ClassName.get(packageName, this.tableClassName);
this.simpleTableType = ClassName.get(packageName, this.simpleTableName);
this.rowType = this.tableType.nestedClass(this.rowClassName);
this.rowResultType = this.tableType.nestedClass(this.rowResultClassName);
}
代码示例来源:origin: palantir/atlasdb
public static TableFactoryRenderer of(
String schemaName,
String packageName,
Namespace defaultNamespace,
Map<String, TableDefinition> definitions) {
SortedMap<String, TableDefinition> sortedDefinitions = Maps.newTreeMap();
for (Entry<String, TableDefinition> entry : definitions.entrySet()) {
sortedDefinitions.put(Renderers.getClassTableName(entry.getKey(), entry.getValue()), entry.getValue());
}
ClassName tableFactoryType = ClassName.get(packageName, schemaName + "TableFactory");
ClassName sharedTriggersType = tableFactoryType.nestedClass("SharedTriggers");
return new TableFactoryRenderer(
schemaName,
packageName,
defaultNamespace.getName(),
sortedDefinitions,
tableFactoryType,
sharedTriggersType);
}
代码示例来源:origin: palantir/atlasdb
String tableName = getTableName(name);
ClassName tableType = ClassName.get(packageName, tableName);
TypeName rowType = tableType.nestedClass(name + "Row");
TypeName columnType = tableType.nestedClass(name + "ColumnValue");
if (!tableDefinition.toTableMetadata().getColumns().hasDynamicColumns()) {
columnType = ParameterizedTypeName.get(
代码示例来源:origin: palantir/atlasdb
private MethodSpec renderNamedPutColumn(NamedColumnDescription col) {
MethodSpec.Builder putColumnBuilder = MethodSpec.methodBuilder("put" + VarName(col))
.addJavadoc("Takes the row-keys and a value to be inserted at column $L.", VarName(col))
.addModifiers(Modifier.PUBLIC);
putColumnBuilder = addParametersFromRowComponents(putColumnBuilder, tableMetadata);
TypeName columnValueType = tableType.nestedClass(VarName(col));
putColumnBuilder.addParameter(getColumnClass(col), col.getLongName());
putColumnBuilder
.addStatement("$T row = $T.of($L)", rowType, rowType, getArgumentsFromRowComponents(tableMetadata))
.addStatement("t.put(tableRef, $T.toCellValues($T.of(row, $T.of($L))))",
ColumnValues.class, ImmutableMultimap.class, columnValueType, col.getLongName());
return putColumnBuilder.build();
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* @return {@link ClassName} for the builder interface for the event stream visitor interface.
*/
public ClassName eventStreamResponseHandlerVisitorBuilderType(OperationModel operation) {
return eventStreamResponseHandlerVisitorType(operation).nestedClass("Builder");
}
代码示例来源:origin: aws/aws-sdk-java-v2
private MethodSpec.Builder acceptMethodSpec(ClassName modelClass, ClassName responseHandlerClass) {
return MethodSpec.methodBuilder("accept")
.addModifiers(PUBLIC)
.addJavadoc(new DocumentationBuilder()
.description("Calls the appropriate visit method depending on "
+ "the subtype of {@link $T}.")
.param("visitor", "Visitor to invoke.")
.build(), modelClass)
.addParameter(responseHandlerClass
.nestedClass("Visitor"), "visitor");
}
代码示例来源:origin: aws/aws-sdk-java-v2
private TypeName builderImplSuperClass() {
if (isRequest()) {
return new AwsServiceBaseRequestSpec(intermediateModel).className().nestedClass("BuilderImpl");
}
if (isResponse()) {
return new AwsServiceBaseResponseSpec(intermediateModel).className().nestedClass("BuilderImpl");
}
return ClassName.OBJECT;
}
代码示例来源:origin: aws/aws-sdk-java-v2
private MethodSpec fluentConsumerFluentSetter(TypeName returnType) {
ClassName memberClass = poetExtensions.getModelClass(memberModel().getShape().getC2jName());
ClassName builderClass = memberClass.nestedClass("Builder");
return fluentDefaultSetterDeclaration(builderConsumerParam(builderClass), returnType)
.addModifiers(Modifier.DEFAULT)
.addStatement("return $N($T.builder().applyMutation($N).build())",
memberModel().getFluentSetterMethodName(),
memberClass,
fieldName())
.addJavadoc("$L", memberModel().getDefaultConsumerFluentSetterDocumentation())
.build();
}
代码示例来源:origin: aws/aws-sdk-java-v2
private MethodSpec builderGetter(MemberModel memberModel) {
return basicGetter(memberModel,
poetExtensions.getModelClass(memberModel.getC2jShape()).nestedClass("Builder"),
CodeBlock.builder().add("return $1N != null ? $1N.toBuilder() : null",
memberModel.getVariable().getVariableName())
.build());
}
内容来源于网络,如有侵权,请联系作者删除!