当前位置: 首页>>代码示例>>Java>>正文


Java TypeName类代码示例

本文整理汇总了Java中com.squareup.javapoet.TypeName的典型用法代码示例。如果您正苦于以下问题:Java TypeName类的具体用法?Java TypeName怎么用?Java TypeName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TypeName类属于com.squareup.javapoet包,在下文中一共展示了TypeName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: builderCopyMethodForList

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private MethodSpec builderCopyMethodForList() {
    TypeName keyType = typeProvider.getTypeNameForSimpleType(memberModel.getMapModel().getKeyModel()
                                                                        .getVariable().getVariableType());
    ClassName valueParameter = poetExtensions.getModelClass(memberModel.getMapModel().getValueModel().getC2jShape());
    ClassName builderForParameter = valueParameter.nestedClass("Builder");
    TypeName parameterType =
        ParameterizedTypeName.get(ClassName.get(Map.class), keyType, WildcardTypeName.subtypeOf(builderForParameter));

    CodeBlock code =
        CodeBlock.builder()
                 .beginControlFlow("if ($N == null)", memberParamName())
                 .addStatement("return null")
                 .endControlFlow()
                 .addStatement("return $N($N.entrySet().stream().collect(toMap($T::getKey, e -> e.getValue().build())))",
                               serviceModelCopiers.copyMethodName(),
                               memberParamName(),
                               Map.Entry.class)
                 .build();

    return MethodSpec.methodBuilder(serviceModelCopiers.builderCopyMethodName())
                     .addModifiers(Modifier.STATIC)
                     .addParameter(parameterType, memberParamName())
                     .returns(typeProvider.fieldType(memberModel))
                     .addCode(code)
                     .build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:27,代码来源:MemberCopierSpec.java

示例2: getMethodByType

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private String getMethodByType(TypeName clazz) {
    StringBuilder sb = new StringBuilder("get");
    if (clazz.equals(TypeName.INT) || clazz.equals(TypeName.INT.box())) {
        sb.append("Int");
    } else if (clazz.equals(TypeName.BOOLEAN) || clazz.equals(TypeName.BOOLEAN.box())) {
        sb.append("Boolean");
    } else if (clazz.equals(TypeName.FLOAT) || clazz.equals(TypeName.FLOAT.box())) {
        sb.append("Float");
    } else if (clazz.equals(TypeName.DOUBLE) || clazz.equals(TypeName.DOUBLE.box())) {
        sb.append("Double");
    } else if (clazz.equals(TypeName.LONG) || clazz.equals(TypeName.LONG.box())) {
        sb.append("Long");
    } else if (clazz.equals(TypeName.SHORT) || clazz.equals(TypeName.SHORT.box())) {
        sb.append("Short");
    } else if (clazz.equals(TypeName.CHAR) || clazz.equals(TypeName.CHAR.box())) {
        sb.append("Char");
    } else if (clazz.equals(TypeName.VOID) || clazz.equals(TypeName.VOID.box()) ||
            clazz.equals(TypeName.BYTE) || clazz.equals(TypeName.BYTE.box())
            || clazz.equals(TypeName.OBJECT)) {
        //should not use this type
    } else {
        sb.append("String");
    }
    return sb.append("Param").toString();
}
 
开发者ID:bboylin,项目名称:D-Router,代码行数:26,代码来源:ActivityHelperGenerator.java

示例3: defaultValue

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private String defaultValue(JsonProperty property, TypeName type) {
  if (property.defaultValue != null) {
    return property.defaultValue;
  }
  if (type == TypeName.BOOLEAN) {
    return "false";
  } else if (type == TypeName.BYTE) {
    return "(byte) 0";
  } else if (type == TypeName.SHORT) {
    return "0";
  } else if (type == TypeName.INT) {
    return "0";
  } else if (type == TypeName.LONG) {
    return "0L";
  } else if (type == TypeName.CHAR) {
    return "'\0'";
  } else if (type == TypeName.FLOAT) {
    return "0.0f";
  } else if (type == TypeName.DOUBLE) {
    return "0.0d";
  } else {
    return "null";
  }
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:25,代码来源:AutoValueJsonExtension.java

示例4: getSuperMethodSpecs

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private List<MethodSpec> getSuperMethodSpecs() {
    List<MethodSpec> methodSpecs = new ArrayList<>();
    this.annotatedClazz.annotatedElement.getEnclosedElements().stream()
            .filter(element -> element instanceof ExecutableElement)
            .map(element -> (ExecutableElement) element)
            .forEach(method -> {
                ClassName preferenceRoom = ClassName.get(PreferenceRoom.class);
                MethodSpec.Builder builder = MethodSpec.overriding(method);
                MethodSpec methodSpec = builder.addStatement("$T.inject($N)", preferenceRoom, method.getParameters().get(0).getSimpleName()).build();
                if(methodSpec.returnType != TypeName.get(Void.TYPE)) {
                    throw new VerifyException(String.format("Returned '%s'. only return type can be void.", methodSpec.returnType.toString()));
                }
                methodSpecs.add(methodSpec);
            });
    return methodSpecs;
}
 
开发者ID:skydoves,项目名称:PreferenceRoom,代码行数:17,代码来源:PreferenceComponentGenerator.java

示例5: buildMethods

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
@Nonnull
@Override
protected List<MethodSpec> buildMethods() {
    final MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC);

    final ImmutableList.Builder<MethodSpec> builder = ImmutableList.builder();
    getProperties().entrySet().forEach(property -> {
        final String name = property.getKey();
        final TypeName type = property.getValue();
        final String fieldName = fieldNamePolicy.convert(name, type);
        final String methodName = methodNamePolicy.convert(name, type);
        builder.add(MethodSpec.methodBuilder(methodName)
                .addModifiers(Modifier.PUBLIC)
                .returns(type)
                .addStatement("return $L", fieldName)
                .build());

        final String propertyName = parameterNamePolicy.convert(name, type);
        constructorBuilder.addParameter(ParameterSpec.builder(type, propertyName)
                .build())
                .addStatement("this.$L = $L", fieldName, propertyName);
    });
    builder.add(constructorBuilder.build());
    return builder.build();
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:27,代码来源:ModelClassBuilder.java

示例6: buildIsDisposed

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
/**
 * Generate the isDisposed method.
 */
@Nonnull
private MethodSpec buildIsDisposed()
  throws ArezProcessorException
{
  final MethodSpec.Builder builder =
    MethodSpec.methodBuilder( "isDisposed" ).
      addModifiers( Modifier.PUBLIC ).
      addAnnotation( Override.class ).
      returns( TypeName.BOOLEAN );

  final CodeBlock.Builder block = CodeBlock.builder();
  block.beginControlFlow( "if ( $N().isTransactionActive() && !this.$N.isDisposed() ) ",
                          getContextMethodName(),
                          GeneratorUtil.DISPOSED_OBSERVABLE_FIELD_NAME );
  block.addStatement( "this.$N.reportObserved()", GeneratorUtil.DISPOSED_OBSERVABLE_FIELD_NAME );
  block.addStatement( "return this.$N", GeneratorUtil.DISPOSED_FIELD_NAME );
  block.nextControlFlow( "else" );
  block.addStatement( "return this.$N", GeneratorUtil.DISPOSED_FIELD_NAME );
  block.endControlFlow();
  builder.addCode( block.build() );

  return builder.build();
}
 
开发者ID:arez,项目名称:arez,代码行数:27,代码来源:ComponentDescriptor.java

示例7: buildComponentTypeNameMethod

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
@Nullable
private MethodSpec buildComponentTypeNameMethod()
  throws ArezProcessorException
{
  if ( null == _componentTypeName )
  {
    return null;
  }

  final MethodSpec.Builder builder =
    MethodSpec.methodBuilder( _componentTypeName.getSimpleName().toString() );
  ProcessorUtil.copyAccessModifiers( _componentTypeName, builder );
  builder.addModifiers( Modifier.FINAL );
  builder.addAnnotation( GeneratorUtil.NONNULL_CLASSNAME );

  builder.returns( TypeName.get( String.class ) );
  builder.addStatement( "return $S", _type );
  return builder.build();
}
 
开发者ID:arez,项目名称:arez,代码行数:20,代码来源:ComponentDescriptor.java

示例8: checkCompiles

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private void checkCompiles(final MethodSpec method) {
	final TypeSpec wrapperTypeSpec = CallerDef
			.getNewCallerSubclassPrototype("Wrapper", TypeName.OBJECT)
			.addMethod(CallerDef.getNewCallMethodPrototype().build())
			.addMethod(CallerDef.getNewConstructorPrototype(TypeName.OBJECT).build())
			.addMethod(method)
			.build();

	final JavaFile wrapperJavaFile = JavaFile
			.builder("", wrapperTypeSpec)
			.build();

	final Set<JavaFile> filesToCompile = new HashSet<>();
	filesToCompile.add(wrapperJavaFile);
	filesToCompile.add(CallerDef.SRC_FILE);

	CompileChecker.checkCompiles(filesToCompile);
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:19,代码来源:TestValueIsAvailableMethodGenerator.java

示例9: BindingSet

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private BindingSet(TypeName targetTypeName, ClassName bindingClassName, boolean isFinal,
                   boolean isView, boolean isActivity,boolean isFragment, boolean isDialog, ImmutableList<ViewBinding> viewBindings,
                   ImmutableList<FieldCollectionViewBinding> collectionBindings,
                   ImmutableList<ResourceBinding> resourceBindings, BindingSet parentBinding, @LayoutRes int layoutId) {
    this.isFinal = isFinal;
    this.targetTypeName = targetTypeName;
    this.bindingClassName = bindingClassName;
    this.isView = isView;
    this.isActivity = isActivity;
    this.isFragment = isFragment;
    this.isDialog = isDialog;
    this.viewBindings = viewBindings;
    this.collectionBindings = collectionBindings;
    this.resourceBindings = resourceBindings;
    this.parentBinding = parentBinding;
    this.layoutId = layoutId;
}
 
开发者ID:qq542391099,项目名称:butterknife-parent,代码行数:18,代码来源:BindingSet.java

示例10: generateSetPropertySpec

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private static MethodSpec generateSetPropertySpec(
    ClassInfo classInfo,
    List<PropertyInfo> properties) {
  MethodSpec.Builder builder = MethodSpec.methodBuilder("setProperty")
      .addModifiers(PUBLIC)
      .addAnnotation(Override.class)
      .returns(TypeName.VOID);

  switch (classInfo.getType()) {
    case VIEW_MANAGER:
      builder
          .addParameter(classInfo.mClassName, "manager")
          .addParameter(classInfo.mViewType, "view");
      break;
    case SHADOW_NODE:
      builder
          .addParameter(classInfo.mClassName, "node");
      break;
  }

  return builder
      .addParameter(STRING_TYPE, "name")
      .addParameter(PROPS_TYPE, "props")
      .addCode(generateSetProperty(classInfo, properties))
      .build();
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:27,代码来源:ReactPropertyProcessor.java

示例11: streamingSimpleMethods

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private List<MethodSpec> streamingSimpleMethods(OperationModel opModel) {
    TypeName responseType = ClassName.get(model.getMetadata().getFullModelPackageName(),
                                          opModel.getReturnType().getReturnType());
    ClassName requestType = ClassName.get(model.getMetadata().getFullModelPackageName(),
                                          opModel.getInput().getVariableType());
    List<MethodSpec> simpleMethods = new ArrayList<>();
    if (opModel.hasStreamingInput()) {
        simpleMethods.add(uploadFromFileSimpleMethod(opModel, responseType, requestType));
    }
    if (opModel.hasStreamingOutput()) {
        simpleMethods.add(downloadToFileSimpleMethod(opModel, responseType, requestType));
        simpleMethods.add(inputStreamSimpleMethod(opModel, responseType, requestType));
        simpleMethods.add(bytesSimpleMethod(opModel, responseType, requestType));
    }
    return simpleMethods;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:17,代码来源:SyncClientInterface.java

示例12: create

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
static OutputValue create(Value value, ClassName specOutputClass, Spec spec)
    throws ParserException {
  ClassName outputClass = specOutputClass.nestedClass(value.name());
  Iterable<TypeVariableName> typeVariables = getTypeVariables(value, spec.typeVariables());

  List<Parameter> parameters = new ArrayList<>();
  for (Parameter parameter : value.parameters()) {
    TypeName rawParamType = withoutTypeParameters(parameter.type());

    if (isDataEnumParameter(rawParamType)) {
      TypeName paramOutputType =
          withParametersFromOther(toOutputClass(rawParamType), parameter.type());
      parameters.add(new Parameter(parameter.name(), paramOutputType, parameter.canBeNull()));
    } else {
      parameters.add(parameter);
    }
  }

  return new OutputValue(outputClass, value.name(), parameters, typeVariables);
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:21,代码来源:OutputValueFactory.java

示例13: addOnBind

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private void addOnBind(Element targetMember, TypeMirror bindTypeMirror, HashMap<Element, List<ViewBinder.Builder>> targetViewBinders) {
    boolean match = false;

    TypeName typeName = TypeName.get(bindTypeMirror);
    DeclaredType bindingDeclaredType = typeUtils.types().getDeclaredType(elementUtils.getTypeElement(bindTypeMirror.toString()));
    OnBind onBind = new NewInstance(typeName);

    // OnBind
    TypeMirror onBindTypeMirror = typeUtils.onBindDeclaredType();
    if (typeUtils.types().isSubtype(bindingDeclaredType, onBindTypeMirror)) {
        addOnBind(targetMember, onBind, targetViewBinders);
        match = true;
    }

    if (!match) {
        String stringBuilder = String.valueOf(typeName) +
                " does not implement required interface. Make sure classes provided in: " +
                "@" + SupportedAnnotations.OnBind.name + " or " +
                "@" + SupportedAnnotations.OnBindEach.name +
                " implements one or more of the following: " +
                TypeUtils.ON_BIND;

        throw new WitchException(logger.logError(stringBuilder));
    }
}
 
开发者ID:sedstrom,项目名称:Witch-Android,代码行数:26,代码来源:WitchProcessor.java

示例14: getUnboxedClass

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
public static TypeName getUnboxedClass(Element element) {
    TypeName typeName = getFieldClass(element);
    if (TypeName.INT.equals(typeName)) {
        return TypeName.get(Integer.class);
    }
    if (TypeName.LONG.equals(typeName)) {
        return TypeName.get(Long.class);
    }
    if (TypeName.FLOAT.equals(typeName)) {
        return TypeName.get(Float.class);
    }
    if (TypeName.DOUBLE.equals(typeName)) {
        return TypeName.get(Double.class);
    }
    if (TypeName.BOOLEAN.equals(typeName)) {
        return TypeName.get(Boolean.class);
    }
    if (TypeName.get(String.class).equals(typeName)) {
        return typeName;
    }
    return null;
}
 
开发者ID:florent37,项目名称:RxAndroidOrm,代码行数:23,代码来源:ProcessUtils.java

示例15: onRegularMapperMethodStatement

import com.squareup.javapoet.TypeName; //导入依赖的package包/类
private void onRegularMapperMethodStatement(ClassName hashMapClassName, TypeName routerTargetTypeName, MethodSpec.Builder calcRegMapperMethodBuilder, UriEntry uriEntry) {
    calcRegMapperMethodBuilder.addCode("// " + uriEntry.getRouterTargetClass() + "\n");

    List<ParamEntry> paramEntries = uriEntry.getParams();
    int paramSize = null == paramEntries ? 0 : paramEntries.size();
    if (paramSize <= 0) {
        calcRegMapperMethodBuilder.addStatement(
                "$L.put($S, new $T($T.class, null))",
                "routerMapper", uriEntry.getUriRegular(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()));
    } else {
        calcRegMapperMethodBuilder.addStatement("$L = new $T<>(" + paramSize + ", 1F)",
                "params", hashMapClassName);
        for (ParamEntry paramEntry : paramEntries) {
            LogUtil.logger("[Reg]paramEntry: " + paramEntry);
            calcRegMapperMethodBuilder.addStatement("params.put($S, $T.class)", paramEntry.getName(), paramEntry.getType());
        }

        calcRegMapperMethodBuilder.addStatement(
                "$L.put($S, new $T($T.class, $L))",
                "routerMapper", uriEntry.getUriRegular(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()), "params");

    }
}
 
开发者ID:wangjiegulu,项目名称:RapidRouter,代码行数:24,代码来源:RouterEntry.java


注:本文中的com.squareup.javapoet.TypeName类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。