com.squareup.javapoet.ClassName.topLevelClassName()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中com.squareup.javapoet.ClassName.topLevelClassName()方法的一些代码示例,展示了ClassName.topLevelClassName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassName.topLevelClassName()方法的具体详情如下:
包路径:com.squareup.javapoet.ClassName
类名称:ClassName
方法名:topLevelClassName

ClassName.topLevelClassName介绍

[英]Returns the top class in this nesting group. Equivalent to chained calls to #enclosingClassName() until the result's enclosing class is null.
[中]返回此嵌套组中的顶级类。相当于对#enclosingClassName()的链式调用,直到结果的封闭类为null。

代码示例

代码示例来源:origin: square/javapoet

/**
 * Returns the top class in this nesting group. Equivalent to chained calls to {@link
 * #enclosingClassName()} until the result's enclosing class is null.
 */
public ClassName topLevelClassName() {
 return enclosingClassName != null ? enclosingClassName.topLevelClassName() : this;
}

代码示例来源:origin: square/javapoet

private void importableType(ClassName className) {
 if (className.packageName().isEmpty()) {
  return;
 }
 ClassName topLevelClassName = className.topLevelClassName();
 String simpleName = topLevelClassName.simpleName();
 ClassName replaced = importableTypes.put(simpleName, topLevelClassName);
 if (replaced != null) {
  importableTypes.put(simpleName, replaced); // On collision, prefer the first inserted.
 }
}

代码示例来源:origin: JakeWharton/butterknife

Id(int value, @Nullable Symbol rSymbol) {
 this.value = value;
 if (rSymbol != null) {
  ClassName className = ClassName.get(rSymbol.packge().getQualifiedName().toString(), R,
    rSymbol.enclClass().name.toString());
  String resourceName = rSymbol.name.toString();
  this.code = className.topLevelClassName().equals(ANDROID_R)
   ? CodeBlock.of("$L.$N", className, resourceName)
   : CodeBlock.of("$T.$N", className, resourceName);
  this.qualifed = true;
 } else {
  this.code = CodeBlock.of("$L", value);
  this.qualifed = false;
 }
}

代码示例来源:origin: square/javapoet

String topLevelSimpleName = className.topLevelClassName().simpleName();
if (currentTypeVariables.contains(topLevelSimpleName)) {
 return className.canonicalName;

代码示例来源:origin: io.virtdata/virtdata-lib-realer

private void importableType(ClassName className) {
 if (className.packageName().isEmpty()) {
  return;
 }
 ClassName topLevelClassName = className.topLevelClassName();
 String simpleName = topLevelClassName.simpleName();
 ClassName replaced = importableTypes.put(simpleName, topLevelClassName);
 if (replaced != null) {
  importableTypes.put(simpleName, replaced); // On collision, prefer the first inserted.
 }
}

代码示例来源:origin: xiaoxiangyeyuHeaven/JD-shopping-mall

private void importableType(ClassName className) {
 if (className.packageName().isEmpty()) {
  return;
 }
 ClassName topLevelClassName = className.topLevelClassName();
 String simpleName = topLevelClassName.simpleName();
 ClassName replaced = importableTypes.put(simpleName, topLevelClassName);
 if (replaced != null) {
  importableTypes.put(simpleName, replaced); // On collision, prefer the first inserted.
 }
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

public String reflectionName() {
 // trivial case: no nested names
 if (names.size() == 2) {
  String packageName = packageName();
  if (packageName.isEmpty()) {
   return names.get(1);
  }
  return packageName + "." + names.get(1);
 }
 // concat top level class name and nested names
 StringBuilder builder = new StringBuilder();
 builder.append(topLevelClassName());
 for (String name : simpleNames().subList(1, simpleNames().size())) {
  builder.append('$').append(name);
 }
 return builder.toString();
}

代码示例来源:origin: com.google.dagger/dagger-compiler

/**
 * Returns the name of the generated class that contains the static {@code create} methods for an
 * annotation type.
 */
static ClassName getAnnotationCreatorClassName(TypeElement annotationType) {
 ClassName annotationTypeName = ClassName.get(annotationType);
 return annotationTypeName
   .topLevelClassName()
   .peerClass(classFileName(annotationTypeName) + "Creator");
}

代码示例来源:origin: xiaoxiangyeyuHeaven/JD-shopping-mall

public String reflectionName() {
 // trivial case: no nested names
 if (names.size() == 2) {
  String packageName = packageName();
  if (packageName.isEmpty()) {
   return names.get(1);
  }
  return packageName + "." + names.get(1);
 }
 // concat top level class name and nested names
 StringBuilder builder = new StringBuilder();
 builder.append(topLevelClassName());
 for (String name : simpleNames().subList(1, simpleNames().size())) {
  builder.append('$').append(name);
 }
 return builder.toString();
}

代码示例来源:origin: com.google.dagger/dagger-compiler

private static ClassName siblingClassName(TypeElement typeElement, String suffix) {
 ClassName className = ClassName.get(typeElement);
 return className.topLevelClassName().peerClass(classFileName(className) + suffix);
}

代码示例来源:origin: com.google.dagger/dagger-compiler

/** The name of the class that hosts the module constructor proxy method. */
static ClassName constructorProxyTypeName(TypeElement moduleElement) {
 ModuleKind.checkIsModule(moduleElement);
 ClassName moduleClassName = ClassName.get(moduleElement);
 return moduleClassName
   .topLevelClassName()
   .peerClass(SourceFiles.classFileName(moduleClassName) + "_Proxy");
}

代码示例来源:origin: CaMnter/AndroidLife

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);
  this.qualifed = true;
}

代码示例来源:origin: WellingtonCosta/convalida

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);
}

代码示例来源:origin: IVIanuu/contributer

descriptor
  .enclosingModule()
  .topLevelClassName()
  .peerClass(
    Joiner.on('_').join(descriptor.enclosingModule().simpleNames())

代码示例来源:origin: com.google.dagger/dagger-android-processor

descriptor
  .enclosingModule()
  .topLevelClassName()
  .peerClass(
    Joiner.on('_').join(descriptor.enclosingModule().simpleNames())

代码示例来源:origin: io.virtdata/virtdata-lib-realer

referencedNames.add(className.topLevelClassName().simpleName());
return join(".", className.simpleNames());

代码示例来源:origin: xiaoxiangyeyuHeaven/JD-shopping-mall

referencedNames.add(className.topLevelClassName().simpleName());
return join(".", className.simpleNames());

代码示例来源:origin: com.jakewharton/butterknife-compiler

Id(int value, @Nullable Symbol rSymbol) {
 this.value = value;
 if (rSymbol != null) {
  ClassName className = ClassName.get(rSymbol.packge().getQualifiedName().toString(), R,
    rSymbol.enclClass().name.toString());
  String resourceName = rSymbol.name.toString();
  this.code = className.topLevelClassName().equals(ANDROID_R)
   ? CodeBlock.of("$L.$N", className, resourceName)
   : CodeBlock.of("$T.$N", className, resourceName);
  this.qualifed = true;
 } else {
  this.code = CodeBlock.of("$L", value);
  this.qualifed = false;
 }
}

相关文章