本文整理了Java中com.squareup.javapoet.ClassName.enclosingClassName()
方法的一些代码示例,展示了ClassName.enclosingClassName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassName.enclosingClassName()
方法的具体详情如下:
包路径:com.squareup.javapoet.ClassName
类名称:ClassName
方法名:enclosingClassName
[英]The enclosing class, or null if this is not enclosed in another class.
[中]封闭类,如果未封闭在另一个类中,则为null。
代码示例来源:origin: square/javapoet
public List<String> simpleNames() {
List<String> simpleNames = new ArrayList<>();
if (enclosingClassName != null) {
simpleNames.addAll(enclosingClassName().simpleNames());
}
simpleNames.add(simpleName);
return simpleNames;
}
代码示例来源:origin: facebook/litho
private static String getTypeNameString(ClassName className) {
ClassName enclosingClass = className.enclosingClassName();
if (enclosingClass == null) {
return className.toString();
}
return enclosingClass.toString() + "$" + className.simpleName();
}
}
代码示例来源:origin: square/wire
private TypeSpec generateEnclosingType(EnclosingType type) {
ClassName javaType = (ClassName) typeName(type.type());
TypeSpec.Builder builder = TypeSpec.classBuilder(javaType.simpleName())
.addModifiers(PUBLIC, FINAL);
if (javaType.enclosingClassName() != null) {
builder.addModifiers(STATIC);
}
String documentation = type.documentation();
if (!documentation.isEmpty()) {
documentation += "\n\n<p>";
}
documentation += "<b>NOTE:</b> This type only exists to maintain class structure"
+ " for its nested types and is not an actual message.";
builder.addJavadoc("$L\n", documentation);
builder.addMethod(MethodSpec.constructorBuilder()
.addModifiers(PRIVATE)
.addStatement("throw new $T()", AssertionError.class)
.build());
for (Type nestedType : type.nestedTypes()) {
builder.addType(generateType(nestedType));
}
return builder.build();
}
代码示例来源:origin: square/javapoet
for (ClassName c = className; c != null; c = c.enclosingClassName()) {
ClassName resolved = resolve(c.simpleName());
nameResolved = resolved != null;
代码示例来源:origin: square/wire
/** Returns a standalone adapter for {@code type}. */
public TypeSpec generateAdapterForCustomType(Type type) {
NameAllocator nameAllocator = nameAllocators.getUnchecked(type);
ClassName adapterTypeName = abstractAdapterName(type.type());
ClassName typeName = (ClassName) typeName(type.type());
TypeSpec.Builder adapter;
if (type instanceof MessageType) {
adapter = messageAdapter(nameAllocator, (MessageType) type, typeName, adapterTypeName, null)
.toBuilder();
} else {
adapter = enumAdapter(nameAllocator, (EnumType) type, typeName, adapterTypeName).toBuilder();
}
if (adapterTypeName.enclosingClassName() != null) adapter.addModifiers(STATIC);
for (Type nestedType : type.nestedTypes()) {
if (profile.getAdapter(nestedType.type()) == null) {
throw new IllegalArgumentException("Missing custom proto adapter for "
+ nestedType.type().enclosingTypeOrPackage() + "." + nestedType.type().simpleName()
+ " when enclosing proto has custom proto adapter.");
}
adapter.addType(generateAdapterForCustomType(nestedType));
}
return adapter.build();
}
代码示例来源:origin: square/wire
builder.addModifiers(PUBLIC, FINAL);
if (javaType.enclosingClassName() != null) {
builder.addModifiers(STATIC);
代码示例来源:origin: com.google.dagger/dagger-compiler
private static void checkName(ClassName name, NestingKind nestingKind) {
switch (nestingKind) {
case TOP_LEVEL:
checkArgument(
name.enclosingClassName() == null, "must be a top-level class name: %s", name);
break;
case MEMBER:
checkNotNull(name.enclosingClassName(), "must not be a top-level class name: %s", name);
break;
default:
throw new IllegalArgumentException(
"nestingKind must be TOP_LEVEL or MEMBER: " + nestingKind);
}
}
代码示例来源:origin: com.squareup.wire/wire-java-generator
private TypeSpec generateEnclosingType(EnclosingType type) {
ClassName javaType = (ClassName) typeName(type.type());
TypeSpec.Builder builder = TypeSpec.classBuilder(javaType.simpleName())
.addModifiers(PUBLIC, FINAL);
if (javaType.enclosingClassName() != null) {
builder.addModifiers(STATIC);
}
String documentation = type.documentation();
if (!documentation.isEmpty()) {
documentation += "\n\n";
}
documentation += "<b>NOTE:</b> This type only exists to maintain class structure"
+ " for its nested types and is not an actual message.\n";
builder.addJavadoc(documentation);
builder.addMethod(MethodSpec.constructorBuilder()
.addModifiers(PRIVATE)
.addStatement("throw new $T()", AssertionError.class)
.build());
for (Type nestedType : type.nestedTypes()) {
builder.addType(generateType(nestedType));
}
return builder.build();
}
代码示例来源:origin: ppdai-incubator/raptor
private TypeSpec generateEnclosingType(ProtoFile protoFile, EnclosingType type) {
ClassName javaType = (ClassName) typeName(type.type());
TypeSpec.Builder builder = TypeSpec.classBuilder(javaType.simpleName())
.addModifiers(PUBLIC, FINAL);
if (javaType.enclosingClassName() != null) {
builder.addModifiers(STATIC);
}
String documentation = type.documentation();
if (!documentation.isEmpty()) {
documentation += "\n\n<p>";
}
documentation += "<b>NOTE:</b> This type only exists to maintain class structure"
+ " for its nested types and is not an actual message.\n";
builder.addJavadoc(documentation);
builder.addMethod(MethodSpec.constructorBuilder()
.addModifiers(PRIVATE)
.addStatement("throw new $T()", AssertionError.class)
.build());
for (Type nestedType : type.nestedTypes()) {
builder.addType(generateType(protoFile, nestedType));
}
return builder.build();
}
代码示例来源:origin: xiaoxiangyeyuHeaven/JD-shopping-mall
for (ClassName c = className; c != null; c = c.enclosingClassName()) {
ClassName resolved = resolve(c.simpleName());
nameResolved = resolved != null;
代码示例来源:origin: io.virtdata/virtdata-lib-realer
for (ClassName c = className; c != null; c = c.enclosingClassName()) {
ClassName resolved = resolve(c.simpleName());
nameResolved = resolved != null;
代码示例来源:origin: ppdai-incubator/raptor
builder.addAnnotation(raptorMessage);
if (javaType.enclosingClassName() != null) {
builder.addModifiers(STATIC);
代码示例来源:origin: com.squareup.wire/wire-java-generator
builder.addModifiers(PUBLIC, FINAL);
if (javaType.enclosingClassName() != null) {
builder.addModifiers(STATIC);
内容来源于网络,如有侵权,请联系作者删除!