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

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

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

ClassName.simpleName介绍

[英]This class name, like "Entry" for java.util.Map.Entry.
[中]这个类名,类似于java的“Entry”。util。地图进入

代码示例

代码示例来源:origin: facebook/litho

static String getEventHandlerInstanceName(ClassName eventHandlerClassName) {
 final String eventHandlerName = eventHandlerClassName.simpleName();
 return eventHandlerName.substring(0, 1).toLowerCase(Locale.ROOT) +
   eventHandlerName.substring(1) +
   "Handler";
}

代码示例来源:origin: north2016/T-MVP

public static String getClassName(TypeElement typeElement) throws ClassNotFoundException {
  return ClassName.get(typeElement).simpleName();
}

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

public static Builder classBuilder(ClassName className) {
 return classBuilder(checkNotNull(className, "className == null").simpleName());
}

代码示例来源:origin: facebook/litho

private static String getComponentName(String componentClassName, String qualifiedSpecClassName) {
 return getComponentTypeName(componentClassName, qualifiedSpecClassName).simpleName();
}

代码示例来源: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: web3j/web3j

static TypeName getEventNativeType(TypeName typeName) {
  if (typeName instanceof ParameterizedTypeName) {
    return TypeName.get(byte[].class);
  }
  String simpleName = ((ClassName) typeName).simpleName();
  if (simpleName.equals(Utf8String.class.getSimpleName())) {
    return TypeName.get(byte[].class);
  } else {
    return getNativeType(typeName);
  }
}

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

/** Returns a parameterized type equivalent to {@code type}. */
 static ParameterizedTypeName get(ParameterizedType type, Map<Type, TypeVariableName> map) {
  ClassName rawType = ClassName.get((Class<?>) type.getRawType());
  ParameterizedType ownerType = (type.getOwnerType() instanceof ParameterizedType)
    && !Modifier.isStatic(((Class<?>) type.getRawType()).getModifiers())
    ? (ParameterizedType) type.getOwnerType() : null;
  List<TypeName> typeArguments = TypeName.list(type.getActualTypeArguments(), map);
  return (ownerType != null)
    ? get(ownerType, map).nestedClass(rawType.simpleName(), typeArguments)
    : new ParameterizedTypeName(null, rawType, typeArguments);
 }
}

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

@Override public TypeName visitDeclared(DeclaredType t, Void p) {
 ClassName rawType = ClassName.get((TypeElement) t.asElement());
 TypeMirror enclosingType = t.getEnclosingType();
 TypeName enclosing =
   (enclosingType.getKind() != TypeKind.NONE)
       && !t.asElement().getModifiers().contains(Modifier.STATIC)
     ? enclosingType.accept(this, null)
     : null;
 if (t.getTypeArguments().isEmpty() && !(enclosing instanceof ParameterizedTypeName)) {
  return rawType;
 }
 List<TypeName> typeArgumentNames = new ArrayList<>();
 for (TypeMirror mirror : t.getTypeArguments()) {
  typeArgumentNames.add(get(mirror, typeVariables));
 }
 return enclosing instanceof ParameterizedTypeName
   ? ((ParameterizedTypeName) enclosing).nestedClass(
   rawType.simpleName(), typeArgumentNames)
   : new ParameterizedTypeName(null, rawType, typeArgumentNames);
}

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

public static Builder annotationBuilder(ClassName className) {
 return annotationBuilder(checkNotNull(className, "className == null").simpleName());
}

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

public static Builder interfaceBuilder(ClassName className) {
 return interfaceBuilder(checkNotNull(className, "className == null").simpleName());
}

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

public static Builder enumBuilder(ClassName className) {
 return enumBuilder(checkNotNull(className, "className == null").simpleName());
}

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

/**
 * Returns the Java type of the abstract adapter class generated for a corresponding {@code
 * protoType}. Returns null if {@code protoType} is not using a custom proto adapter.
 */
public @Nullable ClassName abstractAdapterName(ProtoType protoType) {
 TypeName profileJavaName = profile.getTarget(protoType);
 if (profileJavaName == null) return null;
 ClassName javaName = nameToJavaName.get(protoType);
 Type type = schema.getType(protoType);
 return type instanceof EnumType
   ? javaName.peerClass(javaName.simpleName() + "Adapter")
   : javaName.peerClass("Abstract" + javaName.simpleName() + "Adapter");
}

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

/**
 * Write a companion class for {@code type} that extends {@link StaticInjection}.
 */
private void generateStaticInjection(TypeElement type, List<Element> fields) throws IOException {
 ClassName typeName = ClassName.get(type);
 ClassName adapterClassName = adapterName(ClassName.get(type), STATIC_INJECTION_SUFFIX);
 TypeSpec.Builder result = TypeSpec.classBuilder(adapterClassName.simpleName())
   .addOriginatingElement(type)
   .addJavadoc(AdapterJavadocs.STATIC_INJECTION_TYPE, type)
   .addModifiers(PUBLIC, FINAL)
   .superclass(StaticInjection.class);
 for (Element field : fields) {
  result.addField(memberBindingField(false, field));
 }
 result.addMethod(attachMethod(null, fields, false, typeName, null, true));
 result.addMethod(staticInjectMethod(fields, typeName));
 String packageName = getPackage(type).getQualifiedName().toString();
 JavaFile javaFile = JavaFile.builder(packageName, result.build())
   .addFileComment(AdapterJavadocs.GENERATED_BY_DAGGER)
   .build();
 javaFile.writeTo(processingEnv.getFiler());
}

代码示例来源: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: JakeWharton/butterknife

private TypeSpec createType(int sdk, boolean debuggable) {
 TypeSpec.Builder result = TypeSpec.classBuilder(bindingClassName.simpleName())
   .addModifiers(PUBLIC);
 if (isFinal) {

代码示例来源:origin: VictorAlbertos/RxCache

private TypeSpec classProviders(ClassName className, List<MethodSpec> methodSpecs) {
  return TypeSpec.classBuilder(className.simpleName() + "Actionable")
      .addModifiers(Modifier.PUBLIC)
      .addAnnotation(AnnotationSpec.builder(Generated.class)
          .addMember("value", "$S", ActionsProcessor.class.getCanonicalName())
          .addMember("comments", "$S", "Generated code from RxCache. Don't modify. Or modify. It doesn't matter.")
          .build())
      .addMethods(methodSpecs)
      .build();
}

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

if (requiresRemoval) {
 TypeName listenerClassName = bestGuess(listenerClass.type());
 listenerField = fieldName + ((ClassName) listenerClassName).simpleName();
 result.addField(listenerClassName, listenerField, PRIVATE);

代码示例来源:origin: janishar/PlaceHolderView

@Override
protected TypeSpec.Builder createClassBuilder() {
  return TypeSpec.classBuilder(getClassDetail().getGeneratedClassName())
      .superclass(ParameterizedTypeName.get(
          getClassDetail().getSuperClassName(),
          TypeVariableName.get(getClassDetail().getTypeElement().asType()),
          TypeVariableName.get(getClassDetail().getViewTypeParameterClassName().simpleName())))
      .addModifiers(Modifier.PUBLIC)
      .addAnnotation(Keep.class);
}

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

@Override CodeWriter emit(CodeWriter out) throws IOException {
 if (enclosingType != null) {
  enclosingType.emit(out);
  out.emit(".");
  if (isAnnotated()) {
   out.emit(" ");
   emitAnnotations(out);
  }
  out.emit(rawType.simpleName());
 } else {
  rawType.emit(out);
 }
 if (!typeArguments.isEmpty()) {
  out.emitAndIndent("<");
  boolean firstParameter = true;
  for (TypeName parameter : typeArguments) {
   if (!firstParameter) out.emitAndIndent(", ");
   parameter.emit(out);
   firstParameter = false;
  }
  out.emitAndIndent(">");
 }
 return out;
}

代码示例来源:origin: facebook/litho

@Before
public void ListUp() {
 mDiffTypeSpecWrappingInt =
   new TypeSpec.DeclaredTypeSpec(
     ClassNames.DIFF,
     ClassNames.DIFF.packageName() + "." + ClassNames.DIFF.simpleName(),
     () -> new TypeSpec(TypeName.OBJECT),
     ImmutableList.of(),
     ImmutableList.of(new TypeSpec(TypeName.INT.box())));
}

相关文章