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

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

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

ClassName.get介绍

[英]Returns a class name created from the given parts. For example, calling this with package name "java.util" and simple names "Map", "Entry" yields Map.Entry.
[中]返回从给定零件创建的类名。例如,用包名“java.util”和简单的名称“Map”、“Entry”来调用它会生成Map。进入

代码示例

代码示例来源:origin: web3j/web3j

private MethodSpec.Builder addStatement(MethodSpec.Builder builder, String packageName,
                    String typeName, String className) {
  return builder.addStatement(
      "case \"$L\":\nreturn $T.class", typeName, ClassName.get(packageName, className));
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void getBadgeViewHelper(TypeSpec.Builder typeBuilder) {
  MethodSpec methodSpec = MethodSpec.methodBuilder("getBadgeViewHelper")
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addStatement("return mBadgeViewHelper")
      .returns(ClassName.get(PACKAGE_NAME, "BGABadgeViewHelper"))
      .build();
  typeBuilder.addMethod(methodSpec);
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void callSuperOnTouchEvent(TypeSpec.Builder typeBuilder) {
  MethodSpec methodSpec = MethodSpec.methodBuilder("callSuperOnTouchEvent")
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addParameter(ClassName.get("android.view", "MotionEvent"), "event")
      .addStatement("return super.onTouchEvent(event)")
      .returns(boolean.class)
      .build();
  typeBuilder.addMethod(methodSpec);
}

代码示例来源:origin: ACRA/acra

private void createConfigClass(@NonNull List<Element> elements) throws IOException {
  final TypeSpec.Builder classBuilder = TypeSpec.classBuilder(configName)
      .addSuperinterface(Serializable.class)
      .addSuperinterface(org.acra.config.Configuration.class)
      .addModifiers(Modifier.PUBLIC, Modifier.FINAL);
  Strings.addClassJavadoc(classBuilder, ClassName.get(baseAnnotation.asType()));
  final MethodSpec.Builder constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC)
      .addParameter(ParameterSpec.builder(ClassName.get(PACKAGE, builderName), PARAM_0).addAnnotation(Types.NON_NULL).build());
  elements.stream().filter(ConfigElement.class::isInstance).map(ConfigElement.class::cast).forEach(element -> element.addToConfig(classBuilder, constructor));
  classBuilder.addMethod(constructor.build());
  Strings.writeClass(processingEnv.getFiler(), classBuilder.build());
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void onTouchEvent(TypeSpec.Builder typeBuilder) {
  MethodSpec methodSpec = MethodSpec.methodBuilder("onTouchEvent")
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addParameter(ClassName.get("android.view", "MotionEvent"), "event")
      .addStatement("return mBadgeViewHelper.onTouchEvent(event)")
      .returns(boolean.class)
      .build();
  typeBuilder.addMethod(methodSpec);
}

代码示例来源:origin: f2prateek/dart

private void emitResolvedOptionalSequence(TypeSpec.Builder intentBuilderTypeBuilder) {
 // find superclass
 final ClassName optionalSequence =
   get(target.classPackage, builderClassName(), OPTIONAL_SEQUENCE_CLASS);
 final ClassName resolvedOptional =
   get(target.classPackage, builderClassName(), RESOLVED_OPTIONAL_SEQUENCE_CLASS);
 TypeSpec.Builder resolvedOptionalSequenceBuilder =
   TypeSpec.classBuilder(RESOLVED_OPTIONAL_SEQUENCE_CLASS)
     .superclass(ParameterizedTypeName.get(optionalSequence, resolvedOptional))
     .addModifiers(Modifier.PUBLIC)
     .addModifiers(Modifier.STATIC);
 MethodSpec.Builder constructorBuilder =
   MethodSpec.constructorBuilder()
     .addModifiers(Modifier.PUBLIC)
     .addParameter(Bundler.class, "bundler")
     .addParameter(get("android.content", "Intent"), "intent")
     .addStatement("super(bundler, intent)");
 resolvedOptionalSequenceBuilder.addMethod(constructorBuilder.build());
 intentBuilderTypeBuilder.addType(resolvedOptionalSequenceBuilder.build());
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void setDragDismissDelegate(TypeSpec.Builder typeBuilder) {
  MethodSpec methodSpec = MethodSpec.methodBuilder("setDragDismissDelegate")
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addParameter(ClassName.get(PACKAGE_NAME, "BGADragDismissDelegate"), "delegate")
      .addStatement("mBadgeViewHelper.setDragDismissDelegate(delegate)")
      .build();
  typeBuilder.addMethod(methodSpec);
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void constructor(TypeSpec.Builder typeBuilder, String clazz) {
  TypeName contextType = ClassName.get("android.content", "Context");
  TypeName attributeSetType = ClassName.get("android.util", "AttributeSet");
  MethodSpec constructorOne = MethodSpec.constructorBuilder()
      .addModifiers(Modifier.PUBLIC)
      .addParameter(contextType, "context")
      .addStatement("this(context, null)")
      .build();
  MethodSpec constructorTwo = MethodSpec.constructorBuilder()
      .addModifiers(Modifier.PUBLIC)
      .addParameter(contextType, "context")
      .addParameter(attributeSetType, "attrs")
      .addStatement("this(context, attrs, 0)")
      .build();
  MethodSpec.Builder constructorThreeBuilder = MethodSpec.constructorBuilder()
      .addModifiers(Modifier.PUBLIC)
      .addParameter(contextType, "context")
      .addParameter(attributeSetType, "attrs")
      .addParameter(int.class, "defStyleAttr")
      .addStatement("super(context, attrs, defStyleAttr)");
  if (isAssignable(clazz, "android.widget.ImageView") || isAssignable(clazz, "android.widget.RadioButton")) {
    constructorThreeBuilder.addStatement("mBadgeViewHelper = new BGABadgeViewHelper(this, context, attrs, BGABadgeViewHelper.BadgeGravity.RightTop)");
  } else {
    constructorThreeBuilder.addStatement(
        "mBadgeViewHelper = new BGABadgeViewHelper(this, context, attrs, BGABadgeViewHelper.BadgeGravity.RightCenter)");
  }
  typeBuilder.addMethod(constructorOne)
      .addMethod(constructorTwo)
      .addMethod(constructorThreeBuilder.build());
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void showDrawableBadge(TypeSpec.Builder typeBuilder) {
  MethodSpec methodSpec = MethodSpec.methodBuilder("showDrawableBadge")
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addParameter(ClassName.get("android.graphics", "Bitmap"), "bitmap")
      .addStatement("mBadgeViewHelper.showDrawable(bitmap)")
      .build();
  typeBuilder.addMethod(methodSpec);
}

代码示例来源:origin: f2prateek/dart

public void emitInitialState(TypeSpec.Builder intentBuilderTypeBuilder) {
 TypeSpec.Builder initialStateBuilder =
   TypeSpec.classBuilder(INITIAL_STATE_CLASS)
     .superclass(getInitialStateType(getInitialStateGeneric(true)))
     .addModifiers(Modifier.PUBLIC)
     .addModifiers(Modifier.STATIC);
 MethodSpec.Builder constructorBuilder =
   MethodSpec.constructorBuilder()
     .addModifiers(Modifier.PUBLIC)
     .addParameter(Bundler.class, "bundler")
     .addParameter(get("android.content", "Intent"), "intent");
 if (!target.hasRequiredFields && target.closestRequiredAncestorPackage == null) {
  constructorBuilder.addStatement("super(bundler, intent)");
 } else {
  constructorBuilder.addStatement(
    "super(bundler, new $L(bundler, intent))", RESOLVED_OPTIONAL_SEQUENCE_CLASS);
 }
 initialStateBuilder.addMethod(constructorBuilder.build());
 intentBuilderTypeBuilder.addType(initialStateBuilder.build());
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void onDraw(TypeSpec.Builder typeBuilder) {
  MethodSpec methodSpec = MethodSpec.methodBuilder("onDraw")
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addParameter(ClassName.get("android.graphics", "Canvas"), "canvas")
      .addStatement("super.onDraw(canvas)")
      .addStatement("mBadgeViewHelper.drawBadge(canvas)")
      .build();
  typeBuilder.addMethod(methodSpec);
}

代码示例来源:origin: ACRA/acra

private void createFactoryClass() throws IOException {
    final TypeName configurationBuilderFactory = Types.CONFIGURATION_BUILDER_FACTORY;
    Strings.writeClass(processingEnv.getFiler(), TypeSpec.classBuilder(factoryName)
        .addModifiers(Modifier.PUBLIC)
        .addSuperinterface(configurationBuilderFactory)
        .addAnnotation(AnnotationSpec.builder(AutoService.class).addMember("value", "$T.class", configurationBuilderFactory).build())
        .addMethod(Types.overriding(Types.getOnlyMethod(processingEnv, Strings.CONFIGURATION_BUILDER_FACTORY))
            .addAnnotation(Types.NON_NULL)
            .addStatement("return new $T($L)", ClassName.get(PACKAGE, builderName), PARAM_0)
            .build())
        .build());
  }
}

代码示例来源:origin: bingoogolapple/BGABadgeView-Android

private void dispatchDraw(TypeSpec.Builder typeBuilder) {
  MethodSpec methodSpec = MethodSpec.methodBuilder("dispatchDraw")
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addParameter(ClassName.get("android.graphics", "Canvas"), "canvas")
      .addStatement("super.dispatchDraw(canvas)")
      .addStatement("mBadgeViewHelper.drawBadge(canvas)")
      .build();
  typeBuilder.addMethod(methodSpec);
}

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

public static RClassBuilder create(Filer filer, Messager messager) {
  ClassName className = ClassName.get(NameStore.Package.R, NameStore.Class.R);
  return new RClassBuilder(
      filer,
          .addModifiers(Modifier.FINAL)
          .addMethod(MethodSpec.constructorBuilder()
              .addModifiers(Modifier.PRIVATE)
              .addComment("$S", "Not to be instantiated in public")
              .build()),
      TypeSpec.classBuilder(NameStore.Class.LAYOUT)
          .addModifiers(Modifier.PUBLIC)
          .addModifiers(Modifier.FINAL)
          .addMethod(MethodSpec.constructorBuilder()
              .addModifiers(Modifier.PRIVATE)
              .addComment("$S", "Not to be instantiated in public")
              .build()),
      className,
      ClassName.get(NameStore.Package.R, NameStore.Class.R, NameStore.Class.LAYOUT),
      ClassName.get(NameStore.Package.R, NameStore.Class.R, NameStore.Class.ID),
      new HashMap<String, Integer>(),
      new HashMap<String, Integer>());

代码示例来源:origin: f2prateek/dart

private void emitInitialStateGetter(TypeSpec.Builder intentBuilderTypeBuilder) {
 MethodSpec.Builder initialStateGetterForHensonBuilder =
   MethodSpec.methodBuilder(INITIAL_STATE_METHOD)
     .addModifiers(Modifier.PUBLIC)
     .addModifiers(Modifier.STATIC)
     .addParameter(get("android.content", "Context"), "context")
     .returns(get(target.classPackage, builderClassName(), INITIAL_STATE_CLASS));
 initialStateGetterForHensonBuilder.addStatement(
   "final $T intent = new $T(context, getClassDynamically($S))",
   ClassName.get("android.content", "Intent"),
   ClassName.get("android.content", "Intent"),
   target.getFQN());
 initialStateGetterForHensonBuilder.addStatement(
   "final $T bundler = $T.create()", Bundler.class, Bundler.class);
 initialStateGetterForHensonBuilder.addStatement(
   "return new $L(bundler, intent)", INITIAL_STATE_CLASS);
 intentBuilderTypeBuilder.addMethod(initialStateGetterForHensonBuilder.build());
}

代码示例来源:origin: f2prateek/dart

get(target.classPackage, builderClassName(), OPTIONAL_SEQUENCE_CLASS);
final ParameterizedTypeName parameterizedOptionalSequence =
  ParameterizedTypeName.get(
if (target.parentPackage != null) {
 final ClassName parentOptionalSequence =
   get(
     target.parentPackage,
     target.parentClass + BUNDLE_BUILDER_SUFFIX,
 superClass = ParameterizedTypeName.get(parentOptionalSequence, typeVariable);
} else {
 superClass = get(AllRequiredSetState.class);
    .addModifiers(Modifier.PUBLIC)
    .addParameter(Bundler.class, "bundler")
    .addParameter(get("android.content", "Intent"), "intent")
    .addStatement("super(bundler, intent)");
optionalSequenceBuilder.addMethod(constructorBuilder.build());

代码示例来源:origin: web3j/web3j

MethodSpec buildDefaultEventFlowableFunction(
    String responseClassName,
    String functionName) {
  String generatedFunctionName =
      Strings.lowercaseFirstLetter(functionName) + "EventFlowable";
  ParameterizedTypeName parameterizedTypeName =
      ParameterizedTypeName.get(ClassName.get(Flowable.class),
      ClassName.get("", responseClassName));
  MethodSpec.Builder flowableMethodBuilder =
      MethodSpec.methodBuilder(generatedFunctionName)
          .addModifiers(Modifier.PUBLIC)
          .addParameter(DefaultBlockParameter.class, START_BLOCK)
          .addParameter(DefaultBlockParameter.class, END_BLOCK)
          .returns(parameterizedTypeName);
  flowableMethodBuilder.addStatement("$1T filter = new $1T($2L, $3L, "
      + "getContractAddress())", EthFilter.class, START_BLOCK, END_BLOCK)
      .addStatement("filter.addSingleTopic($T.encode("
          + buildEventDefinitionName(functionName) + "))", EventEncoder.class)
      .addStatement("return " + generatedFunctionName + "(filter)");
  return flowableMethodBuilder
      .build();
}

代码示例来源:origin: web3j/web3j

.addModifiers(Modifier.PUBLIC)
    .addParameter(ParameterizedTypeName.get(ClassName.get(List.class),
        typeVariableName), "values")
    .addStatement("super($L, $N)", length, "values")
    .build();
    .addModifiers(Modifier.PUBLIC)
    .addParameter(ArrayTypeName.of(typeVariableName), "values")
    .varargs()
    .addStatement("super($L, $N)", length, "values")
    .build();
className = ClassName.get(packageName, superclass.getSimpleName() + length);
    .addTypeVariable(typeVariableName)
    .addJavadoc(CODEGEN_WARNING)
    .superclass(ParameterizedTypeName.get(ClassName.get(superclass),
        typeVariableName))
    .addModifiers(Modifier.PUBLIC)

代码示例来源:origin: web3j/web3j

ClassName.get(List.class), ClassName.get("", responseClassName));
    .methodBuilder(generatedFunctionName)
    .addModifiers(Modifier.PUBLIC)
    .addParameter(TransactionReceipt.class, "transactionReceipt")
    .returns(parameterizedTypeName);
transactionMethodBuilder.addStatement("$T valueList = extractEventParametersWithLog("
    + buildEventDefinitionName(functionName) + ", "
    + "transactionReceipt)", ParameterizedTypeName.get(List.class,
    Contract.EventValuesWithLog.class))
    .addStatement("$1T responses = new $1T(valueList.size())",
        ParameterizedTypeName.get(ClassName.get(ArrayList.class),
            ClassName.get("", responseClassName)))
    .beginControlFlow("for ($T eventValues : valueList)",
        Contract.EventValuesWithLog.class)
    .addStatement("$1T typedResponse = new $1T()",
        ClassName.get("", responseClassName))
    .addCode(buildTypedResponse("typedResponse", indexedParameters,
        nonIndexedParameters, false))
transactionMethodBuilder.addStatement("return responses");
return transactionMethodBuilder.build();

代码示例来源:origin: f2prateek/dart

private void emitRequiredSequence(
  TypeSpec.Builder intentBuilderTypeBuilder, List<ExtraInjection> requiredInjections) {
 if (!target.hasRequiredFields) {
  return;
 }
 final TypeName generic = getInitialStateGeneric(false);
 TypeSpec.Builder requiredSequenceBuilder =
   TypeSpec.classBuilder(REQUIRED_SEQUENCE_CLASS)
     .superclass(ParameterizedTypeName.get(get(RequiredStateSequence.class), generic))
     .addTypeVariable((TypeVariableName) generic)
     .addModifiers(Modifier.PUBLIC)
     .addModifiers(Modifier.STATIC);
 MethodSpec.Builder constructorBuilder =
   MethodSpec.constructorBuilder()
     .addModifiers(Modifier.PUBLIC)
     .addParameter(Bundler.class, "bundler")
     .addParameter(generic, "allRequiredSetState")
     .addStatement("super(bundler, allRequiredSetState)");
 requiredSequenceBuilder.addMethod(constructorBuilder.build());
 TypeSpec.Builder builderStateClass = requiredSequenceBuilder;
 for (int i = 0; i < requiredInjections.size(); i++) {
  final boolean isLast = i == requiredInjections.size() - 1;
  final ExtraInjection binding = requiredInjections.get(i);
  final String nextClass = emitRequiredSetter(builderStateClass, binding, generic, isLast);
  builderStateClass = rotateBuilderState(requiredSequenceBuilder, builderStateClass, nextClass);
 }
 intentBuilderTypeBuilder.addType(requiredSequenceBuilder.build());
}

相关文章